hotspot/src/share/vm/memory/metaspace.cpp
author mgerdin
Wed, 11 Sep 2013 09:37:14 +0200
changeset 19984 ba033739c8fe
parent 19979 ebe1dbb6e1aa
child 19988 2b100c528806
permissions -rw-r--r--
8009561: NPG: Metaspace fragmentation when retiring a Metachunk Summary: Use best-fit block-splitting freelist allocation from the block freelist. Reviewed-by: jmasa, stefank
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
/*
15928
f9d5c6e4107f 8003553: NPG: metaspace objects should be zeroed in constructors
coleenp
parents: 15610
diff changeset
     2
 * Copyright (c) 2011, 2013, 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"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    26
#include "memory/binaryTreeDictionary.hpp"
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
    27
#include "memory/freeList.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    28
#include "memory/collectorPolicy.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    29
#include "memory/filemap.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    30
#include "memory/freeList.hpp"
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
    31
#include "memory/metablock.hpp"
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
    32
#include "memory/metachunk.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    33
#include "memory/metaspace.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    34
#include "memory/metaspaceShared.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    35
#include "memory/resourceArea.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    36
#include "memory/universe.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    37
#include "runtime/globals.hpp"
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
    38
#include "runtime/java.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    39
#include "runtime/mutex.hpp"
14579
7f6ce6e3dd80 8003635: NPG: AsynchGetCallTrace broken by Method* virtual call
coleenp
parents: 14474
diff changeset
    40
#include "runtime/orderAccess.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    41
#include "services/memTracker.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    42
#include "utilities/copy.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    43
#include "utilities/debug.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    44
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
    45
typedef BinaryTreeDictionary<Metablock, FreeList> BlockTreeDictionary;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
    46
typedef BinaryTreeDictionary<Metachunk, FreeList> ChunkTreeDictionary;
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
    47
// Define this macro to enable slow integrity checking of
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
    48
// the free chunk lists
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
    49
const bool metaspace_slow_verify = false;
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
    50
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    51
// Parameters for stress mode testing
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    52
const uint metadata_deallocate_a_lot_block = 10;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    53
const uint metadata_deallocate_a_lock_chunk = 3;
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
    54
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
    55
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    56
MetaWord* last_allocated = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    57
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
    58
size_t Metaspace::_class_metaspace_size;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
    59
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    60
// Used in declarations in SpaceManager and ChunkManager
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    61
enum ChunkIndex {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    62
  ZeroIndex = 0,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    63
  SpecializedIndex = ZeroIndex,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    64
  SmallIndex = SpecializedIndex + 1,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    65
  MediumIndex = SmallIndex + 1,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    66
  HumongousIndex = MediumIndex + 1,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    67
  NumberOfFreeLists = 3,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    68
  NumberOfInUseLists = 4
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    69
};
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    70
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    71
enum ChunkSizes {    // in words.
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    72
  ClassSpecializedChunk = 128,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    73
  SpecializedChunk = 128,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    74
  ClassSmallChunk = 256,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    75
  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
    76
  ClassMediumChunk = 4 * K,
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    77
  MediumChunk = 8 * K,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
    78
  HumongousChunkGranularity = 8
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    79
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    80
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    81
static ChunkIndex next_chunk_index(ChunkIndex i) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
    82
  assert(i < NumberOfInUseLists, "Out of bound");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    83
  return (ChunkIndex) (i+1);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    84
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    85
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    86
// Originally _capacity_until_GC was set to MetaspaceSize here but
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    87
// the default MetaspaceSize before argument processing was being
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    88
// used which was not the desired value.  See the code
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    89
// in should_expand() to see how the initialization is handled
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    90
// now.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    91
size_t MetaspaceGC::_capacity_until_GC = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    92
bool MetaspaceGC::_expand_after_GC = false;
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
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    96
// Blocks of space for metadata are allocated out of Metachunks.
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
// Metachunk are allocated out of MetadataVirtualspaces and once
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    99
// allocated there is no explicit link between a Metachunk and
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   100
// the MetadataVirtualspaces from which it was allocated.
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
// Each SpaceManager maintains a
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   103
// list of the chunks it is using and the current chunk.  The current
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   104
// chunk is the chunk from which allocations are done.  Space freed in
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   105
// a chunk is placed on the free list of blocks (BlockFreelist) and
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   106
// reused from there.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   107
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
   108
typedef class FreeList<Metachunk> ChunkList;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   109
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   110
// Manages the global free lists of chunks.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   111
// Has three lists of free chunks, and a total size and
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   112
// count that includes all three
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   113
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   114
class ChunkManager VALUE_OBJ_CLASS_SPEC {
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
  // Free list of chunks of different sizes.
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   117
  //   SpecializedChunk
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   118
  //   SmallChunk
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   119
  //   MediumChunk
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   120
  //   HumongousChunk
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   121
  ChunkList _free_chunks[NumberOfFreeLists];
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   122
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   123
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   124
  //   HumongousChunk
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   125
  ChunkTreeDictionary _humongous_dictionary;
13728
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
  // ChunkManager in all lists of this type
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   128
  size_t _free_chunks_total;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   129
  size_t _free_chunks_count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   130
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   131
  void dec_free_chunks_total(size_t v) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   132
    assert(_free_chunks_count > 0 &&
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   133
             _free_chunks_total > 0,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   134
             "About to go negative");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   135
    Atomic::add_ptr(-1, &_free_chunks_count);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   136
    jlong minus_v = (jlong) - (jlong) v;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   137
    Atomic::add_ptr(minus_v, &_free_chunks_total);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   138
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   139
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   140
  // Debug support
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   141
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   142
  size_t sum_free_chunks();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   143
  size_t sum_free_chunks_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   144
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   145
  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
   146
  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
   147
    if (metaspace_slow_verify) {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   148
      locked_verify_free_chunks_total();
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   149
    }
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   150
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   151
  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
   152
  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
   153
    if (metaspace_slow_verify) {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   154
      locked_verify_free_chunks_count();
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   155
    }
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   156
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   157
  void verify_free_chunks_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   158
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   159
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   160
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   161
  ChunkManager() : _free_chunks_total(0), _free_chunks_count(0) {}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   162
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   163
  // 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
   164
  Metachunk* chunk_freelist_allocate(size_t word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   165
  void chunk_freelist_deallocate(Metachunk* chunk);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   166
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   167
  // 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
   168
  // for special, small, medium, and humongous chunks.
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   169
  static ChunkIndex list_index(size_t size);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   170
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   171
  // Remove the chunk from its freelist.  It is
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   172
  // expected to be on one of the _free_chunks[] lists.
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   173
  void remove_chunk(Metachunk* chunk);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   174
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
   175
  // 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
   176
  // of type index.
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
   177
  void return_chunks(ChunkIndex index, Metachunk* chunks);
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
   178
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   179
  // Total of the space in the free chunks list
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   180
  size_t free_chunks_total();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   181
  size_t free_chunks_total_in_bytes();
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
  // Number of chunks in the free chunks list
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   184
  size_t free_chunks_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   185
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   186
  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
   187
    Atomic::add_ptr(count, &_free_chunks_count);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   188
    Atomic::add_ptr(v, &_free_chunks_total);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   189
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   190
  ChunkTreeDictionary* humongous_dictionary() {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   191
    return &_humongous_dictionary;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   192
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   193
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   194
  ChunkList* free_chunks(ChunkIndex index);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   195
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   196
  // Returns the list for the given chunk word size.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   197
  ChunkList* find_free_chunks_list(size_t word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   198
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   199
  // Add and remove from a list by size.  Selects
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   200
  // list based on size of chunk.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   201
  void free_chunks_put(Metachunk* chuck);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   202
  Metachunk* free_chunks_get(size_t chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   203
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   204
  // Debug support
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   205
  void verify();
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   206
  void slow_verify() {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   207
    if (metaspace_slow_verify) {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   208
      verify();
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   209
    }
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   210
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   211
  void locked_verify();
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   212
  void slow_locked_verify() {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   213
    if (metaspace_slow_verify) {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   214
      locked_verify();
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   215
    }
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
   216
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   217
  void verify_free_chunks_total();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   218
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   219
  void locked_print_free_chunks(outputStream* st);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   220
  void locked_print_sum_free_chunks(outputStream* st);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   221
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   222
  void print_on(outputStream* st);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   223
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   224
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   225
// 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
   226
// to the allocation of a quantum of metadata).
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   227
class BlockFreelist VALUE_OBJ_CLASS_SPEC {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   228
  BlockTreeDictionary* _dictionary;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   229
  static Metablock* initialize_free_chunk(MetaWord* p, size_t word_size);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   230
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   231
  // 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
   232
  // 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
   233
  const static int WasteMultiplier = 4;
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   234
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   235
  // Accessors
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   236
  BlockTreeDictionary* dictionary() const { return _dictionary; }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   237
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   238
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   239
  BlockFreelist();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   240
  ~BlockFreelist();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   241
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   242
  // Get and return a block to the free list
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   243
  MetaWord* get_block(size_t word_size);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   244
  void return_block(MetaWord* p, size_t word_size);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   245
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   246
  size_t total_size() {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   247
  if (dictionary() == NULL) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   248
    return 0;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   249
  } else {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   250
    return dictionary()->total_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   251
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   252
}
13728
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
  void print_on(outputStream* st) const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   255
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   256
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   257
class VirtualSpaceNode : public CHeapObj<mtClass> {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   258
  friend class VirtualSpaceList;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   259
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   260
  // Link to next VirtualSpaceNode
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   261
  VirtualSpaceNode* _next;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   262
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   263
  // total in the VirtualSpace
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   264
  MemRegion _reserved;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   265
  ReservedSpace _rs;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   266
  VirtualSpace _virtual_space;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   267
  MetaWord* _top;
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   268
  // count of chunks contained in this VirtualSpace
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   269
  uintx _container_count;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   270
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   271
  // Convenience functions to access the _virtual_space
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   272
  char* low()  const { return virtual_space()->low(); }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   273
  char* high() const { return virtual_space()->high(); }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   274
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   275
  // The first Metachunk will be allocated at the bottom of the
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   276
  // VirtualSpace
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   277
  Metachunk* first_chunk() { return (Metachunk*) bottom(); }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   278
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   279
  void inc_container_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   280
#ifdef ASSERT
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   281
  uint container_count_slow();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   282
#endif
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   283
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   284
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   285
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   286
  VirtualSpaceNode(size_t byte_size);
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   287
  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
   288
  ~VirtualSpaceNode();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   289
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
   290
  // Convenience functions for logical bottom and end
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
   291
  MetaWord* bottom() const { return (MetaWord*) _virtual_space.low(); }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
   292
  MetaWord* end() const { return (MetaWord*) _virtual_space.high(); }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
   293
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   294
  // address of next available space in _virtual_space;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   295
  // Accessors
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   296
  VirtualSpaceNode* next() { return _next; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   297
  void set_next(VirtualSpaceNode* v) { _next = v; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   298
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   299
  void set_reserved(MemRegion const v) { _reserved = v; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   300
  void set_top(MetaWord* v) { _top = v; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   301
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   302
  // Accessors
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   303
  MemRegion* reserved() { return &_reserved; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   304
  VirtualSpace* virtual_space() const { return (VirtualSpace*) &_virtual_space; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   305
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   306
  // Returns true if "word_size" is available in the VirtualSpace
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   307
  bool is_available(size_t word_size) { return _top + word_size <= end(); }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   308
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   309
  MetaWord* top() const { return _top; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   310
  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
   311
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   312
  uintx container_count() { return _container_count; }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   313
  void dec_container_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   314
#ifdef ASSERT
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   315
  void verify_container_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   316
#endif
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   317
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   318
  // 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
   319
  size_t used_words_in_vs() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   320
  size_t capacity_words_in_vs() const;
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   321
  size_t free_words_in_vs() const;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   322
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   323
  bool initialize();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   324
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   325
  // get space from the virtual space
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   326
  Metachunk* take_from_committed(size_t chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   327
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   328
  // 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
   329
  Metachunk* get_chunk_vs(size_t chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   330
  Metachunk* get_chunk_vs_with_expand(size_t chunk_word_size);
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
  // 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
   333
  // to Virtualspace
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   334
  bool expand_by(size_t words, bool pre_touch = false);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   335
  bool shrink_by(size_t words);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   336
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   337
  // In preparation for deleting this node, remove all the chunks
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   338
  // in the node from any freelist.
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   339
  void purge(ChunkManager* chunk_manager);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   340
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14474
diff changeset
   341
#ifdef ASSERT
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   342
  // Debug support
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   343
  static void verify_virtual_space_total();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   344
  static void verify_virtual_space_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   345
  void mangle();
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14474
diff changeset
   346
#endif
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   347
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   348
  void print_on(outputStream* st) const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   349
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   350
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   351
  // byte_size is the size of the associated virtualspace.
19546
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 19322
diff changeset
   352
VirtualSpaceNode::VirtualSpaceNode(size_t byte_size) : _top(NULL), _next(NULL), _rs(), _container_count(0) {
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
   353
  // align up to vm allocation granularity
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
   354
  byte_size = align_size_up(byte_size, os::vm_allocation_granularity());
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
   355
16430
882cddc35bec 8008217: CDS: Class data sharing limits the malloc heap on Solaris
coleenp
parents: 16355
diff changeset
   356
  // 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
   357
  // 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
   358
  // memory addresses don't conflict.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   359
  if (DumpSharedSpaces) {
16430
882cddc35bec 8008217: CDS: Class data sharing limits the malloc heap on Solaris
coleenp
parents: 16355
diff changeset
   360
    char* shared_base = (char*)SharedBaseAddress;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   361
    _rs = ReservedSpace(byte_size, 0, false, shared_base, 0);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   362
    if (_rs.is_reserved()) {
16430
882cddc35bec 8008217: CDS: Class data sharing limits the malloc heap on Solaris
coleenp
parents: 16355
diff changeset
   363
      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
   364
    } else {
16430
882cddc35bec 8008217: CDS: Class data sharing limits the malloc heap on Solaris
coleenp
parents: 16355
diff changeset
   365
      // Get a mmap region anywhere if the SharedBaseAddress fails.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   366
      _rs = ReservedSpace(byte_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   367
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   368
    MetaspaceShared::set_shared_rs(&_rs);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   369
  } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   370
    _rs = ReservedSpace(byte_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   371
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   372
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   373
  MemTracker::record_virtual_memory_type((address)_rs.base(), mtClass);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   374
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   375
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   376
void VirtualSpaceNode::purge(ChunkManager* chunk_manager) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   377
  Metachunk* chunk = first_chunk();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   378
  Metachunk* invalid_chunk = (Metachunk*) top();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   379
  while (chunk < invalid_chunk ) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   380
    assert(chunk->is_free(), "Should be marked free");
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   381
      MetaWord* next = ((MetaWord*)chunk) + chunk->word_size();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   382
      chunk_manager->remove_chunk(chunk);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   383
      assert(chunk->next() == NULL &&
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   384
             chunk->prev() == NULL,
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   385
             "Was not removed from its list");
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   386
      chunk = (Metachunk*) next;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   387
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   388
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   389
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   390
#ifdef ASSERT
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   391
uint VirtualSpaceNode::container_count_slow() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   392
  uint count = 0;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   393
  Metachunk* chunk = first_chunk();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   394
  Metachunk* invalid_chunk = (Metachunk*) top();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   395
  while (chunk < invalid_chunk ) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   396
    MetaWord* next = ((MetaWord*)chunk) + chunk->word_size();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   397
    // Don't count the chunks on the free lists.  Those are
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   398
    // still part of the VirtualSpaceNode but not currently
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   399
    // counted.
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   400
    if (!chunk->is_free()) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   401
      count++;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   402
    }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   403
    chunk = (Metachunk*) next;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   404
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   405
  return count;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   406
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   407
#endif
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   408
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   409
// List of VirtualSpaces for metadata allocation.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   410
// It has a  _next link for singly linked list and a MemRegion
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   411
// for total space in the VirtualSpace.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   412
class VirtualSpaceList : public CHeapObj<mtClass> {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   413
  friend class VirtualSpaceNode;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   414
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   415
  enum VirtualSpaceSizes {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   416
    VirtualSpaceSize = 256 * K
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   417
  };
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   418
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   419
  // Global list of virtual spaces
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   420
  // Head of the list
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   421
  VirtualSpaceNode* _virtual_space_list;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   422
  // virtual space currently being used for allocations
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   423
  VirtualSpaceNode* _current_virtual_space;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   424
  // Free chunk list for all other metadata
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   425
  ChunkManager      _chunk_manager;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   426
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   427
  // Can this virtual list allocate >1 spaces?  Also, used to determine
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   428
  // whether to allocate unlimited small chunks in this virtual space
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   429
  bool _is_class;
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
   430
  bool can_grow() const { return !is_class() || !UseCompressedClassPointers; }
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
  // Sum of space in all virtual spaces and number of virtual spaces
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   433
  size_t _virtual_space_total;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   434
  size_t _virtual_space_count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   435
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   436
  ~VirtualSpaceList();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   437
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   438
  VirtualSpaceNode* virtual_space_list() const { return _virtual_space_list; }
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
  void set_virtual_space_list(VirtualSpaceNode* v) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   441
    _virtual_space_list = v;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   442
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   443
  void set_current_virtual_space(VirtualSpaceNode* v) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   444
    _current_virtual_space = v;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   445
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   446
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   447
  void link_vs(VirtualSpaceNode* new_entry, size_t vs_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   448
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   449
  // 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
   450
  // 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
   451
  // and is typically followed by the allocation of a chunk.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   452
  bool grow_vs(size_t vs_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   453
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   454
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   455
  VirtualSpaceList(size_t word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   456
  VirtualSpaceList(ReservedSpace rs);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   457
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   458
  size_t free_bytes();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   459
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   460
  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
   461
                           size_t grow_chunks_by_words,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   462
                           size_t medium_chunk_bunch);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   463
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   464
  // Get the first chunk for a Metaspace.  Used for
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   465
  // special cases such as the boot class loader, reflection
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   466
  // class loader and anonymous class loader.
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   467
  Metachunk* get_initialization_chunk(size_t word_size, size_t chunk_bunch);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   468
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   469
  VirtualSpaceNode* current_virtual_space() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   470
    return _current_virtual_space;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   471
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   472
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   473
  ChunkManager* chunk_manager() { return &_chunk_manager; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   474
  bool is_class() const { return _is_class; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   475
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   476
  // Allocate the first virtualspace.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   477
  void initialize(size_t word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   478
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   479
  size_t virtual_space_total() { return _virtual_space_total; }
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   480
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   481
  void inc_virtual_space_total(size_t v);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   482
  void dec_virtual_space_total(size_t v);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   483
  void inc_virtual_space_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   484
  void dec_virtual_space_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   485
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   486
  // Unlink empty VirtualSpaceNodes and free it.
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   487
  void purge();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   488
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   489
  // Used and capacity in the entire list of virtual spaces.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   490
  // These are global values shared by all Metaspaces
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   491
  size_t capacity_words_sum();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   492
  size_t capacity_bytes_sum() { return capacity_words_sum() * BytesPerWord; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   493
  size_t used_words_sum();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   494
  size_t used_bytes_sum() { return used_words_sum() * BytesPerWord; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   495
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   496
  bool contains(const void *ptr);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   497
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   498
  void print_on(outputStream* st) const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   499
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   500
  class VirtualSpaceListIterator : public StackObj {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   501
    VirtualSpaceNode* _virtual_spaces;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   502
   public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   503
    VirtualSpaceListIterator(VirtualSpaceNode* virtual_spaces) :
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   504
      _virtual_spaces(virtual_spaces) {}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   505
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   506
    bool repeat() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   507
      return _virtual_spaces != NULL;
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
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   510
    VirtualSpaceNode* get_next() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   511
      VirtualSpaceNode* result = _virtual_spaces;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   512
      if (_virtual_spaces != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   513
        _virtual_spaces = _virtual_spaces->next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   514
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   515
      return result;
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
  };
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   518
};
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
class Metadebug : AllStatic {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   521
  // Debugging support for Metaspaces
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   522
  static int _deallocate_block_a_lot_count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   523
  static int _deallocate_chunk_a_lot_count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   524
  static int _allocation_fail_alot_count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   525
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   526
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   527
  static int deallocate_block_a_lot_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   528
    return _deallocate_block_a_lot_count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   529
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   530
  static void set_deallocate_block_a_lot_count(int v) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   531
    _deallocate_block_a_lot_count = v;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   532
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   533
  static void inc_deallocate_block_a_lot_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   534
    _deallocate_block_a_lot_count++;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   535
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   536
  static int deallocate_chunk_a_lot_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   537
    return _deallocate_chunk_a_lot_count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   538
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   539
  static void reset_deallocate_chunk_a_lot_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   540
    _deallocate_chunk_a_lot_count = 1;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   541
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   542
  static void inc_deallocate_chunk_a_lot_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   543
    _deallocate_chunk_a_lot_count++;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   544
  }
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
  static void init_allocation_fail_alot_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   547
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   548
  static bool test_metadata_failure();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   549
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   550
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   551
  static void deallocate_chunk_a_lot(SpaceManager* sm,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   552
                                     size_t chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   553
  static void deallocate_block_a_lot(SpaceManager* sm,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   554
                                     size_t chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   555
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   556
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   557
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   558
int Metadebug::_deallocate_block_a_lot_count = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   559
int Metadebug::_deallocate_chunk_a_lot_count = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   560
int Metadebug::_allocation_fail_alot_count = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   561
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   562
//  SpaceManager - used by Metaspace to handle allocations
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   563
class SpaceManager : public CHeapObj<mtClass> {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   564
  friend class Metaspace;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   565
  friend class Metadebug;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   566
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   567
 private:
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   568
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   569
  // protects allocations and contains.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   570
  Mutex* const _lock;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   571
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
   572
  // Type of metadata allocated.
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
   573
  Metaspace::MetadataType _mdtype;
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
   574
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   575
  // Chunk related size
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   576
  size_t _medium_chunk_bunch;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   577
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   578
  // List of chunks in use by this SpaceManager.  Allocations
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   579
  // 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
   580
  // chunks when the SpaceManager is freed.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   581
  Metachunk* _chunks_in_use[NumberOfInUseLists];
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   582
  Metachunk* _current_chunk;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   583
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   584
  // Virtual space where allocation comes from.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   585
  VirtualSpaceList* _vs_list;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   586
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   587
  // Number of small chunks to allocate to a manager
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   588
  // If class space manager, small chunks are unlimited
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   589
  static uint const _small_chunk_limit;
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
  // 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
   592
  size_t _allocated_blocks_words;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   593
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   594
  // Sum of all allocated chunks
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   595
  size_t _allocated_chunks_words;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   596
  size_t _allocated_chunks_count;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   597
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   598
  // Free lists of blocks are per SpaceManager since they
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   599
  // 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
   600
  // 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
   601
  // the class loader using the SpaceManager is collected.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   602
  BlockFreelist _block_freelists;
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
  // protects virtualspace and chunk expansions
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   605
  static const char*  _expand_lock_name;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   606
  static const int    _expand_lock_rank;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   607
  static Mutex* const _expand_lock;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   608
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   609
 private:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   610
  // Accessors
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   611
  Metachunk* chunks_in_use(ChunkIndex index) const { return _chunks_in_use[index]; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   612
  void set_chunks_in_use(ChunkIndex index, Metachunk* v) { _chunks_in_use[index] = v; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   613
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   614
  BlockFreelist* block_freelists() const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   615
    return (BlockFreelist*) &_block_freelists;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   616
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   617
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
   618
  Metaspace::MetadataType mdtype() { return _mdtype; }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   619
  VirtualSpaceList* vs_list() const    { return _vs_list; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   620
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   621
  Metachunk* current_chunk() const { return _current_chunk; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   622
  void set_current_chunk(Metachunk* v) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   623
    _current_chunk = v;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   624
  }
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
  Metachunk* find_current_chunk(size_t word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   627
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   628
  // Add chunk to the list of chunks in use
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   629
  void add_chunk(Metachunk* v, bool make_current);
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   630
  void retire_current_chunk();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   631
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   632
  Mutex* lock() const { return _lock; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   633
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   634
  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
   635
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   636
 protected:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   637
  void initialize();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   638
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   639
 public:
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
   640
  SpaceManager(Metaspace::MetadataType mdtype,
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
   641
               Mutex* lock,
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   642
               VirtualSpaceList* vs_list);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   643
  ~SpaceManager();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   644
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   645
  enum ChunkMultiples {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   646
    MediumChunkMultiple = 4
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   647
  };
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   648
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   649
  // Accessors
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   650
  size_t specialized_chunk_size() { return SpecializedChunk; }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   651
  size_t small_chunk_size() { return (size_t) vs_list()->is_class() ? ClassSmallChunk : SmallChunk; }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   652
  size_t medium_chunk_size() { return (size_t) vs_list()->is_class() ? ClassMediumChunk : MediumChunk; }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   653
  size_t medium_chunk_bunch() { return medium_chunk_size() * MediumChunkMultiple; }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   654
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   655
  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
   656
  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
   657
  size_t allocated_chunks_words() const { return _allocated_chunks_words; }
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   658
  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
   659
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   660
  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
   661
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   662
  static Mutex* expand_lock() { return _expand_lock; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   663
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   664
  // 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
   665
  // 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
   666
  // the in-use list.
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   667
  void inc_size_metrics(size_t words);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   668
  // 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
   669
  // 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
   670
  void inc_used_metrics(size_t words);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   671
  // 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
   672
  // 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
   673
  // 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
   674
  void dec_total_from_size_metrics();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   675
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   676
  // Set the sizes for the initial chunks.
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   677
  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
   678
                               size_t* chunk_word_size,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   679
                               size_t* class_chunk_word_size);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   680
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   681
  size_t sum_capacity_in_chunks_in_use() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   682
  size_t sum_used_in_chunks_in_use() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   683
  size_t sum_free_in_chunks_in_use() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   684
  size_t sum_waste_in_chunks_in_use() const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   685
  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
   686
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   687
  size_t sum_count_in_chunks_in_use();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   688
  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
   689
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   690
  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
   691
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   692
  // Block allocation and deallocation.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   693
  // Allocates a block from the current chunk
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   694
  MetaWord* allocate(size_t word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   695
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   696
  // Helper for allocations
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   697
  MetaWord* allocate_work(size_t word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   698
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   699
  // Returns a block to the per manager freelist
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   700
  void deallocate(MetaWord* p, size_t word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   701
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   702
  // 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
   703
  // returned chunk size (for expanding space for chunk allocation).
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   704
  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
   705
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   706
  // Called when an allocation from the current chunk fails.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   707
  // 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
   708
  // and allocates from that chunk.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   709
  MetaWord* grow_and_allocate(size_t word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   710
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   711
  // debugging support.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   712
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   713
  void dump(outputStream* const out) const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   714
  void print_on(outputStream* st) const;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   715
  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
   716
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   717
  void verify();
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
   718
  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
   719
  NOT_PRODUCT(void mangle_freed_chunks();)
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   720
#ifdef ASSERT
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   721
  void verify_allocated_blocks_words();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   722
#endif
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   723
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   724
  size_t get_raw_word_size(size_t word_size) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   725
    // If only the dictionary is going to be used (i.e., no
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   726
    // indexed free list), then there is a minimum size requirement.
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   727
    // MinChunkSize is a placeholder for the real minimum size JJJ
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   728
    size_t byte_size = word_size * BytesPerWord;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   729
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   730
    size_t byte_size_with_overhead = byte_size + Metablock::overhead();
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   731
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   732
    size_t raw_bytes_size = MAX2(byte_size_with_overhead,
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   733
                                 Metablock::min_block_byte_size());
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   734
    raw_bytes_size = ARENA_ALIGN(raw_bytes_size);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   735
    size_t raw_word_size = raw_bytes_size / BytesPerWord;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   736
    assert(raw_word_size * BytesPerWord == raw_bytes_size, "Size problem");
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   737
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   738
    return raw_word_size;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
   739
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   740
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   741
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   742
uint const SpaceManager::_small_chunk_limit = 4;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   743
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   744
const char* SpaceManager::_expand_lock_name =
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   745
  "SpaceManager chunk allocation lock";
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   746
const int SpaceManager::_expand_lock_rank = Monitor::leaf - 1;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   747
Mutex* const SpaceManager::_expand_lock =
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   748
  new Mutex(SpaceManager::_expand_lock_rank,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   749
            SpaceManager::_expand_lock_name,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   750
            Mutex::_allow_vm_block_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   751
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   752
void VirtualSpaceNode::inc_container_count() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   753
  assert_lock_strong(SpaceManager::expand_lock());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   754
  _container_count++;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   755
  assert(_container_count == container_count_slow(),
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   756
         err_msg("Inconsistency in countainer_count _container_count " SIZE_FORMAT
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   757
                 "container_count_slow() " SIZE_FORMAT,
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   758
                 _container_count, container_count_slow()));
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   759
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   760
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   761
void VirtualSpaceNode::dec_container_count() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   762
  assert_lock_strong(SpaceManager::expand_lock());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   763
  _container_count--;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   764
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   765
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   766
#ifdef ASSERT
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   767
void VirtualSpaceNode::verify_container_count() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   768
  assert(_container_count == container_count_slow(),
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   769
    err_msg("Inconsistency in countainer_count _container_count " SIZE_FORMAT
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   770
            "container_count_slow() " SIZE_FORMAT, _container_count, container_count_slow()));
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   771
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   772
#endif
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   773
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   774
// BlockFreelist methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   775
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   776
BlockFreelist::BlockFreelist() : _dictionary(NULL) {}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   777
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   778
BlockFreelist::~BlockFreelist() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   779
  if (_dictionary != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   780
    if (Verbose && TraceMetadataChunkAllocation) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   781
      _dictionary->print_free_lists(gclog_or_tty);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   782
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   783
    delete _dictionary;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   784
  }
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
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   787
Metablock* BlockFreelist::initialize_free_chunk(MetaWord* p, size_t word_size) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   788
  Metablock* block = (Metablock*) p;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   789
  block->set_word_size(word_size);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   790
  block->set_prev(NULL);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   791
  block->set_next(NULL);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   792
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   793
  return block;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   794
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   795
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   796
void BlockFreelist::return_block(MetaWord* p, size_t word_size) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   797
  Metablock* free_chunk = initialize_free_chunk(p, word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   798
  if (dictionary() == NULL) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   799
   _dictionary = new BlockTreeDictionary();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   800
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   801
  dictionary()->return_chunk(free_chunk);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   802
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   803
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   804
MetaWord* BlockFreelist::get_block(size_t word_size) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   805
  if (dictionary() == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   806
    return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   807
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   808
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   809
  if (word_size < TreeChunk<Metablock, FreeList>::min_size()) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   810
    // Dark matter.  Too small for dictionary.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   811
    return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   812
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   813
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   814
  Metablock* free_block =
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   815
    dictionary()->get_chunk(word_size, FreeBlockDictionary<Metablock>::atLeast);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   816
  if (free_block == NULL) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   817
    return NULL;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   818
  }
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
   819
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   820
  const size_t block_size = free_block->size();
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   821
  if (block_size > WasteMultiplier * word_size) {
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   822
    return_block((MetaWord*)free_block, block_size);
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   823
    return NULL;
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   824
  }
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   825
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   826
  MetaWord* new_block = (MetaWord*)free_block;
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   827
  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
   828
  const size_t unused = block_size - word_size;
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   829
  if (unused >= TreeChunk<Metablock, FreeList>::min_size()) {
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   830
    return_block(new_block + word_size, unused);
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   831
  }
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   832
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
   833
  return new_block;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   834
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   835
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   836
void BlockFreelist::print_on(outputStream* st) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   837
  if (dictionary() == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   838
    return;
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
  dictionary()->print_free_lists(st);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   841
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   842
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   843
// VirtualSpaceNode methods
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
VirtualSpaceNode::~VirtualSpaceNode() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   846
  _rs.release();
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   847
#ifdef ASSERT
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   848
  size_t word_size = sizeof(*this) / BytesPerWord;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   849
  Copy::fill_to_words((HeapWord*) this, word_size, 0xf1f1f1f1);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   850
#endif
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   851
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   852
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   853
size_t VirtualSpaceNode::used_words_in_vs() const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   854
  return pointer_delta(top(), bottom(), sizeof(MetaWord));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   855
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   856
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   857
// Space committed in the VirtualSpace
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   858
size_t VirtualSpaceNode::capacity_words_in_vs() const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   859
  return pointer_delta(end(), bottom(), sizeof(MetaWord));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   860
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   861
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   862
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
   863
  return pointer_delta(end(), top(), sizeof(MetaWord));
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
   864
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   865
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   866
// Allocates the chunk from the virtual space only.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   867
// 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
   868
// chunks removed here are necessarily used for allocation.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   869
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
   870
  // Bottom of the new chunk
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   871
  MetaWord* chunk_limit = top();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   872
  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
   873
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   874
  if (!is_available(chunk_word_size)) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   875
    if (TraceMetadataChunkAllocation) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   876
      tty->print("VirtualSpaceNode::take_from_committed() not available %d words ", chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   877
      // Dump some information about the virtual space that is nearly full
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   878
      print_on(tty);
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
    return NULL;
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
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   883
  // 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
   884
  inc_top(chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   885
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   886
  // Initialize the chunk
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   887
  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
   888
  return result;
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
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   891
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   892
// Expand the virtual space (commit more of the reserved space)
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   893
bool VirtualSpaceNode::expand_by(size_t words, bool pre_touch) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   894
  size_t bytes = words * BytesPerWord;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   895
  bool result =  virtual_space()->expand_by(bytes, pre_touch);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   896
  if (TraceMetavirtualspaceAllocation && !result) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   897
    gclog_or_tty->print_cr("VirtualSpaceNode::expand_by() failed "
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   898
                           "for byte size " SIZE_FORMAT, bytes);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   899
    virtual_space()->print();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   900
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   901
  return result;
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
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   904
// Shrink the virtual space (commit more of the reserved space)
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   905
bool VirtualSpaceNode::shrink_by(size_t words) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   906
  size_t bytes = words * BytesPerWord;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   907
  virtual_space()->shrink_by(bytes);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   908
  return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   909
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   910
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   911
// Add another chunk to the chunk list.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   912
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   913
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
   914
  assert_lock_strong(SpaceManager::expand_lock());
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   915
  Metachunk* result = take_from_committed(chunk_word_size);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   916
  if (result != NULL) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   917
    inc_container_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   918
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   919
  return result;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   920
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   921
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   922
Metachunk* VirtualSpaceNode::get_chunk_vs_with_expand(size_t chunk_word_size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   923
  assert_lock_strong(SpaceManager::expand_lock());
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
  Metachunk* new_chunk = get_chunk_vs(chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   926
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   927
  if (new_chunk == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   928
    // Only a small part of the virtualspace is committed when first
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   929
    // allocated so committing more here can be expected.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   930
    size_t page_size_words = os::vm_page_size() / BytesPerWord;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   931
    size_t aligned_expand_vs_by_words = align_size_up(chunk_word_size,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   932
                                                    page_size_words);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   933
    expand_by(aligned_expand_vs_by_words, false);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   934
    new_chunk = get_chunk_vs(chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   935
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   936
  return new_chunk;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   937
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   938
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   939
bool VirtualSpaceNode::initialize() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   940
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   941
  if (!_rs.is_reserved()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   942
    return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   943
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   944
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   945
  // An allocation out of this Virtualspace that is larger
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   946
  // than an initial commit size can waste that initial committed
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   947
  // space.
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   948
  size_t committed_byte_size = 0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   949
  bool result = virtual_space()->initialize(_rs, committed_byte_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   950
  if (result) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   951
    set_top((MetaWord*)virtual_space()->low());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   952
    set_reserved(MemRegion((HeapWord*)_rs.base(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   953
                 (HeapWord*)(_rs.base() + _rs.size())));
13729
3826a6124401 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 13728
diff changeset
   954
3826a6124401 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 13728
diff changeset
   955
    assert(reserved()->start() == (HeapWord*) _rs.base(),
3826a6124401 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 13728
diff changeset
   956
      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
   957
        " != " PTR_FORMAT, reserved()->start(), _rs.base()));
3826a6124401 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 13728
diff changeset
   958
    assert(reserved()->word_size() == _rs.size() / BytesPerWord,
3826a6124401 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 13728
diff changeset
   959
      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
   960
        " != " SIZE_FORMAT, reserved()->word_size(),
3826a6124401 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 13728
diff changeset
   961
        _rs.size() / BytesPerWord));
13728
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
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   964
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   965
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   966
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   967
void VirtualSpaceNode::print_on(outputStream* st) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   968
  size_t used = used_words_in_vs();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   969
  size_t capacity = capacity_words_in_vs();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   970
  VirtualSpace* vs = virtual_space();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   971
  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
   972
           "[" PTR_FORMAT ", " PTR_FORMAT ", "
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   973
           PTR_FORMAT ", " PTR_FORMAT ")",
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   974
           vs, capacity / K,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
   975
           capacity == 0 ? 0 : used * 100 / capacity,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   976
           bottom(), top(), end(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   977
           vs->high_boundary());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   978
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   979
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14474
diff changeset
   980
#ifdef ASSERT
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   981
void VirtualSpaceNode::mangle() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   982
  size_t word_size = capacity_words_in_vs();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   983
  Copy::fill_to_words((HeapWord*) low(), word_size, 0xf1f1f1f1);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   984
}
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14474
diff changeset
   985
#endif // ASSERT
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   986
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   987
// VirtualSpaceList methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   988
// Space allocated from the VirtualSpace
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   989
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   990
VirtualSpaceList::~VirtualSpaceList() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   991
  VirtualSpaceListIterator iter(virtual_space_list());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   992
  while (iter.repeat()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   993
    VirtualSpaceNode* vsl = iter.get_next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   994
    delete vsl;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   995
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   996
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   997
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   998
void VirtualSpaceList::inc_virtual_space_total(size_t v) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
   999
  assert_lock_strong(SpaceManager::expand_lock());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1000
  _virtual_space_total = _virtual_space_total + v;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1001
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1002
void VirtualSpaceList::dec_virtual_space_total(size_t v) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1003
  assert_lock_strong(SpaceManager::expand_lock());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1004
  _virtual_space_total = _virtual_space_total - v;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1005
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1006
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1007
void VirtualSpaceList::inc_virtual_space_count() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1008
  assert_lock_strong(SpaceManager::expand_lock());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1009
  _virtual_space_count++;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1010
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1011
void VirtualSpaceList::dec_virtual_space_count() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1012
  assert_lock_strong(SpaceManager::expand_lock());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1013
  _virtual_space_count--;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1014
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1015
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1016
void ChunkManager::remove_chunk(Metachunk* chunk) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1017
  size_t word_size = chunk->word_size();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1018
  ChunkIndex index = list_index(word_size);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1019
  if (index != HumongousIndex) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1020
    free_chunks(index)->remove_chunk(chunk);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1021
  } else {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1022
    humongous_dictionary()->remove_chunk(chunk);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1023
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1024
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1025
  // Chunk is being removed from the chunks free list.
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1026
  dec_free_chunks_total(chunk->capacity_word_size());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1027
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1028
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1029
// Walk the list of VirtualSpaceNodes and delete
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1030
// nodes with a 0 container_count.  Remove Metachunks in
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1031
// the node from their respective freelists.
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1032
void VirtualSpaceList::purge() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1033
  assert_lock_strong(SpaceManager::expand_lock());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1034
  // Don't use a VirtualSpaceListIterator because this
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1035
  // 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
  1036
  VirtualSpaceNode* purged_vsl = NULL;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1037
  VirtualSpaceNode* prev_vsl = virtual_space_list();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1038
  VirtualSpaceNode* next_vsl = prev_vsl;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1039
  while (next_vsl != NULL) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1040
    VirtualSpaceNode* vsl = next_vsl;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1041
    next_vsl = vsl->next();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1042
    // Don't free the current virtual space since it will likely
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1043
    // be needed soon.
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1044
    if (vsl->container_count() == 0 && vsl != current_virtual_space()) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1045
      // Unlink it from the list
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1046
      if (prev_vsl == vsl) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1047
        // This is the case of the current note being the first note.
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1048
        assert(vsl == virtual_space_list(), "Expected to be the first note");
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1049
        set_virtual_space_list(vsl->next());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1050
      } else {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1051
        prev_vsl->set_next(vsl->next());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1052
      }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1053
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1054
      vsl->purge(chunk_manager());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1055
      dec_virtual_space_total(vsl->reserved()->word_size());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1056
      dec_virtual_space_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1057
      purged_vsl = vsl;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1058
      delete vsl;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1059
    } else {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1060
      prev_vsl = vsl;
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1061
    }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1062
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1063
#ifdef ASSERT
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1064
  if (purged_vsl != NULL) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1065
  // List should be stable enough to use an iterator here.
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1066
  VirtualSpaceListIterator iter(virtual_space_list());
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1067
    while (iter.repeat()) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1068
      VirtualSpaceNode* vsl = iter.get_next();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1069
      assert(vsl != purged_vsl, "Purge of vsl failed");
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1070
    }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1071
  }
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1072
#endif
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1073
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1074
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1075
size_t VirtualSpaceList::used_words_sum() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1076
  size_t allocated_by_vs = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1077
  VirtualSpaceListIterator iter(virtual_space_list());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1078
  while (iter.repeat()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1079
    VirtualSpaceNode* vsl = iter.get_next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1080
    // Sum used region [bottom, top) in each virtualspace
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1081
    allocated_by_vs += vsl->used_words_in_vs();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1082
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1083
  assert(allocated_by_vs >= chunk_manager()->free_chunks_total(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1084
    err_msg("Total in free chunks " SIZE_FORMAT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1085
            " greater than total from virtual_spaces " SIZE_FORMAT,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1086
            allocated_by_vs, chunk_manager()->free_chunks_total()));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1087
  size_t used =
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1088
    allocated_by_vs - chunk_manager()->free_chunks_total();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1089
  return used;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1090
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1091
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1092
// Space available in all MetadataVirtualspaces allocated
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1093
// for metadata.  This is the upper limit on the capacity
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1094
// of chunks allocated out of all the MetadataVirtualspaces.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1095
size_t VirtualSpaceList::capacity_words_sum() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1096
  size_t capacity = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1097
  VirtualSpaceListIterator iter(virtual_space_list());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1098
  while (iter.repeat()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1099
    VirtualSpaceNode* vsl = iter.get_next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1100
    capacity += vsl->capacity_words_in_vs();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1101
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1102
  return capacity;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1103
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1104
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1105
VirtualSpaceList::VirtualSpaceList(size_t word_size ) :
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1106
                                   _is_class(false),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1107
                                   _virtual_space_list(NULL),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1108
                                   _current_virtual_space(NULL),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1109
                                   _virtual_space_total(0),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1110
                                   _virtual_space_count(0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1111
  MutexLockerEx cl(SpaceManager::expand_lock(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1112
                   Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1113
  bool initialization_succeeded = grow_vs(word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1114
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  1115
  _chunk_manager.free_chunks(SpecializedIndex)->set_size(SpecializedChunk);
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  1116
  _chunk_manager.free_chunks(SmallIndex)->set_size(SmallChunk);
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  1117
  _chunk_manager.free_chunks(MediumIndex)->set_size(MediumChunk);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1118
  assert(initialization_succeeded,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1119
    " VirtualSpaceList initialization should not fail");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1120
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1121
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1122
VirtualSpaceList::VirtualSpaceList(ReservedSpace rs) :
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1123
                                   _is_class(true),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1124
                                   _virtual_space_list(NULL),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1125
                                   _current_virtual_space(NULL),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1126
                                   _virtual_space_total(0),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1127
                                   _virtual_space_count(0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1128
  MutexLockerEx cl(SpaceManager::expand_lock(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1129
                   Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1130
  VirtualSpaceNode* class_entry = new VirtualSpaceNode(rs);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1131
  bool succeeded = class_entry->initialize();
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  1132
  _chunk_manager.free_chunks(SpecializedIndex)->set_size(SpecializedChunk);
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  1133
  _chunk_manager.free_chunks(SmallIndex)->set_size(ClassSmallChunk);
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  1134
  _chunk_manager.free_chunks(MediumIndex)->set_size(ClassMediumChunk);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1135
  assert(succeeded, " VirtualSpaceList initialization should not fail");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1136
  link_vs(class_entry, rs.size()/BytesPerWord);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1137
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1138
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1139
size_t VirtualSpaceList::free_bytes() {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1140
  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
  1141
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1142
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1143
// Allocate another meta virtual space and add it to the list.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1144
bool VirtualSpaceList::grow_vs(size_t vs_word_size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1145
  assert_lock_strong(SpaceManager::expand_lock());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1146
  if (vs_word_size == 0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1147
    return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1148
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1149
  // Reserve the space
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1150
  size_t vs_byte_size = vs_word_size * BytesPerWord;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1151
  assert(vs_byte_size % os::vm_page_size() == 0, "Not aligned");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1152
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1153
  // Allocate the meta virtual space and initialize it.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1154
  VirtualSpaceNode* new_entry = new VirtualSpaceNode(vs_byte_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1155
  if (!new_entry->initialize()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1156
    delete new_entry;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1157
    return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1158
  } else {
14579
7f6ce6e3dd80 8003635: NPG: AsynchGetCallTrace broken by Method* virtual call
coleenp
parents: 14474
diff changeset
  1159
    // ensure lock-free iteration sees fully initialized node
7f6ce6e3dd80 8003635: NPG: AsynchGetCallTrace broken by Method* virtual call
coleenp
parents: 14474
diff changeset
  1160
    OrderAccess::storestore();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1161
    link_vs(new_entry, vs_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1162
    return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1163
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1164
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1165
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1166
void VirtualSpaceList::link_vs(VirtualSpaceNode* new_entry, size_t vs_word_size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1167
  if (virtual_space_list() == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1168
      set_virtual_space_list(new_entry);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1169
  } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1170
    current_virtual_space()->set_next(new_entry);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1171
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1172
  set_current_virtual_space(new_entry);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1173
  inc_virtual_space_total(vs_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1174
  inc_virtual_space_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1175
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1176
  new_entry->mangle();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1177
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1178
  if (TraceMetavirtualspaceAllocation && Verbose) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1179
    VirtualSpaceNode* vsl = current_virtual_space();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1180
    vsl->print_on(tty);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1181
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1182
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1183
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1184
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
  1185
                                           size_t grow_chunks_by_words,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1186
                                           size_t medium_chunk_bunch) {
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
  // Get a chunk from the chunk freelist
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1189
  Metachunk* next = chunk_manager()->chunk_freelist_allocate(grow_chunks_by_words);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1190
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1191
  if (next != NULL) {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1192
    next->container()->inc_container_count();
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1193
  } else {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1194
    // Allocate a chunk out of the current virtual space.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1195
    next = current_virtual_space()->get_chunk_vs(grow_chunks_by_words);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1196
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1197
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1198
  if (next == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1199
    // Not enough room in current virtual space.  Try to commit
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1200
    // more space.
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1201
    size_t expand_vs_by_words = MAX2(medium_chunk_bunch,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1202
                                     grow_chunks_by_words);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1203
    size_t page_size_words = os::vm_page_size() / BytesPerWord;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1204
    size_t aligned_expand_vs_by_words = align_size_up(expand_vs_by_words,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1205
                                                        page_size_words);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1206
    bool vs_expanded =
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1207
      current_virtual_space()->expand_by(aligned_expand_vs_by_words, false);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1208
    if (!vs_expanded) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1209
      // Should the capacity of the metaspaces be expanded for
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1210
      // this allocation?  If it's the virtual space for classes and is
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1211
      // being used for CompressedHeaders, don't allocate a new virtualspace.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1212
      if (can_grow() && MetaspaceGC::should_expand(this, word_size)) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1213
        // Get another virtual space.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1214
          size_t grow_vs_words =
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1215
            MAX2((size_t)VirtualSpaceSize, aligned_expand_vs_by_words);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1216
        if (grow_vs(grow_vs_words)) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1217
          // Got it.  It's on the list now.  Get a chunk from it.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1218
          next = current_virtual_space()->get_chunk_vs_with_expand(grow_chunks_by_words);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1219
        }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1220
      } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1221
        // Allocation will fail and induce a GC
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1222
        if (TraceMetadataChunkAllocation && Verbose) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1223
          gclog_or_tty->print_cr("VirtualSpaceList::get_new_chunk():"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1224
            " Fail instead of expand the metaspace");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1225
        }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1226
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1227
    } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1228
      // The virtual space expanded, get a new chunk
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1229
      next = current_virtual_space()->get_chunk_vs(grow_chunks_by_words);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1230
      assert(next != NULL, "Just expanded, should succeed");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1231
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1232
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1233
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1234
  assert(next == NULL || (next->next() == NULL && next->prev() == NULL),
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1235
         "New chunk is still on some list");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1236
  return next;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1237
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1238
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1239
Metachunk* VirtualSpaceList::get_initialization_chunk(size_t chunk_word_size,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1240
                                                      size_t chunk_bunch) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1241
  // Get a chunk from the chunk freelist
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1242
  Metachunk* new_chunk = get_new_chunk(chunk_word_size,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1243
                                       chunk_word_size,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1244
                                       chunk_bunch);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1245
  return new_chunk;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1246
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1247
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1248
void VirtualSpaceList::print_on(outputStream* st) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1249
  if (TraceMetadataChunkAllocation && Verbose) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1250
    VirtualSpaceListIterator iter(virtual_space_list());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1251
    while (iter.repeat()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1252
      VirtualSpaceNode* node = iter.get_next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1253
      node->print_on(st);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1254
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1255
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1256
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1257
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1258
bool VirtualSpaceList::contains(const void *ptr) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1259
  VirtualSpaceNode* list = virtual_space_list();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1260
  VirtualSpaceListIterator iter(list);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1261
  while (iter.repeat()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1262
    VirtualSpaceNode* node = iter.get_next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1263
    if (node->reserved()->contains(ptr)) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1264
      return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1265
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1266
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1267
  return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1268
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1269
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1270
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1271
// MetaspaceGC methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1272
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1273
// VM_CollectForMetadataAllocation is the vm operation used to GC.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1274
// 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
  1275
// 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
  1276
// 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
  1277
// 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
  1278
// gen had bounds, MinMetaspaceExpansion and MaxMetaspaceExpansion.  The
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1279
// 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
  1280
//
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1281
// 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
  1282
// 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
  1283
// 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
  1284
// 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
  1285
// 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
  1286
// 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
  1287
// 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
  1288
// 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
  1289
// the HWM.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1290
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1291
// 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
  1292
// Increase by a minimum amount (MinMetaspaceExpansion) so that
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1293
// another expansion is not requested too soon.  If that is not
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1294
// enough to satisfy the allocation (i.e. big enough for a word_size
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1295
// allocation), increase by MaxMetaspaceExpansion.  If that is still
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1296
// not enough, expand by the size of the allocation (word_size) plus
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1297
// some.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1298
size_t MetaspaceGC::delta_capacity_until_GC(size_t word_size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1299
  size_t before_inc = MetaspaceGC::capacity_until_GC();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1300
  size_t min_delta_words = MinMetaspaceExpansion / BytesPerWord;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1301
  size_t max_delta_words = MaxMetaspaceExpansion / BytesPerWord;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1302
  size_t page_size_words = os::vm_page_size() / BytesPerWord;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1303
  size_t size_delta_words = align_size_up(word_size, page_size_words);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1304
  size_t delta_words = MAX2(size_delta_words, min_delta_words);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1305
  if (delta_words > min_delta_words) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1306
    // 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
  1307
    // allocation so make the delta greater than just enough
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1308
    // for this allocation.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1309
    delta_words = MAX2(delta_words, max_delta_words);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1310
    if (delta_words > max_delta_words) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1311
      // This allocation is large but the next ones are probably not
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1312
      // so increase by the minimum.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1313
      delta_words = delta_words + min_delta_words;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1314
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1315
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1316
  return delta_words;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1317
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1318
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1319
bool MetaspaceGC::should_expand(VirtualSpaceList* vsl, size_t word_size) {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1320
16391
7bf8a7699f5f 8004241: NPG: Metaspace occupies more memory than specified by -XX:MaxMetaspaceSize option
mgerdin
parents: 16387
diff changeset
  1321
  // If the user wants a limit, impose one.
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
  1322
  // The reason for someone using this flag is to limit reserved space.  So
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  1323
  // for non-class virtual space, compare against virtual spaces that are reserved.
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  1324
  // For class virtual space, we only compare against the committed space, not
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  1325
  // reserved space, because this is a larger space prereserved for compressed
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  1326
  // class pointers.
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  1327
  if (!FLAG_IS_DEFAULT(MaxMetaspaceSize)) {
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  1328
    size_t real_allocated = Metaspace::space_list()->virtual_space_total() +
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  1329
              MetaspaceAux::allocated_capacity_bytes(Metaspace::ClassType);
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  1330
    if (real_allocated >= MaxMetaspaceSize) {
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  1331
      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
  1332
    }
16391
7bf8a7699f5f 8004241: NPG: Metaspace occupies more memory than specified by -XX:MaxMetaspaceSize option
mgerdin
parents: 16387
diff changeset
  1333
  }
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
  // Class virtual space should always be expanded.  Call GC for the other
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1336
  // metadata virtual space.
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  1337
  if (Metaspace::using_class_space() &&
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  1338
      (vsl == Metaspace::class_space_list())) return true;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1339
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1340
  // If this is part of an allocation after a GC, expand
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1341
  // unconditionally.
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1342
  if (MetaspaceGC::expand_after_GC()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1343
    return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1344
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1345
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1346
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1347
  // If the capacity is below the minimum capacity, allow the
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1348
  // expansion.  Also set the high-water-mark (capacity_until_GC)
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1349
  // to that minimum capacity so that a GC will not be induced
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1350
  // until that minimum capacity is exceeded.
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
  1351
  size_t committed_capacity_bytes = MetaspaceAux::allocated_capacity_bytes();
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  1352
  size_t metaspace_size_bytes = MetaspaceSize;
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1353
  if (committed_capacity_bytes < metaspace_size_bytes ||
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1354
      capacity_until_GC() == 0) {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1355
    set_capacity_until_GC(metaspace_size_bytes);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1356
    return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1357
  } else {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1358
    if (committed_capacity_bytes < capacity_until_GC()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1359
      return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1360
    } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1361
      if (TraceMetadataChunkAllocation && Verbose) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1362
        gclog_or_tty->print_cr("  allocation request size " SIZE_FORMAT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1363
                        "  capacity_until_GC " SIZE_FORMAT
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1364
                        "  allocated_capacity_bytes " SIZE_FORMAT,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1365
                        word_size,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1366
                        capacity_until_GC(),
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1367
                        MetaspaceAux::allocated_capacity_bytes());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1368
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1369
      return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1370
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1371
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1372
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1373
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1374
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1375
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1376
void MetaspaceGC::compute_new_size() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1377
  assert(_shrink_factor <= 100, "invalid shrink factor");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1378
  uint current_shrink_factor = _shrink_factor;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1379
  _shrink_factor = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1380
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1381
  // Until a faster way of calculating the "used" quantity is implemented,
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1382
  // use "capacity".
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1383
  const size_t used_after_gc = MetaspaceAux::allocated_capacity_bytes();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1384
  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
  1385
15610
528d799702c7 8005452: NPG: Create new flags for Metaspace resizing policy
jmasa
parents: 15488
diff changeset
  1386
  const double minimum_free_percentage = MinMetaspaceFreeRatio / 100.0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1387
  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
  1388
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1389
  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
  1390
  size_t minimum_desired_capacity =
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1391
    (size_t)MIN2(min_tmp, double(max_uintx));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1392
  // Don't shrink less than the initial generation size
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1393
  minimum_desired_capacity = MAX2(minimum_desired_capacity,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1394
                                  MetaspaceSize);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1395
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1396
  if (PrintGCDetails && Verbose) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1397
    gclog_or_tty->print_cr("\nMetaspaceGC::compute_new_size: ");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1398
    gclog_or_tty->print_cr("  "
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1399
                  "  minimum_free_percentage: %6.2f"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1400
                  "  maximum_used_percentage: %6.2f",
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1401
                  minimum_free_percentage,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1402
                  maximum_used_percentage);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1403
    gclog_or_tty->print_cr("  "
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1404
                  "   used_after_gc       : %6.1fKB",
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1405
                  used_after_gc / (double) K);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1406
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1407
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1408
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1409
  size_t shrink_bytes = 0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1410
  if (capacity_until_GC < minimum_desired_capacity) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1411
    // 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
  1412
    // increment the HWM.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1413
    size_t expand_bytes = minimum_desired_capacity - capacity_until_GC;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1414
    // Don't expand unless it's significant
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1415
    if (expand_bytes >= MinMetaspaceExpansion) {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1416
      MetaspaceGC::set_capacity_until_GC(capacity_until_GC + expand_bytes);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1417
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1418
    if (PrintGCDetails && Verbose) {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1419
      size_t new_capacity_until_GC = capacity_until_GC;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1420
      gclog_or_tty->print_cr("    expanding:"
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1421
                    "  minimum_desired_capacity: %6.1fKB"
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1422
                    "  expand_bytes: %6.1fKB"
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1423
                    "  MinMetaspaceExpansion: %6.1fKB"
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1424
                    "  new metaspace HWM:  %6.1fKB",
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1425
                    minimum_desired_capacity / (double) K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1426
                    expand_bytes / (double) K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1427
                    MinMetaspaceExpansion / (double) K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1428
                    new_capacity_until_GC / (double) K);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1429
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1430
    return;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1431
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1432
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1433
  // No expansion, now see if we want to shrink
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1434
  // We would never want to shrink more than this
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1435
  size_t max_shrink_bytes = capacity_until_GC - minimum_desired_capacity;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1436
  assert(max_shrink_bytes >= 0, err_msg("max_shrink_bytes " SIZE_FORMAT,
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1437
    max_shrink_bytes));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1438
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1439
  // Should shrinking be considered?
15610
528d799702c7 8005452: NPG: Create new flags for Metaspace resizing policy
jmasa
parents: 15488
diff changeset
  1440
  if (MaxMetaspaceFreeRatio < 100) {
528d799702c7 8005452: NPG: Create new flags for Metaspace resizing policy
jmasa
parents: 15488
diff changeset
  1441
    const double maximum_free_percentage = MaxMetaspaceFreeRatio / 100.0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1442
    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
  1443
    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
  1444
    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
  1445
    maximum_desired_capacity = MAX2(maximum_desired_capacity,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1446
                                    MetaspaceSize);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1447
    if (PrintGCDetails && Verbose) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1448
      gclog_or_tty->print_cr("  "
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1449
                             "  maximum_free_percentage: %6.2f"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1450
                             "  minimum_used_percentage: %6.2f",
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1451
                             maximum_free_percentage,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1452
                             minimum_used_percentage);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1453
      gclog_or_tty->print_cr("  "
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1454
                             "  minimum_desired_capacity: %6.1fKB"
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1455
                             "  maximum_desired_capacity: %6.1fKB",
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1456
                             minimum_desired_capacity / (double) K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1457
                             maximum_desired_capacity / (double) K);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1458
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1459
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1460
    assert(minimum_desired_capacity <= maximum_desired_capacity,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1461
           "sanity check");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1462
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1463
    if (capacity_until_GC > maximum_desired_capacity) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1464
      // Capacity too large, compute shrinking size
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1465
      shrink_bytes = capacity_until_GC - maximum_desired_capacity;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1466
      // 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
  1467
      // 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
  1468
      // 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
  1469
      // 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
  1470
      // 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
  1471
      // 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
  1472
      shrink_bytes = shrink_bytes / 100 * current_shrink_factor;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1473
      assert(shrink_bytes <= max_shrink_bytes,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1474
        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
  1475
          shrink_bytes, max_shrink_bytes));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1476
      if (current_shrink_factor == 0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1477
        _shrink_factor = 10;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1478
      } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1479
        _shrink_factor = MIN2(current_shrink_factor * 4, (uint) 100);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1480
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1481
      if (PrintGCDetails && Verbose) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1482
        gclog_or_tty->print_cr("  "
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1483
                      "  shrinking:"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1484
                      "  initSize: %.1fK"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1485
                      "  maximum_desired_capacity: %.1fK",
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1486
                      MetaspaceSize / (double) K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1487
                      maximum_desired_capacity / (double) K);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1488
        gclog_or_tty->print_cr("  "
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1489
                      "  shrink_bytes: %.1fK"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1490
                      "  current_shrink_factor: %d"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1491
                      "  new shrink factor: %d"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1492
                      "  MinMetaspaceExpansion: %.1fK",
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1493
                      shrink_bytes / (double) K,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1494
                      current_shrink_factor,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1495
                      _shrink_factor,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1496
                      MinMetaspaceExpansion / (double) K);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1497
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1498
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1499
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1500
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1501
  // 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
  1502
  if (shrink_bytes >= MinMetaspaceExpansion &&
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1503
      ((capacity_until_GC - shrink_bytes) >= MetaspaceSize)) {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1504
    MetaspaceGC::set_capacity_until_GC(capacity_until_GC - shrink_bytes);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1505
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1506
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1507
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1508
// Metadebug methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1509
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1510
void Metadebug::deallocate_chunk_a_lot(SpaceManager* sm,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1511
                                       size_t chunk_word_size){
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1512
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1513
  VirtualSpaceList* vsl = sm->vs_list();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1514
  if (MetaDataDeallocateALot &&
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1515
      Metadebug::deallocate_chunk_a_lot_count() % MetaDataDeallocateALotInterval == 0 ) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1516
    Metadebug::reset_deallocate_chunk_a_lot_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1517
    for (uint i = 0; i < metadata_deallocate_a_lock_chunk; i++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1518
      Metachunk* dummy_chunk = vsl->current_virtual_space()->take_from_committed(chunk_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1519
      if (dummy_chunk == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1520
        break;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1521
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1522
      vsl->chunk_manager()->chunk_freelist_deallocate(dummy_chunk);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1523
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1524
      if (TraceMetadataChunkAllocation && Verbose) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1525
        gclog_or_tty->print("Metadebug::deallocate_chunk_a_lot: %d) ",
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1526
                               sm->sum_count_in_chunks_in_use());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1527
        dummy_chunk->print_on(gclog_or_tty);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1528
        gclog_or_tty->print_cr("  Free chunks total %d  count %d",
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1529
                               vsl->chunk_manager()->free_chunks_total(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1530
                               vsl->chunk_manager()->free_chunks_count());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1531
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1532
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1533
  } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1534
    Metadebug::inc_deallocate_chunk_a_lot_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1535
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1536
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1537
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1538
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1539
void Metadebug::deallocate_block_a_lot(SpaceManager* sm,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1540
                                       size_t raw_word_size){
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1541
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1542
  if (MetaDataDeallocateALot &&
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1543
        Metadebug::deallocate_block_a_lot_count() % MetaDataDeallocateALotInterval == 0 ) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1544
    Metadebug::set_deallocate_block_a_lot_count(0);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1545
    for (uint i = 0; i < metadata_deallocate_a_lot_block; i++) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1546
      MetaWord* dummy_block = sm->allocate_work(raw_word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1547
      if (dummy_block == 0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1548
        break;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1549
      }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1550
      sm->deallocate(dummy_block, raw_word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1551
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1552
  } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1553
    Metadebug::inc_deallocate_block_a_lot_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1554
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1555
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1556
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1557
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1558
void Metadebug::init_allocation_fail_alot_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1559
  if (MetadataAllocationFailALot) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1560
    _allocation_fail_alot_count =
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1561
      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
  1562
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1563
}
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
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1566
bool Metadebug::test_metadata_failure() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1567
  if (MetadataAllocationFailALot &&
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1568
      Threads::is_vm_complete()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1569
    if (_allocation_fail_alot_count > 0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1570
      _allocation_fail_alot_count--;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1571
    } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1572
      if (TraceMetadataChunkAllocation && Verbose) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1573
        gclog_or_tty->print_cr("Metadata allocation failing for "
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1574
                               "MetadataAllocationFailALot");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1575
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1576
      init_allocation_fail_alot_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1577
      return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1578
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1579
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1580
  return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1581
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1582
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1583
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1584
// ChunkManager methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1585
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1586
size_t ChunkManager::free_chunks_total() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1587
  return _free_chunks_total;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1588
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1589
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1590
size_t ChunkManager::free_chunks_total_in_bytes() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1591
  return free_chunks_total() * BytesPerWord;
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
size_t ChunkManager::free_chunks_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1595
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1596
  if (!UseConcMarkSweepGC && !SpaceManager::expand_lock()->is_locked()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1597
    MutexLockerEx cl(SpaceManager::expand_lock(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1598
                     Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1599
    // 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
  1600
    // 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
  1601
    slow_locked_verify_free_chunks_count();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1602
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1603
#endif
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  1604
  return _free_chunks_count;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1605
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1606
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1607
void ChunkManager::locked_verify_free_chunks_total() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1608
  assert_lock_strong(SpaceManager::expand_lock());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1609
  assert(sum_free_chunks() == _free_chunks_total,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1610
    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
  1611
           " same as sum " SIZE_FORMAT, _free_chunks_total,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1612
           sum_free_chunks()));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1613
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1614
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1615
void ChunkManager::verify_free_chunks_total() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1616
  MutexLockerEx cl(SpaceManager::expand_lock(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1617
                     Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1618
  locked_verify_free_chunks_total();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1619
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1620
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1621
void ChunkManager::locked_verify_free_chunks_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1622
  assert_lock_strong(SpaceManager::expand_lock());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1623
  assert(sum_free_chunks_count() == _free_chunks_count,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1624
    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
  1625
           " same as sum " SIZE_FORMAT, _free_chunks_count,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1626
           sum_free_chunks_count()));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1627
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1628
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1629
void ChunkManager::verify_free_chunks_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1630
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1631
  MutexLockerEx cl(SpaceManager::expand_lock(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1632
                     Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1633
  locked_verify_free_chunks_count();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1634
#endif
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
void ChunkManager::verify() {
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  1638
  MutexLockerEx cl(SpaceManager::expand_lock(),
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  1639
                     Mutex::_no_safepoint_check_flag);
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  1640
  locked_verify();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1641
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1642
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1643
void ChunkManager::locked_verify() {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1644
  locked_verify_free_chunks_count();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1645
  locked_verify_free_chunks_total();
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
void ChunkManager::locked_print_free_chunks(outputStream* st) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1649
  assert_lock_strong(SpaceManager::expand_lock());
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1650
  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
  1651
                _free_chunks_total, _free_chunks_count);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1652
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1653
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1654
void ChunkManager::locked_print_sum_free_chunks(outputStream* st) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1655
  assert_lock_strong(SpaceManager::expand_lock());
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1656
  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
  1657
                sum_free_chunks(), sum_free_chunks_count());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1658
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1659
ChunkList* ChunkManager::free_chunks(ChunkIndex index) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1660
  return &_free_chunks[index];
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1661
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1662
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1663
// 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
  1664
// methods that are used in product builds.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1665
size_t ChunkManager::sum_free_chunks() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1666
  assert_lock_strong(SpaceManager::expand_lock());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1667
  size_t result = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1668
  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
  1669
    ChunkList* list = free_chunks(i);
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
    if (list == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1672
      continue;
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
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  1675
    result = result + list->count() * list->size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1676
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1677
  result = result + humongous_dictionary()->total_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1678
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1679
}
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
size_t ChunkManager::sum_free_chunks_count() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1682
  assert_lock_strong(SpaceManager::expand_lock());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1683
  size_t count = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1684
  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
  1685
    ChunkList* list = free_chunks(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1686
    if (list == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1687
      continue;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1688
    }
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  1689
    count = count + list->count();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1690
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1691
  count = count + humongous_dictionary()->total_free_blocks();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1692
  return count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1693
}
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
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
  1696
  ChunkIndex index = list_index(word_size);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1697
  assert(index < HumongousIndex, "No humongous list");
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1698
  return free_chunks(index);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1699
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1700
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1701
void ChunkManager::free_chunks_put(Metachunk* chunk) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1702
  assert_lock_strong(SpaceManager::expand_lock());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1703
  ChunkList* free_list = find_free_chunks_list(chunk->word_size());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1704
  chunk->set_next(free_list->head());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1705
  free_list->set_head(chunk);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1706
  // chunk is being returned to the chunk free list
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1707
  inc_free_chunks_total(chunk->capacity_word_size());
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  1708
  slow_locked_verify();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1709
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1710
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1711
void ChunkManager::chunk_freelist_deallocate(Metachunk* chunk) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1712
  // The deallocation of a chunk originates in the freelist
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1713
  // manangement code for a Metaspace and does not hold the
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1714
  // lock.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1715
  assert(chunk != NULL, "Deallocating NULL");
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  1716
  assert_lock_strong(SpaceManager::expand_lock());
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  1717
  slow_locked_verify();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1718
  if (TraceMetadataChunkAllocation) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1719
    tty->print_cr("ChunkManager::chunk_freelist_deallocate: chunk "
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1720
                  PTR_FORMAT "  size " SIZE_FORMAT,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1721
                  chunk, chunk->word_size());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1722
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1723
  free_chunks_put(chunk);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1724
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1725
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1726
Metachunk* ChunkManager::free_chunks_get(size_t word_size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1727
  assert_lock_strong(SpaceManager::expand_lock());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1728
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  1729
  slow_locked_verify();
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1730
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1731
  Metachunk* chunk = NULL;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1732
  if (list_index(word_size) != HumongousIndex) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1733
    ChunkList* free_list = find_free_chunks_list(word_size);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1734
    assert(free_list != NULL, "Sanity check");
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1735
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1736
    chunk = free_list->head();
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1737
    debug_only(Metachunk* debug_head = chunk;)
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1738
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1739
    if (chunk == NULL) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1740
      return NULL;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1741
    }
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1742
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1743
    // 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
  1744
    free_list->remove_chunk(chunk);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1745
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1746
    // Chunk is being removed from the chunks free list.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1747
    dec_free_chunks_total(chunk->capacity_word_size());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1748
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1749
    if (TraceMetadataChunkAllocation && Verbose) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1750
      tty->print_cr("ChunkManager::free_chunks_get: free_list "
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1751
                    PTR_FORMAT " head " PTR_FORMAT " size " SIZE_FORMAT,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1752
                    free_list, chunk, chunk->word_size());
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
  } else {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1755
    chunk = humongous_dictionary()->get_chunk(
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1756
      word_size,
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1757
      FreeBlockDictionary<Metachunk>::atLeast);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1758
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1759
    if (chunk != NULL) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1760
      if (TraceMetadataHumongousAllocation) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1761
        size_t waste = chunk->word_size() - word_size;
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1762
        tty->print_cr("Free list allocate humongous chunk size " SIZE_FORMAT
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1763
                      " for requested size " SIZE_FORMAT
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1764
                      " waste " SIZE_FORMAT,
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1765
                      chunk->word_size(), word_size, waste);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1766
      }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1767
      // Chunk is being removed from the chunks free list.
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1768
      dec_free_chunks_total(chunk->capacity_word_size());
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1769
    } else {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1770
      return NULL;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1771
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1772
  }
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1773
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1774
  // 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
  1775
  chunk->set_next(NULL);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1776
  chunk->set_prev(NULL);
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1777
#ifdef ASSERT
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1778
  // 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
  1779
  // work.
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1780
  chunk->set_is_free(false);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  1781
#endif
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  1782
  slow_locked_verify();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1783
  return chunk;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1784
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1785
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1786
Metachunk* ChunkManager::chunk_freelist_allocate(size_t word_size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1787
  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
  1788
  slow_locked_verify();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1789
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1790
  // Take from the beginning of the list
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1791
  Metachunk* chunk = free_chunks_get(word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1792
  if (chunk == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1793
    return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1794
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1795
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1796
  assert((word_size <= chunk->word_size()) ||
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1797
         list_index(chunk->word_size() == HumongousIndex),
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1798
         "Non-humongous variable sized chunk");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1799
  if (TraceMetadataChunkAllocation) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1800
    size_t list_count;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1801
    if (list_index(word_size) < HumongousIndex) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1802
      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
  1803
      list_count = list->count();
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1804
    } else {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1805
      list_count = humongous_dictionary()->total_count();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1806
    }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1807
    tty->print("ChunkManager::chunk_freelist_allocate: " PTR_FORMAT " chunk "
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1808
               PTR_FORMAT "  size " SIZE_FORMAT " count " SIZE_FORMAT " ",
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1809
               this, chunk, chunk->word_size(), list_count);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1810
    locked_print_free_chunks(tty);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1811
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1812
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1813
  return chunk;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1814
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1815
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1816
void ChunkManager::print_on(outputStream* out) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1817
  if (PrintFLSStatistics != 0) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1818
    humongous_dictionary()->report_statistics();
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1819
  }
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1820
}
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1821
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1822
// SpaceManager methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1823
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1824
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
  1825
                                           size_t* chunk_word_size,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1826
                                           size_t* class_chunk_word_size) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1827
  switch (type) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1828
  case Metaspace::BootMetaspaceType:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1829
    *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
  1830
    *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
  1831
    break;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1832
  case Metaspace::ROMetaspaceType:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1833
    *chunk_word_size = SharedReadOnlySize / wordSize;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1834
    *class_chunk_word_size = ClassSpecializedChunk;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1835
    break;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1836
  case Metaspace::ReadWriteMetaspaceType:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1837
    *chunk_word_size = SharedReadWriteSize / wordSize;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1838
    *class_chunk_word_size = ClassSpecializedChunk;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1839
    break;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1840
  case Metaspace::AnonymousMetaspaceType:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1841
  case Metaspace::ReflectionMetaspaceType:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1842
    *chunk_word_size = SpecializedChunk;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1843
    *class_chunk_word_size = ClassSpecializedChunk;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1844
    break;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1845
  default:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1846
    *chunk_word_size = SmallChunk;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1847
    *class_chunk_word_size = ClassSmallChunk;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1848
    break;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1849
  }
15488
6594bd32ea05 8007257: NPG: metaspace.cpp: Incorrect arguments in calls to err_msg
mikael
parents: 15087
diff changeset
  1850
  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
  1851
    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
  1852
            " class " SIZE_FORMAT,
15488
6594bd32ea05 8007257: NPG: metaspace.cpp: Incorrect arguments in calls to err_msg
mikael
parents: 15087
diff changeset
  1853
            *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
  1854
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1855
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1856
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
  1857
  MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1858
  size_t free = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1859
  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
  1860
    Metachunk* chunk = chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1861
    while (chunk != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1862
      free += chunk->free_word_size();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1863
      chunk = chunk->next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1864
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1865
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1866
  return free;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1867
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1868
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1869
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
  1870
  MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1871
  size_t result = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1872
  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
  1873
   result += sum_waste_in_chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1874
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1875
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1876
  return result;
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
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
  1880
  size_t result = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1881
  Metachunk* chunk = chunks_in_use(index);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1882
  // 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
  1883
  // 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
  1884
  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
  1885
    if (chunk != current_chunk()) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1886
      result += chunk->free_word_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1887
    }
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
  1888
    chunk = chunk->next();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1889
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1890
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1891
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1892
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1893
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
  1894
  // 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
  1895
  // 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
  1896
  // 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
  1897
  // 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
  1898
  // 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
  1899
  // 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
  1900
  // 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
  1901
  // answer.
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1902
  if (UseConcMarkSweepGC) {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1903
    return allocated_chunks_words();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1904
  } else {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1905
    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
  1906
    size_t sum = 0;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1907
    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
  1908
      Metachunk* chunk = chunks_in_use(i);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1909
      while (chunk != NULL) {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1910
        sum += chunk->capacity_word_size();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1911
        chunk = chunk->next();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1912
      }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1913
    }
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  1914
  return sum;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1915
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1916
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1917
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1918
size_t SpaceManager::sum_count_in_chunks_in_use() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1919
  size_t count = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1920
  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
  1921
    count = count + sum_count_in_chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1922
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  1923
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1924
  return count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1925
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1926
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1927
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
  1928
  size_t count = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1929
  Metachunk* chunk = chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1930
  while (chunk != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1931
    count++;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1932
    chunk = chunk->next();
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
  return count;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1935
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1936
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1937
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1938
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
  1939
  MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1940
  size_t used = 0;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1941
  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
  1942
    Metachunk* chunk = chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1943
    while (chunk != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1944
      used += chunk->used_word_size();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1945
      chunk = chunk->next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1946
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1947
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1948
  return used;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1949
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1950
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1951
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
  1952
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1953
  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
  1954
    Metachunk* chunk = chunks_in_use(i);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1955
    st->print("SpaceManager: %s " PTR_FORMAT,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1956
                 chunk_size_name(i), chunk);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1957
    if (chunk != NULL) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1958
      st->print_cr(" free " SIZE_FORMAT,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1959
                   chunk->free_word_size());
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1960
    } else {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1961
      st->print_cr("");
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1962
    }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1963
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1964
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1965
  vs_list()->chunk_manager()->locked_print_free_chunks(st);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1966
  vs_list()->chunk_manager()->locked_print_sum_free_chunks(st);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1967
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1968
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1969
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
  1970
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1971
  // 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
  1972
  // _small_chunk_limit small chunks can be allocated but
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1973
  // 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
  1974
  // chunks will be allocated.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1975
  size_t chunk_word_size;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1976
  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
  1977
      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
  1978
    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
  1979
    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
  1980
      chunk_word_size = medium_chunk_size();
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
  } else {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1983
    chunk_word_size = medium_chunk_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1984
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1985
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1986
  // Might still need a humongous chunk.  Enforce an
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1987
  // eight word granularity to facilitate reuse (some
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1988
  // wastage but better chance of reuse).
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1989
  size_t if_humongous_sized_chunk =
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1990
    align_size_up(word_size + Metachunk::overhead(),
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1991
                  HumongousChunkGranularity);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1992
  chunk_word_size =
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1993
    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
  1994
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1995
  assert(!SpaceManager::is_humongous(word_size) ||
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1996
         chunk_word_size == if_humongous_sized_chunk,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1997
         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
  1998
                 " chunk_word_size " SIZE_FORMAT,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  1999
                 word_size, chunk_word_size));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2000
  if (TraceMetadataHumongousAllocation &&
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2001
      SpaceManager::is_humongous(word_size)) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2002
    gclog_or_tty->print_cr("Metadata humongous allocation:");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2003
    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
  2004
    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
  2005
                           chunk_word_size);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2006
    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
  2007
                           Metachunk::overhead());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2008
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2009
  return chunk_word_size;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2010
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2011
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2012
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
  2013
  assert(vs_list()->current_virtual_space() != NULL,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2014
         "Should have been set");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2015
  assert(current_chunk() == NULL ||
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2016
         current_chunk()->allocate(word_size) == NULL,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2017
         "Don't need to expand");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2018
  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
  2019
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2020
  if (TraceMetadataChunkAllocation && Verbose) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2021
    size_t words_left = 0;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2022
    size_t words_used = 0;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2023
    if (current_chunk() != NULL) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2024
      words_left = current_chunk()->free_word_size();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2025
      words_used = current_chunk()->used_word_size();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2026
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2027
    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
  2028
                           " words " SIZE_FORMAT " words used " SIZE_FORMAT
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2029
                           " words left",
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2030
                            word_size, words_used, words_left);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2031
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2032
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2033
  // Get another chunk out of the virtual space
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2034
  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
  2035
  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
  2036
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2037
  // 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
  2038
  // and do an allocation from it.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2039
  if (next != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2040
    Metadebug::deallocate_chunk_a_lot(this, grow_chunks_by_words);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2041
    // 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
  2042
    add_chunk(next, false);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2043
    return next->allocate(word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2044
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2045
  return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2046
}
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
void SpaceManager::print_on(outputStream* st) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2049
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2050
  for (ChunkIndex i = ZeroIndex;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2051
       i < NumberOfInUseLists ;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2052
       i = next_chunk_index(i) ) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2053
    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
  2054
                 chunks_in_use(i),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2055
                 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
  2056
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2057
  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
  2058
               " Humongous " SIZE_FORMAT,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2059
               sum_waste_in_chunks_in_use(SmallIndex),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2060
               sum_waste_in_chunks_in_use(MediumIndex),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2061
               sum_waste_in_chunks_in_use(HumongousIndex));
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2062
  // block free lists
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2063
  if (block_freelists() != NULL) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2064
    st->print_cr("total in block free lists " SIZE_FORMAT,
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2065
      block_freelists()->total_size());
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2066
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2067
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2068
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2069
SpaceManager::SpaceManager(Metaspace::MetadataType mdtype,
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2070
                           Mutex* lock,
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2071
                           VirtualSpaceList* vs_list) :
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2072
  _vs_list(vs_list),
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2073
  _mdtype(mdtype),
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2074
  _allocated_blocks_words(0),
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2075
  _allocated_chunks_words(0),
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2076
  _allocated_chunks_count(0),
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2077
  _lock(lock)
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2078
{
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2079
  initialize();
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2080
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2081
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2082
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
  2083
  assert_lock_strong(SpaceManager::expand_lock());
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2084
  // 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
  2085
  // for each SpaceManager
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2086
  _allocated_chunks_words = _allocated_chunks_words + words;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2087
  _allocated_chunks_count++;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2088
  // Global total of capacity in allocated Metachunks
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2089
  MetaspaceAux::inc_capacity(mdtype(), words);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2090
  // Global total of allocated Metablocks.
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2091
  // 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
  2092
  // 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
  2093
  // 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
  2094
  // Metachunk).
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2095
  MetaspaceAux::inc_used(mdtype(), Metachunk::overhead());
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2096
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2097
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2098
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
  2099
  // Add to the per SpaceManager total
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2100
  Atomic::add_ptr(words, &_allocated_blocks_words);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2101
  // Add to the global total
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2102
  MetaspaceAux::inc_used(mdtype(), words);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2103
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2104
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2105
void SpaceManager::dec_total_from_size_metrics() {
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2106
  MetaspaceAux::dec_capacity(mdtype(), allocated_chunks_words());
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2107
  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
  2108
  // Also deduct the overhead per Metachunk
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2109
  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
  2110
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2111
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2112
void SpaceManager::initialize() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2113
  Metadebug::init_allocation_fail_alot_count();
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2114
  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
  2115
    _chunks_in_use[i] = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2116
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2117
  _current_chunk = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2118
  if (TraceMetadataChunkAllocation && Verbose) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2119
    gclog_or_tty->print_cr("SpaceManager(): " PTR_FORMAT, this);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2120
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2121
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2122
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2123
void ChunkManager::return_chunks(ChunkIndex index, Metachunk* chunks) {
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2124
  if (chunks == NULL) {
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2125
    return;
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2126
  }
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2127
  ChunkList* list = free_chunks(index);
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2128
  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
  2129
  assert_lock_strong(SpaceManager::expand_lock());
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2130
  Metachunk* cur = chunks;
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2131
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2132
  // 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
  2133
  // 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
  2134
  // of FreeList then something like FreeList::prepend()
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2135
  // can be used in place of this loop
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2136
  while (cur != NULL) {
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2137
    assert(cur->container() != NULL, "Container should have been set");
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2138
    cur->container()->dec_container_count();
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2139
    // Capture the next link before it is changed
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2140
    // by the call to return_chunk_at_head();
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2141
    Metachunk* next = cur->next();
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2142
    cur->set_is_free(true);
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2143
    list->return_chunk_at_head(cur);
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2144
    cur = next;
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2145
  }
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2146
}
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2147
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2148
SpaceManager::~SpaceManager() {
16385
4a05c6d94b04 8005602: NPG: classunloading does not happen while CMS GC with -XX:+CMSClassUnloadingEnabled is used
mgerdin
parents: 15954
diff changeset
  2149
  // 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
  2150
  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
  2151
    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
  2152
            " allocated_chunks_words() " SIZE_FORMAT,
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2153
            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
  2154
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2155
  MutexLockerEx fcl(SpaceManager::expand_lock(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2156
                    Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2157
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2158
  ChunkManager* chunk_manager = vs_list()->chunk_manager();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2159
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2160
  chunk_manager->slow_locked_verify();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2161
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2162
  dec_total_from_size_metrics();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2163
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2164
  if (TraceMetadataChunkAllocation && Verbose) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2165
    gclog_or_tty->print_cr("~SpaceManager(): " PTR_FORMAT, this);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2166
    locked_print_chunks_in_use_on(gclog_or_tty);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2167
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2168
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2169
  // Do not mangle freed Metachunks.  The chunk size inside Metachunks
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2170
  // 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
  2171
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2172
  // 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
  2173
  // below.
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2174
  chunk_manager->inc_free_chunks_total(allocated_chunks_words(),
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2175
                                       sum_count_in_chunks_in_use());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2176
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2177
  // 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
  2178
  // to the global list of free chunks.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2179
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2180
  // 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
  2181
  // free lists.  Each list is NULL terminated.
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2182
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2183
  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
  2184
    if (TraceMetadataChunkAllocation && Verbose) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2185
      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
  2186
                             sum_count_in_chunks_in_use(i),
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2187
                             chunk_size_name(i));
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2188
    }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2189
    Metachunk* chunks = chunks_in_use(i);
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2190
    chunk_manager->return_chunks(i, chunks);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2191
    set_chunks_in_use(i, NULL);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2192
    if (TraceMetadataChunkAllocation && Verbose) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2193
      gclog_or_tty->print_cr("updated freelist count %d %s",
16996
e699388c6dd8 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 16439
diff changeset
  2194
                             chunk_manager->free_chunks(i)->count(),
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2195
                             chunk_size_name(i));
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2196
    }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2197
    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
  2198
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2199
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2200
  // 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
  2201
  // 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
  2202
  // 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
  2203
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2204
  // Humongous chunks
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2205
  if (TraceMetadataChunkAllocation && Verbose) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2206
    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
  2207
                            sum_count_in_chunks_in_use(HumongousIndex),
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2208
                            chunk_size_name(HumongousIndex));
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2209
    gclog_or_tty->print("Humongous chunk dictionary: ");
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2210
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2211
  // Humongous chunks are never the current chunk.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2212
  Metachunk* humongous_chunks = chunks_in_use(HumongousIndex);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2213
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2214
  while (humongous_chunks != NULL) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2215
#ifdef ASSERT
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2216
    humongous_chunks->set_is_free(true);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2217
#endif
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2218
    if (TraceMetadataChunkAllocation && Verbose) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2219
      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
  2220
                          humongous_chunks,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2221
                          humongous_chunks->word_size());
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2222
    }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2223
    assert(humongous_chunks->word_size() == (size_t)
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2224
           align_size_up(humongous_chunks->word_size(),
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2225
                             HumongousChunkGranularity),
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2226
           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
  2227
                   " granularity %d",
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2228
                   humongous_chunks->word_size(), HumongousChunkGranularity));
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2229
    Metachunk* next_humongous_chunks = humongous_chunks->next();
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  2230
    humongous_chunks->container()->dec_container_count();
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2231
    chunk_manager->humongous_dictionary()->return_chunk(humongous_chunks);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2232
    humongous_chunks = next_humongous_chunks;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2233
  }
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2234
  if (TraceMetadataChunkAllocation && Verbose) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2235
    gclog_or_tty->print_cr("");
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2236
    gclog_or_tty->print_cr("updated dictionary count %d %s",
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2237
                     chunk_manager->humongous_dictionary()->total_count(),
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2238
                     chunk_size_name(HumongousIndex));
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2239
  }
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2240
  chunk_manager->slow_locked_verify();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2241
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2242
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2243
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
  2244
  switch (index) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2245
    case SpecializedIndex:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2246
      return "Specialized";
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2247
    case SmallIndex:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2248
      return "Small";
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2249
    case MediumIndex:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2250
      return "Medium";
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2251
    case HumongousIndex:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2252
      return "Humongous";
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2253
    default:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2254
      return NULL;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2255
  }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2256
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2257
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2258
ChunkIndex ChunkManager::list_index(size_t size) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2259
  switch (size) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2260
    case SpecializedChunk:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2261
      assert(SpecializedChunk == ClassSpecializedChunk,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2262
             "Need branch for ClassSpecializedChunk");
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2263
      return SpecializedIndex;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2264
    case SmallChunk:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2265
    case ClassSmallChunk:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2266
      return SmallIndex;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2267
    case MediumChunk:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2268
    case ClassMediumChunk:
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2269
      return MediumIndex;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2270
    default:
15087
8849ea877278 8005486: NPG: Incorrect assertion in ChunkManager::list_index()
jmasa
parents: 15086
diff changeset
  2271
      assert(size > MediumChunk || size > ClassMediumChunk,
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2272
             "Not a humongous chunk");
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2273
      return HumongousIndex;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2274
  }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2275
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2276
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2277
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
  2278
  assert_lock_strong(_lock);
18987
a1b541fe1159 8019845: Memory leak during class redefinition
fparain
parents: 18492
diff changeset
  2279
  size_t raw_word_size = get_raw_word_size(word_size);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2280
  size_t min_size = TreeChunk<Metablock, FreeList>::min_size();
18987
a1b541fe1159 8019845: Memory leak during class redefinition
fparain
parents: 18492
diff changeset
  2281
  assert(raw_word_size >= min_size,
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2282
         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
  2283
  block_freelists()->return_block(p, raw_word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2284
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2285
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2286
// 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
  2287
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
  2288
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2289
  assert(new_chunk != NULL, "Should not be NULL");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2290
  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
  2291
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2292
  new_chunk->reset_empty();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2293
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2294
  // Find the correct list and and set the current
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2295
  // chunk for that list.
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2296
  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
  2297
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2298
  if (index != HumongousIndex) {
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2299
    retire_current_chunk();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2300
    set_current_chunk(new_chunk);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2301
    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
  2302
    set_chunks_in_use(index, new_chunk);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2303
  } else {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2304
    // 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
  2305
    // 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
  2306
    // chunk.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2307
    if (make_current) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2308
      // 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
  2309
      set_current_chunk(new_chunk);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2310
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2311
    // 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
  2312
    // 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
  2313
    // 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
  2314
    // of the humongous chunks list.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2315
    new_chunk->set_next(chunks_in_use(HumongousIndex));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2316
    set_chunks_in_use(HumongousIndex, new_chunk);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2317
15087
8849ea877278 8005486: NPG: Incorrect assertion in ChunkManager::list_index()
jmasa
parents: 15086
diff changeset
  2318
    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
  2319
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2320
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2321
  // Add to the running sum of capacity
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2322
  inc_size_metrics(new_chunk->word_size());
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2323
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2324
  assert(new_chunk->is_empty(), "Not ready for reuse");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2325
  if (TraceMetadataChunkAllocation && Verbose) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2326
    gclog_or_tty->print("SpaceManager::add_chunk: %d) ",
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2327
                        sum_count_in_chunks_in_use());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2328
    new_chunk->print_on(gclog_or_tty);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2329
    if (vs_list() != NULL) {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2330
      vs_list()->chunk_manager()->locked_print_free_chunks(tty);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2331
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2332
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2333
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2334
19984
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2335
void SpaceManager::retire_current_chunk() {
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2336
  if (current_chunk() != NULL) {
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2337
    size_t remaining_words = current_chunk()->free_word_size();
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2338
    if (remaining_words >= TreeChunk<Metablock, FreeList>::min_size()) {
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2339
      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
  2340
      inc_used_metrics(remaining_words);
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2341
    }
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2342
  }
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2343
}
ba033739c8fe 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 19979
diff changeset
  2344
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2345
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
  2346
                                       size_t grow_chunks_by_words) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2347
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2348
  Metachunk* next = vs_list()->get_new_chunk(word_size,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2349
                                             grow_chunks_by_words,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2350
                                             medium_chunk_bunch());
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
  if (TraceMetadataHumongousAllocation &&
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2353
      SpaceManager::is_humongous(next->word_size())) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2354
    gclog_or_tty->print_cr("  new humongous chunk word size " PTR_FORMAT,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2355
                           next->word_size());
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2356
  }
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2357
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2358
  return next;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2359
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2360
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2361
MetaWord* SpaceManager::allocate(size_t word_size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2362
  MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2363
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  2364
  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
  2365
  BlockFreelist* fl =  block_freelists();
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2366
  MetaWord* p = NULL;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2367
  // 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
  2368
  // 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
  2369
  // 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
  2370
  // 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
  2371
  // for allocations.  Do some profiling.  JJJ
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2372
  if (fl->total_size() > allocation_from_dictionary_limit) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2373
    p = fl->get_block(raw_word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2374
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2375
  if (p == NULL) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2376
    p = allocate_work(raw_word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2377
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2378
  Metadebug::deallocate_block_a_lot(this, raw_word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2379
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2380
  return p;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2381
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2382
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2383
// Returns the address of spaced allocated for "word_size".
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2384
// This methods does not know about blocks (Metablocks)
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2385
MetaWord* SpaceManager::allocate_work(size_t word_size) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2386
  assert_lock_strong(_lock);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2387
#ifdef ASSERT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2388
  if (Metadebug::test_metadata_failure()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2389
    return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2390
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2391
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2392
  // Is there space in the current chunk?
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2393
  MetaWord* result = NULL;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2394
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2395
  // 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
  2396
  // 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
  2397
  // of memory if this returns null.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2398
  if (DumpSharedSpaces) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2399
    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
  2400
    inc_used_metrics(word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2401
    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
  2402
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2403
  if (current_chunk() != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2404
    result = current_chunk()->allocate(word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2405
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2406
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2407
  if (result == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2408
    result = grow_and_allocate(word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2409
  }
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2410
  if (result != 0) {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2411
    inc_used_metrics(word_size);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2412
    assert(result != (MetaWord*) chunks_in_use(MediumIndex),
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2413
           "Head of the list is being allocated");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2414
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2415
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2416
  return result;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2417
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2418
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2419
void SpaceManager::verify() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2420
  // If there are blocks in the dictionary, then
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2421
  // verfication of chunks does not work since
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2422
  // being in the dictionary alters a chunk.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2423
  if (block_freelists()->total_size() == 0) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2424
    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
  2425
      Metachunk* curr = chunks_in_use(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2426
      while (curr != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2427
        curr->verify();
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  2428
        verify_chunk_size(curr);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2429
        curr = curr->next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2430
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2431
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2432
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2433
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2434
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  2435
void SpaceManager::verify_chunk_size(Metachunk* chunk) {
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  2436
  assert(is_humongous(chunk->word_size()) ||
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2437
         chunk->word_size() == medium_chunk_size() ||
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2438
         chunk->word_size() == small_chunk_size() ||
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2439
         chunk->word_size() == specialized_chunk_size(),
14635
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  2440
         "Chunk size is wrong");
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  2441
  return;
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  2442
}
6a3c85b8111c 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 14590
diff changeset
  2443
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2444
#ifdef ASSERT
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2445
void SpaceManager::verify_allocated_blocks_words() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2446
  // 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
  2447
  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
  2448
    "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
  2449
  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
  2450
    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
  2451
            " vs " SIZE_FORMAT,
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2452
            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
  2453
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2454
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2455
#endif
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2456
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2457
void SpaceManager::dump(outputStream* const out) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2458
  size_t curr_total = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2459
  size_t waste = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2460
  uint i = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2461
  size_t used = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2462
  size_t capacity = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2463
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2464
  // 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
  2465
  for (ChunkIndex index = ZeroIndex;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2466
       index < NumberOfInUseLists;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2467
       index = next_chunk_index(index)) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2468
    for (Metachunk* curr = chunks_in_use(index);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2469
         curr != NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2470
         curr = curr->next()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2471
      out->print("%d) ", i++);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2472
      curr->print_on(out);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2473
      if (TraceMetadataChunkAllocation && Verbose) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2474
        block_freelists()->print_on(out);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2475
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2476
      curr_total += curr->word_size();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2477
      used += curr->used_word_size();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2478
      capacity += curr->capacity_word_size();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2479
      waste += curr->free_word_size() + curr->overhead();;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2480
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2481
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2482
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2483
  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
  2484
  // Free space isn't wasted.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2485
  waste -= free;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2486
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2487
  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
  2488
                " free " SIZE_FORMAT " capacity " SIZE_FORMAT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2489
                " waste " SIZE_FORMAT, curr_total, used, free, capacity, waste);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2490
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2491
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14474
diff changeset
  2492
#ifndef PRODUCT
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2493
void SpaceManager::mangle_freed_chunks() {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2494
  for (ChunkIndex index = ZeroIndex;
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  2495
       index < NumberOfInUseLists;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2496
       index = next_chunk_index(index)) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2497
    for (Metachunk* curr = chunks_in_use(index);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2498
         curr != NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2499
         curr = curr->next()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2500
      curr->mangle();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2501
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2502
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2503
}
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14474
diff changeset
  2504
#endif // PRODUCT
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2505
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2506
// MetaspaceAux
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2507
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2508
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2509
size_t MetaspaceAux::_allocated_capacity_words[] = {0, 0};
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2510
size_t MetaspaceAux::_allocated_used_words[] = {0, 0};
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2511
19322
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  2512
size_t MetaspaceAux::free_bytes(Metaspace::MetadataType mdtype) {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  2513
  VirtualSpaceList* list = Metaspace::get_space_list(mdtype);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  2514
  return list == NULL ? 0 : list->free_bytes();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  2515
}
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  2516
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2517
size_t MetaspaceAux::free_bytes() {
19322
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  2518
  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
  2519
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2520
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2521
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
  2522
  assert_lock_strong(SpaceManager::expand_lock());
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2523
  assert(words <= allocated_capacity_words(mdtype),
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2524
    err_msg("About to decrement below 0: words " SIZE_FORMAT
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2525
            " is greater than _allocated_capacity_words[%u] " SIZE_FORMAT,
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2526
            words, mdtype, allocated_capacity_words(mdtype)));
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2527
  _allocated_capacity_words[mdtype] -= words;
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2528
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2529
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2530
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
  2531
  assert_lock_strong(SpaceManager::expand_lock());
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2532
  // Needs to be atomic
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2533
  _allocated_capacity_words[mdtype] += words;
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2534
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2535
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2536
void MetaspaceAux::dec_used(Metaspace::MetadataType mdtype, size_t words) {
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2537
  assert(words <= allocated_used_words(mdtype),
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2538
    err_msg("About to decrement below 0: words " SIZE_FORMAT
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2539
            " is greater than _allocated_used_words[%u] " SIZE_FORMAT,
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2540
            words, mdtype, allocated_used_words(mdtype)));
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2541
  // 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
  2542
  // 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
  2543
  // 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
  2544
  // and protected by the Metaspace lock.
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2545
  jlong minus_words = (jlong) - (jlong) words;
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2546
  Atomic::add_ptr(minus_words, &_allocated_used_words[mdtype]);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2547
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2548
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2549
void MetaspaceAux::inc_used(Metaspace::MetadataType mdtype, size_t words) {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2550
  // _allocated_used_words tracks allocations for
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2551
  // each piece of metadata.  Those allocations are
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2552
  // generally done concurrently by different application
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2553
  // threads so must be done atomically.
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2554
  Atomic::add_ptr(words, &_allocated_used_words[mdtype]);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2555
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2556
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2557
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
  2558
  size_t used = 0;
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2559
  ClassLoaderDataGraphMetaspaceIterator iter;
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2560
  while (iter.repeat()) {
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2561
    Metaspace* msp = iter.get_next();
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2562
    // Sum allocated_blocks_words for each metaspace
13733
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2563
    if (msp != NULL) {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2564
      used += msp->used_words_slow(mdtype);
13733
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2565
    }
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2566
  }
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2567
  return used * BytesPerWord;
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2568
}
e41e23ae6758 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 13729
diff changeset
  2569
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2570
size_t MetaspaceAux::free_in_bytes(Metaspace::MetadataType mdtype) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2571
  size_t free = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2572
  ClassLoaderDataGraphMetaspaceIterator iter;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2573
  while (iter.repeat()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2574
    Metaspace* msp = iter.get_next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2575
    if (msp != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2576
      free += msp->free_words(mdtype);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2577
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2578
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2579
  return free * BytesPerWord;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2580
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2581
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2582
size_t MetaspaceAux::capacity_bytes_slow(Metaspace::MetadataType mdtype) {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2583
  if ((mdtype == Metaspace::ClassType) && !Metaspace::using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2584
    return 0;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2585
  }
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2586
  // 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
  2587
  // added to the capacity calculation as needed.
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2588
  size_t capacity = 0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2589
  ClassLoaderDataGraphMetaspaceIterator iter;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2590
  while (iter.repeat()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2591
    Metaspace* msp = iter.get_next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2592
    if (msp != NULL) {
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2593
      capacity += msp->capacity_words_slow(mdtype);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2594
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2595
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2596
  return capacity * BytesPerWord;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2597
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2598
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2599
size_t MetaspaceAux::reserved_in_bytes(Metaspace::MetadataType mdtype) {
19322
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  2600
  VirtualSpaceList* list = Metaspace::get_space_list(mdtype);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  2601
  return list == NULL ? 0 : list->virtual_space_total();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2602
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2603
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2604
size_t MetaspaceAux::min_chunk_size() { return Metaspace::first_chunk_word_size(); }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2605
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2606
size_t MetaspaceAux::free_chunks_total(Metaspace::MetadataType mdtype) {
19322
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  2607
  VirtualSpaceList* list = Metaspace::get_space_list(mdtype);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  2608
  if (list == NULL) {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2609
    return 0;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2610
  }
19322
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 19319
diff changeset
  2611
  ChunkManager* chunk = list->chunk_manager();
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2612
  chunk->slow_verify();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2613
  return chunk->free_chunks_total();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2614
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2615
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2616
size_t MetaspaceAux::free_chunks_total_in_bytes(Metaspace::MetadataType mdtype) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2617
  return free_chunks_total(mdtype) * BytesPerWord;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2618
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2619
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2620
size_t MetaspaceAux::free_chunks_total() {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2621
  return free_chunks_total(Metaspace::ClassType) +
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2622
         free_chunks_total(Metaspace::NonClassType);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2623
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2624
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2625
size_t MetaspaceAux::free_chunks_total_in_bytes() {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2626
  return free_chunks_total() * BytesPerWord;
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
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2629
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
  2630
  gclog_or_tty->print(", [Metaspace:");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2631
  if (PrintGCDetails && Verbose) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2632
    gclog_or_tty->print(" "  SIZE_FORMAT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2633
                        "->" SIZE_FORMAT
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2634
                        "("  SIZE_FORMAT ")",
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2635
                        prev_metadata_used,
18442
b9d7f080cda4 8014546: MetaspaceAux print_metaspace_change() should print "used" after GC not capacity
jmasa
parents: 17858
diff changeset
  2636
                        allocated_used_bytes(),
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2637
                        reserved_in_bytes());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2638
  } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2639
    gclog_or_tty->print(" "  SIZE_FORMAT "K"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2640
                        "->" SIZE_FORMAT "K"
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2641
                        "("  SIZE_FORMAT "K)",
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2642
                        prev_metadata_used / K,
18442
b9d7f080cda4 8014546: MetaspaceAux print_metaspace_change() should print "used" after GC not capacity
jmasa
parents: 17858
diff changeset
  2643
                        allocated_used_bytes() / K,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2644
                        reserved_in_bytes()/ K);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2645
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2646
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2647
  gclog_or_tty->print("]");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2648
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2649
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2650
// This is printed when PrintGCDetails
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2651
void MetaspaceAux::print_on(outputStream* out) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2652
  Metaspace::MetadataType nct = Metaspace::NonClassType;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2653
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2654
  out->print_cr(" Metaspace total "
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2655
                SIZE_FORMAT "K, used " SIZE_FORMAT "K,"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2656
                " reserved " SIZE_FORMAT "K",
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2657
                allocated_capacity_bytes()/K, allocated_used_bytes()/K, reserved_in_bytes()/K);
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2658
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2659
  out->print_cr("  data space     "
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2660
                SIZE_FORMAT "K, used " SIZE_FORMAT "K,"
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2661
                " reserved " SIZE_FORMAT "K",
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2662
                allocated_capacity_bytes(nct)/K,
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2663
                allocated_used_bytes(nct)/K,
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2664
                reserved_in_bytes(nct)/K);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2665
  if (Metaspace::using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2666
    Metaspace::MetadataType ct = Metaspace::ClassType;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2667
    out->print_cr("  class space    "
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2668
                  SIZE_FORMAT "K, used " SIZE_FORMAT "K,"
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2669
                  " reserved " SIZE_FORMAT "K",
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2670
                  allocated_capacity_bytes(ct)/K,
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2671
                  allocated_used_bytes(ct)/K,
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2672
                  reserved_in_bytes(ct)/K);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2673
  }
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
// Print information for class space and data space separately.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2677
// This is almost the same as above.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2678
void MetaspaceAux::print_on(outputStream* out, Metaspace::MetadataType mdtype) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2679
  size_t free_chunks_capacity_bytes = free_chunks_total_in_bytes(mdtype);
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2680
  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
  2681
  size_t used_bytes = used_bytes_slow(mdtype);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2682
  size_t free_bytes = free_in_bytes(mdtype);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2683
  size_t used_and_free = used_bytes + free_bytes +
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2684
                           free_chunks_capacity_bytes;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2685
  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
  2686
             "K + unused in chunks " SIZE_FORMAT "K  + "
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2687
             " capacity in free chunks " SIZE_FORMAT "K = " SIZE_FORMAT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2688
             "K  capacity in allocated chunks " SIZE_FORMAT "K",
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2689
             used_bytes / K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2690
             free_bytes / K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2691
             free_chunks_capacity_bytes / K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2692
             used_and_free / K,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2693
             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
  2694
  // 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
  2695
  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
  2696
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2697
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2698
// Print total fragmentation for class metaspaces
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2699
void MetaspaceAux::print_class_waste(outputStream* out) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2700
  assert(Metaspace::using_class_space(), "class metaspace not used");
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2701
  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
  2702
  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
  2703
  ClassLoaderDataGraphMetaspaceIterator iter;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2704
  while (iter.repeat()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2705
    Metaspace* msp = iter.get_next();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2706
    if (msp != NULL) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2707
      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
  2708
      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
  2709
      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
  2710
      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
  2711
      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
  2712
      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
  2713
      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
  2714
    }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2715
  }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2716
  out->print_cr(" class: " SIZE_FORMAT " specialized(s) " SIZE_FORMAT ", "
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2717
                SIZE_FORMAT " small(s) " SIZE_FORMAT ", "
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2718
                SIZE_FORMAT " medium(s) " SIZE_FORMAT ", "
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2719
                "large count " SIZE_FORMAT,
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2720
                cls_specialized_count, cls_specialized_waste,
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2721
                cls_small_count, cls_small_waste,
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2722
                cls_medium_count, cls_medium_waste, cls_humongous_count);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2723
}
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2724
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2725
// 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
  2726
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
  2727
  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
  2728
  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
  2729
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2730
  ClassLoaderDataGraphMetaspaceIterator iter;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2731
  while (iter.repeat()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2732
    Metaspace* msp = iter.get_next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2733
    if (msp != NULL) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2734
      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
  2735
      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
  2736
      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
  2737
      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
  2738
      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
  2739
      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
  2740
      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
  2741
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2742
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2743
  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
  2744
  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
  2745
                        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
  2746
                        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
  2747
                        "large count " SIZE_FORMAT,
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2748
             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
  2749
             small_waste, medium_count, medium_waste, humongous_count);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2750
  if (Metaspace::using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2751
    print_class_waste(out);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2752
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2753
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2754
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2755
// Dump global metaspace things from the end of ClassLoaderDataGraph
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2756
void MetaspaceAux::dump(outputStream* out) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2757
  out->print_cr("All Metaspace:");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2758
  out->print("data space: "); print_on(out, Metaspace::NonClassType);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2759
  out->print("class space: "); print_on(out, Metaspace::ClassType);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2760
  print_waste(out);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2761
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2762
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2763
void MetaspaceAux::verify_free_chunks() {
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2764
  Metaspace::space_list()->chunk_manager()->verify();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2765
  if (Metaspace::using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2766
    Metaspace::class_space_list()->chunk_manager()->verify();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2767
  }
14474
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2768
}
4154f1817a75 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 14123
diff changeset
  2769
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2770
void MetaspaceAux::verify_capacity() {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2771
#ifdef ASSERT
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2772
  size_t running_sum_capacity_bytes = allocated_capacity_bytes();
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2773
  // 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
  2774
  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
  2775
  assert(running_sum_capacity_bytes == capacity_in_use_bytes,
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2776
    err_msg("allocated_capacity_words() * BytesPerWord " SIZE_FORMAT
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2777
            " capacity_bytes_slow()" SIZE_FORMAT,
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2778
            running_sum_capacity_bytes, capacity_in_use_bytes));
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2779
  for (Metaspace::MetadataType i = Metaspace::ClassType;
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2780
       i < Metaspace:: MetadataTypeCount;
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2781
       i = (Metaspace::MetadataType)(i + 1)) {
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2782
    size_t capacity_in_use_bytes = capacity_bytes_slow(i);
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2783
    assert(allocated_capacity_bytes(i) == capacity_in_use_bytes,
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2784
      err_msg("allocated_capacity_bytes(%u) " SIZE_FORMAT
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2785
              " capacity_bytes_slow(%u)" SIZE_FORMAT,
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2786
              i, allocated_capacity_bytes(i), i, capacity_in_use_bytes));
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2787
  }
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2788
#endif
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2789
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2790
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2791
void MetaspaceAux::verify_used() {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2792
#ifdef ASSERT
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2793
  size_t running_sum_used_bytes = allocated_used_bytes();
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2794
  // 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
  2795
  size_t used_in_use_bytes = used_bytes_slow();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2796
  assert(allocated_used_bytes() == used_in_use_bytes,
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2797
    err_msg("allocated_used_bytes() " SIZE_FORMAT
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2798
            " used_bytes_slow()" SIZE_FORMAT,
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2799
            allocated_used_bytes(), used_in_use_bytes));
17628
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2800
  for (Metaspace::MetadataType i = Metaspace::ClassType;
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2801
       i < Metaspace:: MetadataTypeCount;
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2802
       i = (Metaspace::MetadataType)(i + 1)) {
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2803
    size_t used_in_use_bytes = used_bytes_slow(i);
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2804
    assert(allocated_used_bytes(i) == used_in_use_bytes,
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2805
      err_msg("allocated_used_bytes(%u) " SIZE_FORMAT
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2806
              " used_bytes_slow(%u)" SIZE_FORMAT,
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2807
              i, allocated_used_bytes(i), i, used_in_use_bytes));
481e0280aed3 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 17117
diff changeset
  2808
  }
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2809
#endif
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2810
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2811
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2812
void MetaspaceAux::verify_metrics() {
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2813
  verify_capacity();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2814
  verify_used();
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2815
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2816
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  2817
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2818
// Metaspace methods
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2819
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2820
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
  2821
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
  2822
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2823
Metaspace::Metaspace(Mutex* lock, MetaspaceType type) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  2824
  initialize(lock, type);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2825
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2826
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2827
Metaspace::~Metaspace() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2828
  delete _vsm;
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2829
  if (using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2830
    delete _class_vsm;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2831
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2832
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2833
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2834
VirtualSpaceList* Metaspace::_space_list = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2835
VirtualSpaceList* Metaspace::_class_space_list = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2836
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2837
#define VIRTUALSPACEMULTIPLIER 2
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2838
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2839
#ifdef _LP64
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2840
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
  2841
  // 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
  2842
  // 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
  2843
  // (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
  2844
  // between the lower base and higher address.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2845
  address lower_base;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2846
  address higher_address;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2847
  if (UseSharedSpaces) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2848
    higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()),
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2849
                          (address)(metaspace_base + class_metaspace_size()));
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2850
    lower_base = MIN2(metaspace_base, cds_base);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2851
  } else {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2852
    higher_address = metaspace_base + class_metaspace_size();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2853
    lower_base = metaspace_base;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2854
  }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2855
  Universe::set_narrow_klass_base(lower_base);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2856
  if ((uint64_t)(higher_address - lower_base) < (uint64_t)max_juint) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2857
    Universe::set_narrow_klass_shift(0);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2858
  } else {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2859
    assert(!UseSharedSpaces, "Cannot shift with UseSharedSpaces");
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2860
    Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2861
  }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2862
}
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2863
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2864
// 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
  2865
// to work with compressed klass pointers.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2866
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
  2867
  assert(cds_base != 0 && UseSharedSpaces, "Only use with CDS");
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  2868
  assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs");
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2869
  address lower_base = MIN2((address)metaspace_base, cds_base);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2870
  address higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()),
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2871
                                (address)(metaspace_base + class_metaspace_size()));
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2872
  return ((uint64_t)(higher_address - lower_base) < (uint64_t)max_juint);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2873
}
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2874
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2875
// Try to allocate the metaspace at the requested addr.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2876
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
  2877
  assert(using_class_space(), "called improperly");
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  2878
  assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs");
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2879
  assert(class_metaspace_size() < KlassEncodingMetaspaceMax,
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2880
         "Metaspace size is too big");
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2881
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2882
  ReservedSpace metaspace_rs = ReservedSpace(class_metaspace_size(),
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2883
                                             os::vm_allocation_granularity(),
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2884
                                             false, requested_addr, 0);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2885
  if (!metaspace_rs.is_reserved()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2886
    if (UseSharedSpaces) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2887
      // Keep trying to allocate the metaspace, increasing the requested_addr
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2888
      // 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
  2889
      // use of CDS with compressed klass pointers.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2890
      char *addr = requested_addr;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2891
      while (!metaspace_rs.is_reserved() && (addr + 1*G > addr) &&
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2892
             can_use_cds_with_metaspace_addr(addr + 1*G, cds_base)) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2893
        addr = addr + 1*G;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2894
        metaspace_rs = ReservedSpace(class_metaspace_size(),
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2895
                                     os::vm_allocation_granularity(), false, addr, 0);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2896
      }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2897
    }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2898
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2899
    // 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
  2900
    // 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
  2901
    // metaspace as if UseCompressedClassPointers is off because too much
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  2902
    // initialization has happened that depends on UseCompressedClassPointers.
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  2903
    // So, UseCompressedClassPointers cannot be turned off at this point.
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2904
    if (!metaspace_rs.is_reserved()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2905
      metaspace_rs = ReservedSpace(class_metaspace_size(),
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2906
                                   os::vm_allocation_granularity(), false);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2907
      if (!metaspace_rs.is_reserved()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2908
        vm_exit_during_initialization(err_msg("Could not allocate metaspace: %d bytes",
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2909
                                              class_metaspace_size()));
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2910
      }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2911
    }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2912
  }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2913
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2914
  // If we got here then the metaspace got allocated.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2915
  MemTracker::record_virtual_memory_type((address)metaspace_rs.base(), mtClass);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2916
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2917
  // Verify that we can use shared spaces.  Otherwise, turn off CDS.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2918
  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
  2919
    FileMapInfo::stop_sharing_and_unmap(
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2920
        "Could not allocate metaspace at a compatible address");
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2921
  }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2922
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2923
  set_narrow_klass_base_and_shift((address)metaspace_rs.base(),
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2924
                                  UseSharedSpaces ? (address)cds_base : 0);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2925
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2926
  initialize_class_space(metaspace_rs);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2927
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2928
  if (PrintCompressedOopsMode || (PrintMiscellaneous && Verbose)) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2929
    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
  2930
                            Universe::narrow_klass_base(), Universe::narrow_klass_shift());
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2931
    gclog_or_tty->print_cr("Metaspace Size: " SIZE_FORMAT " Address: " PTR_FORMAT " Req Addr: " PTR_FORMAT,
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2932
                           class_metaspace_size(), metaspace_rs.base(), requested_addr);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2933
  }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2934
}
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2935
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  2936
// 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
  2937
// 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
  2938
void Metaspace::initialize_class_space(ReservedSpace rs) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2939
  // 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
  2940
  assert(rs.size() >= CompressedClassSpaceSize,
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  2941
         err_msg(SIZE_FORMAT " != " UINTX_FORMAT, rs.size(), CompressedClassSpaceSize));
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2942
  assert(using_class_space(), "Must be using class space");
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2943
  _class_space_list = new VirtualSpaceList(rs);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2944
}
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2945
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2946
#endif
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2947
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2948
void Metaspace::global_initialize() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2949
  // Initialize the alignment for shared spaces.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2950
  int max_alignment = os::vm_page_size();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2951
  size_t cds_total = 0;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2952
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  2953
  set_class_metaspace_size(align_size_up(CompressedClassSpaceSize,
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2954
                                         os::vm_allocation_granularity()));
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2955
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2956
  MetaspaceShared::set_max_alignment(max_alignment);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2957
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2958
  if (DumpSharedSpaces) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2959
    SharedReadOnlySize = align_size_up(SharedReadOnlySize, max_alignment);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2960
    SharedReadWriteSize = align_size_up(SharedReadWriteSize, max_alignment);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2961
    SharedMiscDataSize  = align_size_up(SharedMiscDataSize, max_alignment);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2962
    SharedMiscCodeSize  = align_size_up(SharedMiscCodeSize, max_alignment);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2963
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2964
    // 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
  2965
    // 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
  2966
    // remainder is the misc code and data chunks.
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2967
    cds_total = FileMapInfo::shared_spaces_size();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2968
    _space_list = new VirtualSpaceList(cds_total/wordSize);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2969
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2970
#ifdef _LP64
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2971
    // 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
  2972
    // properly when creating the shared archive.
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  2973
    assert(UseCompressedOops && UseCompressedClassPointers,
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  2974
      "UseCompressedOops and UseCompressedClassPointers must be set");
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2975
    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
  2976
    if (TraceMetavirtualspaceAllocation && Verbose) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2977
      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
  2978
                             _space_list->current_virtual_space()->bottom());
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2979
    }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2980
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2981
    // Set the shift to zero.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2982
    assert(class_metaspace_size() < (uint64_t)(max_juint) - cds_total,
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2983
           "CDS region is too large");
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2984
    Universe::set_narrow_klass_shift(0);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2985
#endif
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2986
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2987
  } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2988
    // 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
  2989
    // 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
  2990
    // the addresses don't conflict)
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  2991
    address cds_address = NULL;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2992
    if (UseSharedSpaces) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2993
      FileMapInfo* mapinfo = new FileMapInfo();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2994
      memset(mapinfo, 0, sizeof(FileMapInfo));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2995
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2996
      // 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
  2997
      // initialization fails, shared spaces [UseSharedSpaces] are
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2998
      // disabled and the file is closed.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  2999
      // Map in spaces now also
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3000
      if (mapinfo->initialize() && MetaspaceShared::map_shared_spaces(mapinfo)) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3001
        FileMapInfo::set_current_info(mapinfo);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3002
      } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3003
        assert(!mapinfo->is_open() && !UseSharedSpaces,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3004
               "archive file not closed or shared spaces not disabled.");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3005
      }
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3006
      cds_total = FileMapInfo::shared_spaces_size();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3007
      cds_address = (address)mapinfo->region_base(0);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3008
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3009
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3010
#ifdef _LP64
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  3011
    // If UseCompressedClassPointers is set then allocate the metaspace area
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3012
    // above the heap and above the CDS area (if it exists).
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3013
    if (using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3014
      if (UseSharedSpaces) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3015
        allocate_metaspace_compressed_klass_ptrs((char *)(cds_address + cds_total), cds_address);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3016
      } else {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3017
        allocate_metaspace_compressed_klass_ptrs((char *)CompressedKlassPointersBase, 0);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3018
      }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3019
    }
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3020
#endif
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3021
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3022
    // Initialize these before initializing the VirtualSpaceList
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3023
    _first_chunk_word_size = InitialBootClassLoaderMetaspaceSize / BytesPerWord;
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3024
    _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
  3025
    // 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
  3026
    // 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
  3027
    // from there.  This size calculated by -version.
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3028
    _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
  3029
                                       (CompressedClassSpaceSize/BytesPerWord)*2);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3030
    _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
  3031
    // Arbitrarily set the initial virtual space to a multiple
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3032
    // of the boot class loader size.
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3033
    size_t word_size = VIRTUALSPACEMULTIPLIER * first_chunk_word_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3034
    // Initialize the list of virtual spaces.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3035
    _space_list = new VirtualSpaceList(word_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3036
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3037
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3038
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3039
void Metaspace::initialize(Mutex* lock, MetaspaceType type) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3040
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3041
  assert(space_list() != NULL,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3042
    "Metadata VirtualSpaceList has not been initialized");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3043
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3044
  _vsm = new SpaceManager(NonClassType, lock, space_list());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3045
  if (_vsm == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3046
    return;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3047
  }
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3048
  size_t word_size;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3049
  size_t class_word_size;
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3050
  vsm()->get_initial_chunk_sizes(type, &word_size, &class_word_size);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3051
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3052
  if (using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3053
    assert(class_space_list() != NULL,
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3054
      "Class VirtualSpaceList has not been initialized");
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3055
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3056
    // Allocate SpaceManager for classes.
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3057
    _class_vsm = new SpaceManager(ClassType, lock, class_space_list());
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3058
    if (_class_vsm == NULL) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3059
      return;
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3060
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3061
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3062
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3063
  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
  3064
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3065
  // Allocate chunk for metadata objects
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3066
  Metachunk* new_chunk =
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3067
     space_list()->get_initialization_chunk(word_size,
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3068
                                            vsm()->medium_chunk_bunch());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3069
  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
  3070
  if (new_chunk != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3071
    // 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
  3072
    vsm()->add_chunk(new_chunk, true);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3073
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3074
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3075
  // Allocate chunk for class metadata objects
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3076
  if (using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3077
    Metachunk* class_chunk =
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3078
       class_space_list()->get_initialization_chunk(class_word_size,
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3079
                                                    class_vsm()->medium_chunk_bunch());
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3080
    if (class_chunk != NULL) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3081
      class_vsm()->add_chunk(class_chunk, true);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3082
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3083
  }
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3084
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3085
  _alloc_record_head = NULL;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3086
  _alloc_record_tail = NULL;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3087
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3088
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3089
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
  3090
  size_t byte_size = word_size * wordSize;
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3091
  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
  3092
}
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3093
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3094
MetaWord* Metaspace::allocate(size_t word_size, MetadataType mdtype) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3095
  // DumpSharedSpaces doesn't use class metadata area (yet)
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  3096
  // Also, don't use class_vsm() unless UseCompressedClassPointers is true.
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3097
  if (mdtype == ClassType && using_class_space()) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3098
    return  class_vsm()->allocate(word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3099
  } else {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3100
    return  vsm()->allocate(word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3101
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3102
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3103
13755
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  3104
MetaWord* Metaspace::expand_and_allocate(size_t word_size, MetadataType mdtype) {
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  3105
  MetaWord* result;
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  3106
  MetaspaceGC::set_expand_after_GC(true);
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  3107
  size_t before_inc = MetaspaceGC::capacity_until_GC();
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3108
  size_t delta_bytes = MetaspaceGC::delta_capacity_until_GC(word_size) * BytesPerWord;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3109
  MetaspaceGC::inc_capacity_until_GC(delta_bytes);
13755
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  3110
  if (PrintGCDetails && Verbose) {
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  3111
    gclog_or_tty->print_cr("Increase capacity to GC from " SIZE_FORMAT
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  3112
      " to " SIZE_FORMAT, before_inc, MetaspaceGC::capacity_until_GC());
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  3113
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3114
13755
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  3115
  result = allocate(word_size, mdtype);
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  3116
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  3117
  return result;
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  3118
}
a00f5de57d30 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 13739
diff changeset
  3119
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3120
// Space allocated in the Metaspace.  This may
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3121
// be across several metadata virtual spaces.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3122
char* Metaspace::bottom() const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3123
  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
  3124
  return (char*)vsm()->current_chunk()->bottom();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3125
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3126
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3127
size_t Metaspace::used_words_slow(MetadataType mdtype) const {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3128
  if (mdtype == ClassType) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3129
    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
  3130
  } else {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3131
    return vsm()->sum_used_in_chunks_in_use();  // includes overhead!
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3132
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3133
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3134
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3135
size_t Metaspace::free_words(MetadataType mdtype) const {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3136
  if (mdtype == ClassType) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3137
    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
  3138
  } else {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3139
    return vsm()->sum_free_in_chunks_in_use();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3140
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3141
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3142
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3143
// Space capacity in the Metaspace.  It includes
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3144
// space in the list of chunks from which allocations
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3145
// 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
  3146
// in the space available in the dictionary which
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3147
// is already counted in some chunk.
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3148
size_t Metaspace::capacity_words_slow(MetadataType mdtype) const {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3149
  if (mdtype == ClassType) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3150
    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
  3151
  } else {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3152
    return vsm()->sum_capacity_in_chunks_in_use();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3153
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3154
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3155
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3156
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
  3157
  return used_words_slow(mdtype) * BytesPerWord;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3158
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3159
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3160
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
  3161
  return capacity_words_slow(mdtype) * BytesPerWord;
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3162
}
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 17101
diff changeset
  3163
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3164
void Metaspace::deallocate(MetaWord* ptr, size_t word_size, bool is_class) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3165
  if (SafepointSynchronize::is_at_safepoint()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3166
    assert(Thread::current()->is_VM_thread(), "should be the VM thread");
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3167
    // Don't take Heap_lock
17117
46f2f90d6b14 8013129: Possible deadlock with Metaspace locks due to mixed usage of safepoint aware and non-safepoint aware locking
mgerdin
parents: 17109
diff changeset
  3168
    MutexLockerEx ml(vsm()->lock(), Mutex::_no_safepoint_check_flag);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3169
    if (word_size < TreeChunk<Metablock, FreeList>::min_size()) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3170
      // Dark matter.  Too small for dictionary.
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3171
#ifdef ASSERT
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3172
      Copy::fill_to_words((HeapWord*)ptr, word_size, 0xf5f5f5f5);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3173
#endif
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3174
      return;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3175
    }
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3176
    if (is_class && using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3177
      class_vsm()->deallocate(ptr, word_size);
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3178
    } else {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3179
      vsm()->deallocate(ptr, word_size);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3180
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3181
  } else {
17117
46f2f90d6b14 8013129: Possible deadlock with Metaspace locks due to mixed usage of safepoint aware and non-safepoint aware locking
mgerdin
parents: 17109
diff changeset
  3182
    MutexLockerEx ml(vsm()->lock(), Mutex::_no_safepoint_check_flag);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3183
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3184
    if (word_size < TreeChunk<Metablock, FreeList>::min_size()) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3185
      // Dark matter.  Too small for dictionary.
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3186
#ifdef ASSERT
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3187
      Copy::fill_to_words((HeapWord*)ptr, word_size, 0xf5f5f5f5);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3188
#endif
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3189
      return;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3190
    }
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3191
    if (is_class && using_class_space()) {
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3192
      class_vsm()->deallocate(ptr, word_size);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3193
    } else {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3194
      vsm()->deallocate(ptr, word_size);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3195
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3196
  }
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
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3199
Metablock* Metaspace::allocate(ClassLoaderData* loader_data, size_t word_size,
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3200
                              bool read_only, MetaspaceObj::Type type, TRAPS) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3201
  if (HAS_PENDING_EXCEPTION) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3202
    assert(false, "Should not allocate with exception pending");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3203
    return NULL;  // caller does a CHECK_NULL too
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3204
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3205
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3206
  MetadataType mdtype = (type == MetaspaceObj::ClassType) ? ClassType : NonClassType;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3207
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3208
  // SSS: Should we align the allocations and make sure the sizes are aligned.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3209
  MetaWord* result = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3210
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3211
  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
  3212
        "ClassLoaderData::the_null_class_loader_data() should have been used.");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3213
  // 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
  3214
  // 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
  3215
  // to revisit this for application class data sharing.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3216
  if (DumpSharedSpaces) {
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3217
    assert(type > MetaspaceObj::UnknownType && type < MetaspaceObj::_number_of_types, "sanity");
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3218
    Metaspace* space = read_only ? loader_data->ro_metaspace() : loader_data->rw_metaspace();
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3219
    result = space->allocate(word_size, NonClassType);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3220
    if (result == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3221
      report_out_of_shared_space(read_only ? SharedReadOnly : SharedReadWrite);
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3222
    } else {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3223
      space->record_allocation(result, type, space->vsm()->get_raw_word_size(word_size));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3224
    }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3225
    return Metablock::initialize(result, word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3226
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3227
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3228
  result = loader_data->metaspace_non_null()->allocate(word_size, mdtype);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3229
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3230
  if (result == NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3231
    // Try to clean out some memory and retry.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3232
    result =
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3233
      Universe::heap()->collector_policy()->satisfy_failed_metadata_allocation(
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3234
        loader_data, word_size, mdtype);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3235
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3236
    // If result is still null, we are out of memory.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3237
    if (result == NULL) {
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3238
      if (Verbose && TraceMetadataChunkAllocation) {
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3239
        gclog_or_tty->print_cr("Metaspace allocation failed for size "
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3240
          SIZE_FORMAT, word_size);
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
  3241
        if (loader_data->metaspace_or_null() != NULL) loader_data->dump(gclog_or_tty);
15086
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3242
        MetaspaceAux::dump(gclog_or_tty);
2bfd799e9147 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 14842
diff changeset
  3243
      }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3244
      // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support
19979
ebe1dbb6e1aa 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 19546
diff changeset
  3245
      const char* space_string = (mdtype == ClassType) ? "Compressed class space" :
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
  3246
                                                         "Metadata space";
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  3247
      report_java_out_of_memory(space_string);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3248
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3249
      if (JvmtiExport::should_post_resource_exhausted()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3250
        JvmtiExport::post_resource_exhausted(
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3251
            JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR,
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
  3252
            space_string);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3253
      }
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
  3254
      if (mdtype == ClassType) {
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  3255
        THROW_OOP_0(Universe::out_of_memory_error_class_metaspace());
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  3256
      } else {
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  3257
        THROW_OOP_0(Universe::out_of_memory_error_metaspace());
dd63ba6b0ee4 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 17858
diff changeset
  3258
      }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3259
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3260
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13877
diff changeset
  3261
  return Metablock::initialize(result, word_size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3262
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3263
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3264
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
  3265
  assert(DumpSharedSpaces, "sanity");
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3266
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3267
  AllocRecord *rec = new AllocRecord((address)ptr, type, (int)word_size * HeapWordSize);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3268
  if (_alloc_record_head == NULL) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3269
    _alloc_record_head = _alloc_record_tail = rec;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3270
  } else {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3271
    _alloc_record_tail->_next = rec;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3272
    _alloc_record_tail = rec;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3273
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3274
}
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3275
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3276
void Metaspace::iterate(Metaspace::AllocRecordClosure *closure) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3277
  assert(DumpSharedSpaces, "unimplemented for !DumpSharedSpaces");
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3278
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3279
  address last_addr = (address)bottom();
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3280
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3281
  for (AllocRecord *rec = _alloc_record_head; rec; rec = rec->_next) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3282
    address ptr = rec->_ptr;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3283
    if (last_addr < ptr) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3284
      closure->doit(last_addr, MetaspaceObj::UnknownType, ptr - last_addr);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3285
    }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3286
    closure->doit(ptr, rec->_type, rec->_byte_size);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3287
    last_addr = ptr + rec->_byte_size;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3288
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3289
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3290
  address top = ((address)bottom()) + used_bytes_slow(Metaspace::NonClassType);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3291
  if (last_addr < top) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3292
    closure->doit(last_addr, MetaspaceObj::UnknownType, top - last_addr);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3293
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3294
}
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17628
diff changeset
  3295
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  3296
void Metaspace::purge() {
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  3297
  MutexLockerEx cl(SpaceManager::expand_lock(),
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  3298
                   Mutex::_no_safepoint_check_flag);
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  3299
  space_list()->purge();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3300
  if (using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3301
    class_space_list()->purge();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3302
  }
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  3303
}
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  3304
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3305
void Metaspace::print_on(outputStream* out) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3306
  // Print both class virtual space counts and metaspace.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3307
  if (Verbose) {
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3308
    vsm()->print_on(out);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3309
    if (using_class_space()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3310
      class_vsm()->print_on(out);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3311
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3312
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3313
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3314
14579
7f6ce6e3dd80 8003635: NPG: AsynchGetCallTrace broken by Method* virtual call
coleenp
parents: 14474
diff changeset
  3315
bool Metaspace::contains(const void * ptr) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3316
  if (MetaspaceShared::is_in_shared_space(ptr)) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3317
    return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3318
  }
14579
7f6ce6e3dd80 8003635: NPG: AsynchGetCallTrace broken by Method* virtual call
coleenp
parents: 14474
diff changeset
  3319
  // This is checked while unlocked.  As long as the virtualspaces are added
7f6ce6e3dd80 8003635: NPG: AsynchGetCallTrace broken by Method* virtual call
coleenp
parents: 14474
diff changeset
  3320
  // at the end, the pointer will be in one of them.  The virtual spaces
7f6ce6e3dd80 8003635: NPG: AsynchGetCallTrace broken by Method* virtual call
coleenp
parents: 14474
diff changeset
  3321
  // aren't deleted presently.  When they are, some sort of locking might
7f6ce6e3dd80 8003635: NPG: AsynchGetCallTrace broken by Method* virtual call
coleenp
parents: 14474
diff changeset
  3322
  // be needed.  Note, locking this can cause inversion problems with the
7f6ce6e3dd80 8003635: NPG: AsynchGetCallTrace broken by Method* virtual call
coleenp
parents: 14474
diff changeset
  3323
  // caller in MetaspaceObj::is_metadata() function.
17101
3a82a58d9aa9 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 16996
diff changeset
  3324
  return space_list()->contains(ptr) ||
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3325
         (using_class_space() && class_space_list()->contains(ptr));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3326
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3327
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3328
void Metaspace::verify() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3329
  vsm()->verify();
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3330
  if (using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3331
    class_vsm()->verify();
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3332
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3333
}
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
void Metaspace::dump(outputStream* const out) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3336
  out->print_cr("\nVirtual space manager: " INTPTR_FORMAT, vsm());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3337
  vsm()->dump(out);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3338
  if (using_class_space()) {
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3339
    out->print_cr("\nClass space manager: " INTPTR_FORMAT, class_vsm());
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3340
    class_vsm()->dump(out);
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 18987
diff changeset
  3341
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  3342
}