annotate src/share/vm/memory/metaspace.cpp @ 14309:63a4eb8bcd23

8025856: Fix typos in the GC code Summary: Fix about 440 typos in comments in the VM code Reviewed-by: mgerdin, tschatzl, coleenp, kmo, jcoomes
author jwilhelm
date Thu, 23 Jan 2014 14:47:23 +0100
parents e4e941b83466
children e5d78f318aec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1 /*
8712
3efdfd6ddbf2 8003553: NPG: metaspace objects should be zeroed in constructors
coleenp
parents: 8040
diff changeset
2 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
6725
da91efe96a93 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.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
4 *
da91efe96a93 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
da91efe96a93 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
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
7 * published by the Free Software Foundation.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
8 *
da91efe96a93 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
da91efe96a93 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
da91efe96a93 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
da91efe96a93 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
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
13 * accompanied this code).
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
14 *
da91efe96a93 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
da91efe96a93 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,
da91efe96a93 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.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
18 *
da91efe96a93 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
da91efe96a93 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
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
21 * questions.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
22 *
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
23 */
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
24 #include "precompiled.hpp"
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
25 #include "gc_interface/collectedHeap.hpp"
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
26 #include "memory/allocation.hpp"
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
27 #include "memory/binaryTreeDictionary.hpp"
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
28 #include "memory/freeList.hpp"
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
29 #include "memory/collectorPolicy.hpp"
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
30 #include "memory/filemap.hpp"
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
31 #include "memory/freeList.hpp"
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
32 #include "memory/gcLocker.hpp"
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
33 #include "memory/metachunk.hpp"
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
34 #include "memory/metaspace.hpp"
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
35 #include "memory/metaspaceShared.hpp"
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
36 #include "memory/resourceArea.hpp"
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
37 #include "memory/universe.hpp"
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
38 #include "runtime/atomic.inline.hpp"
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
39 #include "runtime/globals.hpp"
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
40 #include "runtime/init.hpp"
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
41 #include "runtime/java.hpp"
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
42 #include "runtime/mutex.hpp"
7176
59c790074993 8003635: NPG: AsynchGetCallTrace broken by Method* virtual call
coleenp
parents: 6969
diff changeset
43 #include "runtime/orderAccess.hpp"
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
44 #include "services/memTracker.hpp"
12839
a6414751d537 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 12838
diff changeset
45 #include "services/memoryService.hpp"
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
46 #include "utilities/copy.hpp"
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
47 #include "utilities/debug.hpp"
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
48
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
49 typedef BinaryTreeDictionary<Metablock, FreeList> BlockTreeDictionary;
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
50 typedef BinaryTreeDictionary<Metachunk, FreeList> ChunkTreeDictionary;
12902
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
51
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
52 // Set this constant to enable slow integrity checking of the free chunk lists
6969
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
53 const bool metaspace_slow_verify = false;
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
54
12231
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
55 size_t const allocation_from_dictionary_limit = 4 * K;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
56
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
57 MetaWord* last_allocated = 0;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
58
13000
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
59 size_t Metaspace::_compressed_class_space_size;
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
60
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
61 // Used in declarations in SpaceManager and ChunkManager
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
62 enum ChunkIndex {
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
63 ZeroIndex = 0,
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
64 SpecializedIndex = ZeroIndex,
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
65 SmallIndex = SpecializedIndex + 1,
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
66 MediumIndex = SmallIndex + 1,
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
67 HumongousIndex = MediumIndex + 1,
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
68 NumberOfFreeLists = 3,
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
69 NumberOfInUseLists = 4
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
70 };
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
71
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
72 enum ChunkSizes { // in words.
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
73 ClassSpecializedChunk = 128,
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
74 SpecializedChunk = 128,
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
75 ClassSmallChunk = 256,
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
76 SmallChunk = 512,
11064
de2d15ce3d4a 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 10376
diff changeset
77 ClassMediumChunk = 4 * K,
12979
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
78 MediumChunk = 8 * K
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
79 };
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
80
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
81 static ChunkIndex next_chunk_index(ChunkIndex i) {
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
82 assert(i < NumberOfInUseLists, "Out of bound");
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
83 return (ChunkIndex) (i+1);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
84 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
85
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
86 volatile intptr_t MetaspaceGC::_capacity_until_GC = 0;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
87 uint MetaspaceGC::_shrink_factor = 0;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
88 bool MetaspaceGC::_should_concurrent_collect = false;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
89
10101
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
90 typedef class FreeList<Metachunk> ChunkList;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
91
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
92 // Manages the global free lists of chunks.
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
93 class ChunkManager : public CHeapObj<mtInternal> {
12979
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
94 friend class TestVirtualSpaceNodeTest;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
95
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
96 // Free list of chunks of different sizes.
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
97 // SpecializedChunk
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
98 // SmallChunk
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
99 // MediumChunk
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
100 // HumongousChunk
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
101 ChunkList _free_chunks[NumberOfFreeLists];
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
102
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
103 // HumongousChunk
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
104 ChunkTreeDictionary _humongous_dictionary;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
105
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
106 // ChunkManager in all lists of this type
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
107 size_t _free_chunks_total;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
108 size_t _free_chunks_count;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
109
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
110 void dec_free_chunks_total(size_t v) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
111 assert(_free_chunks_count > 0 &&
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
112 _free_chunks_total > 0,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
113 "About to go negative");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
114 Atomic::add_ptr(-1, &_free_chunks_count);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
115 jlong minus_v = (jlong) - (jlong) v;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
116 Atomic::add_ptr(minus_v, &_free_chunks_total);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
117 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
118
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
119 // Debug support
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
120
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
121 size_t sum_free_chunks();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
122 size_t sum_free_chunks_count();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
123
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
124 void locked_verify_free_chunks_total();
6969
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
125 void slow_locked_verify_free_chunks_total() {
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
126 if (metaspace_slow_verify) {
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
127 locked_verify_free_chunks_total();
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
128 }
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
129 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
130 void locked_verify_free_chunks_count();
6969
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
131 void slow_locked_verify_free_chunks_count() {
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
132 if (metaspace_slow_verify) {
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
133 locked_verify_free_chunks_count();
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
134 }
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
135 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
136 void verify_free_chunks_count();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
137
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
138 public:
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
139
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
140 ChunkManager(size_t specialized_size, size_t small_size, size_t medium_size)
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
141 : _free_chunks_total(0), _free_chunks_count(0) {
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
142 _free_chunks[SpecializedIndex].set_size(specialized_size);
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
143 _free_chunks[SmallIndex].set_size(small_size);
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
144 _free_chunks[MediumIndex].set_size(medium_size);
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
145 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
146
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
147 // add or delete (return) a chunk to the global freelist.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
148 Metachunk* chunk_freelist_allocate(size_t word_size);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
149
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
150 // Map a size to a list index assuming that there are lists
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
151 // for special, small, medium, and humongous chunks.
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
152 static ChunkIndex list_index(size_t size);
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
153
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
154 // Remove the chunk from its freelist. It is
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
155 // expected to be on one of the _free_chunks[] lists.
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
156 void remove_chunk(Metachunk* chunk);
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
157
10101
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
158 // Add the simple linked list of chunks to the freelist of chunks
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
159 // of type index.
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
160 void return_chunks(ChunkIndex index, Metachunk* chunks);
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
161
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
162 // Total of the space in the free chunks list
12235
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
163 size_t free_chunks_total_words();
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
164 size_t free_chunks_total_bytes();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
165
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
166 // Number of chunks in the free chunks list
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
167 size_t free_chunks_count();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
168
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
169 void inc_free_chunks_total(size_t v, size_t count = 1) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
170 Atomic::add_ptr(count, &_free_chunks_count);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
171 Atomic::add_ptr(v, &_free_chunks_total);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
172 }
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
173 ChunkTreeDictionary* humongous_dictionary() {
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
174 return &_humongous_dictionary;
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
175 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
176
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
177 ChunkList* free_chunks(ChunkIndex index);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
178
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
179 // Returns the list for the given chunk word size.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
180 ChunkList* find_free_chunks_list(size_t word_size);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
181
12906
94c0343b1887 8026715: Remove the MetaDataDeallocateALot develop flag
stefank
parents: 12902
diff changeset
182 // Remove from a list by size. Selects list based on size of chunk.
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
183 Metachunk* free_chunks_get(size_t chunk_word_size);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
184
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
185 // Debug support
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
186 void verify();
6969
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
187 void slow_verify() {
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
188 if (metaspace_slow_verify) {
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
189 verify();
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
190 }
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
191 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
192 void locked_verify();
6969
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
193 void slow_locked_verify() {
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
194 if (metaspace_slow_verify) {
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
195 locked_verify();
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
196 }
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
197 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
198 void verify_free_chunks_total();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
199
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
200 void locked_print_free_chunks(outputStream* st);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
201 void locked_print_sum_free_chunks(outputStream* st);
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
202
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
203 void print_on(outputStream* st) const;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
204 };
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
205
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
206 // Used to manage the free list of Metablocks (a block corresponds
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
207 // to the allocation of a quantum of metadata).
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
208 class BlockFreelist VALUE_OBJ_CLASS_SPEC {
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
209 BlockTreeDictionary* _dictionary;
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
210
12231
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
211 // Only allocate and split from freelist if the size of the allocation
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
212 // is at least 1/4th the size of the available block.
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
213 const static int WasteMultiplier = 4;
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
214
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
215 // Accessors
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
216 BlockTreeDictionary* dictionary() const { return _dictionary; }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
217
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
218 public:
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
219 BlockFreelist();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
220 ~BlockFreelist();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
221
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
222 // Get and return a block to the free list
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
223 MetaWord* get_block(size_t word_size);
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
224 void return_block(MetaWord* p, size_t word_size);
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
225
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
226 size_t total_size() {
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
227 if (dictionary() == NULL) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
228 return 0;
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
229 } else {
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
230 return dictionary()->total_size();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
231 }
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
232 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
233
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
234 void print_on(outputStream* st) const;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
235 };
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
236
12902
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
237 // A VirtualSpaceList node.
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
238 class VirtualSpaceNode : public CHeapObj<mtClass> {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
239 friend class VirtualSpaceList;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
240
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
241 // Link to next VirtualSpaceNode
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
242 VirtualSpaceNode* _next;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
243
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
244 // total in the VirtualSpace
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
245 MemRegion _reserved;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
246 ReservedSpace _rs;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
247 VirtualSpace _virtual_space;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
248 MetaWord* _top;
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
249 // count of chunks contained in this VirtualSpace
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
250 uintx _container_count;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
251
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
252 // Convenience functions to access the _virtual_space
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
253 char* low() const { return virtual_space()->low(); }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
254 char* high() const { return virtual_space()->high(); }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
255
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
256 // The first Metachunk will be allocated at the bottom of the
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
257 // VirtualSpace
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
258 Metachunk* first_chunk() { return (Metachunk*) bottom(); }
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
259
12979
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
260 // Committed but unused space in the virtual space
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
261 size_t free_words_in_vs() const;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
262 public:
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
263
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
264 VirtualSpaceNode(size_t byte_size);
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
265 VirtualSpaceNode(ReservedSpace rs) : _top(NULL), _next(NULL), _rs(rs), _container_count(0) {}
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
266 ~VirtualSpaceNode();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
267
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
268 // Convenience functions for logical bottom and end
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
269 MetaWord* bottom() const { return (MetaWord*) _virtual_space.low(); }
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
270 MetaWord* end() const { return (MetaWord*) _virtual_space.high(); }
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
271
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
272 size_t reserved_words() const { return _virtual_space.reserved_size() / BytesPerWord; }
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
273 size_t committed_words() const { return _virtual_space.actual_committed_size() / BytesPerWord; }
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
274
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
275 bool is_pre_committed() const { return _virtual_space.special(); }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
276
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
277 // address of next available space in _virtual_space;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
278 // Accessors
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
279 VirtualSpaceNode* next() { return _next; }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
280 void set_next(VirtualSpaceNode* v) { _next = v; }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
281
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
282 void set_reserved(MemRegion const v) { _reserved = v; }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
283 void set_top(MetaWord* v) { _top = v; }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
284
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
285 // Accessors
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
286 MemRegion* reserved() { return &_reserved; }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
287 VirtualSpace* virtual_space() const { return (VirtualSpace*) &_virtual_space; }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
288
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
289 // Returns true if "word_size" is available in the VirtualSpace
14211
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
290 bool is_available(size_t word_size) { return word_size <= pointer_delta(end(), _top, sizeof(MetaWord)); }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
291
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
292 MetaWord* top() const { return _top; }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
293 void inc_top(size_t word_size) { _top += word_size; }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
294
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
295 uintx container_count() { return _container_count; }
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
296 void inc_container_count();
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
297 void dec_container_count();
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
298 #ifdef ASSERT
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
299 uint container_count_slow();
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
300 void verify_container_count();
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
301 #endif
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
302
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
303 // used and capacity in this single entry in the list
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
304 size_t used_words_in_vs() const;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
305 size_t capacity_words_in_vs() const;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
306
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
307 bool initialize();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
308
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
309 // get space from the virtual space
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
310 Metachunk* take_from_committed(size_t chunk_word_size);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
311
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
312 // Allocate a chunk from the virtual space and return it.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
313 Metachunk* get_chunk_vs(size_t chunk_word_size);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
314
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
315 // Expands/shrinks the committed space in a virtual space. Delegates
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
316 // to Virtualspace
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
317 bool expand_by(size_t min_words, size_t preferred_words);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
318
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
319 // In preparation for deleting this node, remove all the chunks
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
320 // in the node from any freelist.
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
321 void purge(ChunkManager* chunk_manager);
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
322
12979
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
323 // If an allocation doesn't fit in the current node a new node is created.
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
324 // Allocate chunks out of the remaining committed space in this node
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
325 // to avoid wasting that memory.
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
326 // This always adds up because all the chunk sizes are multiples of
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
327 // the smallest chunk size.
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
328 void retire(ChunkManager* chunk_manager);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
329
7185
90273fc0a981 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 6969
diff changeset
330 #ifdef ASSERT
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
331 // Debug support
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
332 void mangle();
7185
90273fc0a981 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 6969
diff changeset
333 #endif
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
334
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
335 void print_on(outputStream* st) const;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
336 };
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
337
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
338 #define assert_is_ptr_aligned(ptr, alignment) \
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
339 assert(is_ptr_aligned(ptr, alignment), \
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
340 err_msg(PTR_FORMAT " is not aligned to " \
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
341 SIZE_FORMAT, ptr, alignment))
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
342
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
343 #define assert_is_size_aligned(size, alignment) \
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
344 assert(is_size_aligned(size, alignment), \
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
345 err_msg(SIZE_FORMAT " is not aligned to " \
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
346 SIZE_FORMAT, size, alignment))
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
347
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
348
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
349 // Decide if large pages should be committed when the memory is reserved.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
350 static bool should_commit_large_pages_when_reserving(size_t bytes) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
351 if (UseLargePages && UseLargePagesInMetaspace && !os::can_commit_large_page_memory()) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
352 size_t words = bytes / BytesPerWord;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
353 bool is_class = false; // We never reserve large pages for the class space.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
354 if (MetaspaceGC::can_expand(words, is_class) &&
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
355 MetaspaceGC::allowed_expansion() >= words) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
356 return true;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
357 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
358 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
359
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
360 return false;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
361 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
362
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
363 // byte_size is the size of the associated virtualspace.
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
364 VirtualSpaceNode::VirtualSpaceNode(size_t bytes) : _top(NULL), _next(NULL), _rs(), _container_count(0) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
365 assert_is_size_aligned(bytes, Metaspace::reserve_alignment());
8752
82f49e8e2c28 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: 8712
diff changeset
366
8804
91bf0bdae37b 8008217: CDS: Class data sharing limits the malloc heap on Solaris
coleenp
parents: 8754
diff changeset
367 // This allocates memory with mmap. For DumpSharedspaces, try to reserve
91bf0bdae37b 8008217: CDS: Class data sharing limits the malloc heap on Solaris
coleenp
parents: 8754
diff changeset
368 // configurable address, generally at the top of the Java heap so other
91bf0bdae37b 8008217: CDS: Class data sharing limits the malloc heap on Solaris
coleenp
parents: 8754
diff changeset
369 // memory addresses don't conflict.
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
370 if (DumpSharedSpaces) {
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
371 bool large_pages = false; // No large pages when dumping the CDS archive.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
372 char* shared_base = (char*)align_ptr_up((char*)SharedBaseAddress, Metaspace::reserve_alignment());
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
373
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
374 _rs = ReservedSpace(bytes, Metaspace::reserve_alignment(), large_pages, shared_base, 0);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
375 if (_rs.is_reserved()) {
8804
91bf0bdae37b 8008217: CDS: Class data sharing limits the malloc heap on Solaris
coleenp
parents: 8754
diff changeset
376 assert(shared_base == 0 || _rs.base() == shared_base, "should match");
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
377 } else {
8804
91bf0bdae37b 8008217: CDS: Class data sharing limits the malloc heap on Solaris
coleenp
parents: 8754
diff changeset
378 // Get a mmap region anywhere if the SharedBaseAddress fails.
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
379 _rs = ReservedSpace(bytes, Metaspace::reserve_alignment(), large_pages);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
380 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
381 MetaspaceShared::set_shared_rs(&_rs);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
382 } else {
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
383 bool large_pages = should_commit_large_pages_when_reserving(bytes);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
384
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
385 _rs = ReservedSpace(bytes, Metaspace::reserve_alignment(), large_pages);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
386 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
387
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
388 if (_rs.is_reserved()) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
389 assert(_rs.base() != NULL, "Catch if we get a NULL address");
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
390 assert(_rs.size() != 0, "Catch if we get a 0 size");
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
391 assert_is_ptr_aligned(_rs.base(), Metaspace::reserve_alignment());
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
392 assert_is_size_aligned(_rs.size(), Metaspace::reserve_alignment());
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
393
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
394 MemTracker::record_virtual_memory_type((address)_rs.base(), mtClass);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
395 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
396 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
397
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
398 void VirtualSpaceNode::purge(ChunkManager* chunk_manager) {
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
399 Metachunk* chunk = first_chunk();
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
400 Metachunk* invalid_chunk = (Metachunk*) top();
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
401 while (chunk < invalid_chunk ) {
12902
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
402 assert(chunk->is_tagged_free(), "Should be tagged free");
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
403 MetaWord* next = ((MetaWord*)chunk) + chunk->word_size();
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
404 chunk_manager->remove_chunk(chunk);
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
405 assert(chunk->next() == NULL &&
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
406 chunk->prev() == NULL,
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
407 "Was not removed from its list");
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
408 chunk = (Metachunk*) next;
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
409 }
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
410 }
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
411
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
412 #ifdef ASSERT
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
413 uint VirtualSpaceNode::container_count_slow() {
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
414 uint count = 0;
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
415 Metachunk* chunk = first_chunk();
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
416 Metachunk* invalid_chunk = (Metachunk*) top();
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
417 while (chunk < invalid_chunk ) {
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
418 MetaWord* next = ((MetaWord*)chunk) + chunk->word_size();
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
419 // Don't count the chunks on the free lists. Those are
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
420 // still part of the VirtualSpaceNode but not currently
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
421 // counted.
12902
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
422 if (!chunk->is_tagged_free()) {
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
423 count++;
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
424 }
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
425 chunk = (Metachunk*) next;
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
426 }
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
427 return count;
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
428 }
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
429 #endif
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
430
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
431 // List of VirtualSpaces for metadata allocation.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
432 class VirtualSpaceList : public CHeapObj<mtClass> {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
433 friend class VirtualSpaceNode;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
434
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
435 enum VirtualSpaceSizes {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
436 VirtualSpaceSize = 256 * K
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
437 };
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
438
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
439 // Head of the list
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
440 VirtualSpaceNode* _virtual_space_list;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
441 // virtual space currently being used for allocations
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
442 VirtualSpaceNode* _current_virtual_space;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
443
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
444 // Is this VirtualSpaceList used for the compressed class space
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
445 bool _is_class;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
446
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
447 // Sum of reserved and committed memory in the virtual spaces
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
448 size_t _reserved_words;
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
449 size_t _committed_words;
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
450
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
451 // Number of virtual spaces
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
452 size_t _virtual_space_count;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
453
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
454 ~VirtualSpaceList();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
455
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
456 VirtualSpaceNode* virtual_space_list() const { return _virtual_space_list; }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
457
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
458 void set_virtual_space_list(VirtualSpaceNode* v) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
459 _virtual_space_list = v;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
460 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
461 void set_current_virtual_space(VirtualSpaceNode* v) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
462 _current_virtual_space = v;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
463 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
464
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
465 void link_vs(VirtualSpaceNode* new_entry);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
466
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
467 // Get another virtual space and add it to the list. This
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
468 // is typically prompted by a failed attempt to allocate a chunk
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
469 // and is typically followed by the allocation of a chunk.
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
470 bool create_new_virtual_space(size_t vs_word_size);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
471
12979
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
472 // Chunk up the unused committed space in the current
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
473 // virtual space and add the chunks to the free list.
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
474 void retire_current_virtual_space();
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
475
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
476 public:
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
477 VirtualSpaceList(size_t word_size);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
478 VirtualSpaceList(ReservedSpace rs);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
479
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
480 size_t free_bytes();
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
481
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
482 Metachunk* get_new_chunk(size_t word_size,
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
483 size_t grow_chunks_by_words,
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
484 size_t medium_chunk_bunch);
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
485
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
486 bool expand_node_by(VirtualSpaceNode* node,
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
487 size_t min_words,
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
488 size_t preferred_words);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
489
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
490 bool expand_by(size_t min_words,
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
491 size_t preferred_words);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
492
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
493 VirtualSpaceNode* current_virtual_space() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
494 return _current_virtual_space;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
495 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
496
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
497 bool is_class() const { return _is_class; }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
498
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
499 bool initialization_succeeded() { return _virtual_space_list != NULL; }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
500
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
501 size_t reserved_words() { return _reserved_words; }
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
502 size_t reserved_bytes() { return reserved_words() * BytesPerWord; }
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
503 size_t committed_words() { return _committed_words; }
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
504 size_t committed_bytes() { return committed_words() * BytesPerWord; }
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
505
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
506 void inc_reserved_words(size_t v);
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
507 void dec_reserved_words(size_t v);
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
508 void inc_committed_words(size_t v);
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
509 void dec_committed_words(size_t v);
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
510 void inc_virtual_space_count();
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
511 void dec_virtual_space_count();
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
512
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
513 // Unlink empty VirtualSpaceNodes and free it.
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
514 void purge(ChunkManager* chunk_manager);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
515
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
516 void print_on(outputStream* st) const;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
517
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
518 class VirtualSpaceListIterator : public StackObj {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
519 VirtualSpaceNode* _virtual_spaces;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
520 public:
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
521 VirtualSpaceListIterator(VirtualSpaceNode* virtual_spaces) :
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
522 _virtual_spaces(virtual_spaces) {}
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
523
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
524 bool repeat() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
525 return _virtual_spaces != NULL;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
526 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
527
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
528 VirtualSpaceNode* get_next() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
529 VirtualSpaceNode* result = _virtual_spaces;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
530 if (_virtual_spaces != NULL) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
531 _virtual_spaces = _virtual_spaces->next();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
532 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
533 return result;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
534 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
535 };
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
536 };
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
537
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
538 class Metadebug : AllStatic {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
539 // Debugging support for Metaspaces
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
540 static int _allocation_fail_alot_count;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
541
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
542 public:
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
543
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
544 static void init_allocation_fail_alot_count();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
545 #ifdef ASSERT
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
546 static bool test_metadata_failure();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
547 #endif
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
548 };
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
549
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
550 int Metadebug::_allocation_fail_alot_count = 0;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
551
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
552 // SpaceManager - used by Metaspace to handle allocations
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
553 class SpaceManager : public CHeapObj<mtClass> {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
554 friend class Metaspace;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
555 friend class Metadebug;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
556
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
557 private:
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
558
14190
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
559 // protects allocations
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
560 Mutex* const _lock;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
561
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
562 // Type of metadata allocated.
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
563 Metaspace::MetadataType _mdtype;
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
564
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
565 // List of chunks in use by this SpaceManager. Allocations
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
566 // are done from the current chunk. The list is used for deallocating
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
567 // chunks when the SpaceManager is freed.
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
568 Metachunk* _chunks_in_use[NumberOfInUseLists];
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
569 Metachunk* _current_chunk;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
570
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
571 // Number of small chunks to allocate to a manager
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
572 // If class space manager, small chunks are unlimited
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
573 static uint const _small_chunk_limit;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
574
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
575 // Sum of all space in allocated chunks
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
576 size_t _allocated_blocks_words;
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
577
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
578 // Sum of all allocated chunks
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
579 size_t _allocated_chunks_words;
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
580 size_t _allocated_chunks_count;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
581
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
582 // Free lists of blocks are per SpaceManager since they
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
583 // are assumed to be in chunks in use by the SpaceManager
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
584 // and all chunks in use by a SpaceManager are freed when
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
585 // the class loader using the SpaceManager is collected.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
586 BlockFreelist _block_freelists;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
587
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
588 // protects virtualspace and chunk expansions
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
589 static const char* _expand_lock_name;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
590 static const int _expand_lock_rank;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
591 static Mutex* const _expand_lock;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
592
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
593 private:
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
594 // Accessors
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
595 Metachunk* chunks_in_use(ChunkIndex index) const { return _chunks_in_use[index]; }
14190
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
596 void set_chunks_in_use(ChunkIndex index, Metachunk* v) {
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
597 // ensure lock-free iteration sees fully initialized node
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
598 OrderAccess::storestore();
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
599 _chunks_in_use[index] = v;
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
600 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
601
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
602 BlockFreelist* block_freelists() const {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
603 return (BlockFreelist*) &_block_freelists;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
604 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
605
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
606 Metaspace::MetadataType mdtype() { return _mdtype; }
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
607
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
608 VirtualSpaceList* vs_list() const { return Metaspace::get_space_list(_mdtype); }
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
609 ChunkManager* chunk_manager() const { return Metaspace::get_chunk_manager(_mdtype); }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
610
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
611 Metachunk* current_chunk() const { return _current_chunk; }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
612 void set_current_chunk(Metachunk* v) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
613 _current_chunk = v;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
614 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
615
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
616 Metachunk* find_current_chunk(size_t word_size);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
617
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
618 // Add chunk to the list of chunks in use
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
619 void add_chunk(Metachunk* v, bool make_current);
12231
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
620 void retire_current_chunk();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
621
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
622 Mutex* lock() const { return _lock; }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
623
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
624 const char* chunk_size_name(ChunkIndex index) const;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
625
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
626 protected:
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
627 void initialize();
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
628
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
629 public:
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
630 SpaceManager(Metaspace::MetadataType mdtype,
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
631 Mutex* lock);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
632 ~SpaceManager();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
633
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
634 enum ChunkMultiples {
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
635 MediumChunkMultiple = 4
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
636 };
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
637
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
638 bool is_class() { return _mdtype == Metaspace::ClassType; }
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
639
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
640 // Accessors
12979
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
641 size_t specialized_chunk_size() { return (size_t) is_class() ? ClassSpecializedChunk : SpecializedChunk; }
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
642 size_t small_chunk_size() { return (size_t) is_class() ? ClassSmallChunk : SmallChunk; }
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
643 size_t medium_chunk_size() { return (size_t) is_class() ? ClassMediumChunk : MediumChunk; }
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
644 size_t medium_chunk_bunch() { return medium_chunk_size() * MediumChunkMultiple; }
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
645
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
646 size_t smallest_chunk_size() { return specialized_chunk_size(); }
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
647
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
648 size_t allocated_blocks_words() const { return _allocated_blocks_words; }
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
649 size_t allocated_blocks_bytes() const { return _allocated_blocks_words * BytesPerWord; }
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
650 size_t allocated_chunks_words() const { return _allocated_chunks_words; }
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
651 size_t allocated_chunks_count() const { return _allocated_chunks_count; }
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
652
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
653 bool is_humongous(size_t word_size) { return word_size > medium_chunk_size(); }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
654
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
655 static Mutex* expand_lock() { return _expand_lock; }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
656
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
657 // Increment the per Metaspace and global running sums for Metachunks
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
658 // by the given size. This is used when a Metachunk to added to
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
659 // the in-use list.
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
660 void inc_size_metrics(size_t words);
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
661 // Increment the per Metaspace and global running sums Metablocks by the given
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
662 // size. This is used when a Metablock is allocated.
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
663 void inc_used_metrics(size_t words);
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
664 // Delete the portion of the running sums for this SpaceManager. That is,
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
665 // the globals running sums for the Metachunks and Metablocks are
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
666 // decremented for all the Metachunks in-use by this SpaceManager.
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
667 void dec_total_from_size_metrics();
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
668
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
669 // Set the sizes for the initial chunks.
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
670 void get_initial_chunk_sizes(Metaspace::MetaspaceType type,
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
671 size_t* chunk_word_size,
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
672 size_t* class_chunk_word_size);
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
673
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
674 size_t sum_capacity_in_chunks_in_use() const;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
675 size_t sum_used_in_chunks_in_use() const;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
676 size_t sum_free_in_chunks_in_use() const;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
677 size_t sum_waste_in_chunks_in_use() const;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
678 size_t sum_waste_in_chunks_in_use(ChunkIndex index ) const;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
679
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
680 size_t sum_count_in_chunks_in_use();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
681 size_t sum_count_in_chunks_in_use(ChunkIndex i);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
682
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
683 Metachunk* get_new_chunk(size_t word_size, size_t grow_chunks_by_words);
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
684
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
685 // Block allocation and deallocation.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
686 // Allocates a block from the current chunk
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
687 MetaWord* allocate(size_t word_size);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
688
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
689 // Helper for allocations
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
690 MetaWord* allocate_work(size_t word_size);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
691
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
692 // Returns a block to the per manager freelist
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
693 void deallocate(MetaWord* p, size_t word_size);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
694
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
695 // Based on the allocation size and a minimum chunk size,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
696 // returned chunk size (for expanding space for chunk allocation).
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
697 size_t calc_chunk_size(size_t allocation_word_size);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
698
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
699 // Called when an allocation from the current chunk fails.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
700 // Gets a new chunk (may require getting a new virtual space),
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
701 // and allocates from that chunk.
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
702 MetaWord* grow_and_allocate(size_t word_size);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
703
12839
a6414751d537 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 12838
diff changeset
704 // Notify memory usage to MemoryService.
a6414751d537 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 12838
diff changeset
705 void track_metaspace_memory_usage();
a6414751d537 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 12838
diff changeset
706
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
707 // debugging support.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
708
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
709 void dump(outputStream* const out) const;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
710 void print_on(outputStream* st) const;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
711 void locked_print_chunks_in_use_on(outputStream* st) const;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
712
14190
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
713 bool contains(const void *ptr);
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
714
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
715 void verify();
7208
eade6b2e4782 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 7187
diff changeset
716 void verify_chunk_size(Metachunk* chunk);
7185
90273fc0a981 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 6969
diff changeset
717 NOT_PRODUCT(void mangle_freed_chunks();)
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
718 #ifdef ASSERT
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
719 void verify_allocated_blocks_words();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
720 #endif
10376
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
721
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
722 size_t get_raw_word_size(size_t word_size) {
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
723 size_t byte_size = word_size * BytesPerWord;
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
724
12902
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
725 size_t raw_bytes_size = MAX2(byte_size, sizeof(Metablock));
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
726 raw_bytes_size = align_size_up(raw_bytes_size, Metachunk::object_alignment());
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
727
10376
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
728 size_t raw_word_size = raw_bytes_size / BytesPerWord;
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
729 assert(raw_word_size * BytesPerWord == raw_bytes_size, "Size problem");
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
730
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
731 return raw_word_size;
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
732 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
733 };
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
734
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
735 uint const SpaceManager::_small_chunk_limit = 4;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
736
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
737 const char* SpaceManager::_expand_lock_name =
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
738 "SpaceManager chunk allocation lock";
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
739 const int SpaceManager::_expand_lock_rank = Monitor::leaf - 1;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
740 Mutex* const SpaceManager::_expand_lock =
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
741 new Mutex(SpaceManager::_expand_lock_rank,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
742 SpaceManager::_expand_lock_name,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
743 Mutex::_allow_vm_block_flag);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
744
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
745 void VirtualSpaceNode::inc_container_count() {
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
746 assert_lock_strong(SpaceManager::expand_lock());
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
747 _container_count++;
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
748 assert(_container_count == container_count_slow(),
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
749 err_msg("Inconsistency in countainer_count _container_count " SIZE_FORMAT
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
750 " container_count_slow() " SIZE_FORMAT,
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
751 _container_count, container_count_slow()));
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
752 }
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
753
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
754 void VirtualSpaceNode::dec_container_count() {
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
755 assert_lock_strong(SpaceManager::expand_lock());
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
756 _container_count--;
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
757 }
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
758
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
759 #ifdef ASSERT
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
760 void VirtualSpaceNode::verify_container_count() {
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
761 assert(_container_count == container_count_slow(),
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
762 err_msg("Inconsistency in countainer_count _container_count " SIZE_FORMAT
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
763 " container_count_slow() " SIZE_FORMAT, _container_count, container_count_slow()));
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
764 }
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
765 #endif
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
766
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
767 // BlockFreelist methods
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
768
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
769 BlockFreelist::BlockFreelist() : _dictionary(NULL) {}
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
770
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
771 BlockFreelist::~BlockFreelist() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
772 if (_dictionary != NULL) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
773 if (Verbose && TraceMetadataChunkAllocation) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
774 _dictionary->print_free_lists(gclog_or_tty);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
775 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
776 delete _dictionary;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
777 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
778 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
779
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
780 void BlockFreelist::return_block(MetaWord* p, size_t word_size) {
12902
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
781 Metablock* free_chunk = ::new (p) Metablock(word_size);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
782 if (dictionary() == NULL) {
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
783 _dictionary = new BlockTreeDictionary();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
784 }
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
785 dictionary()->return_chunk(free_chunk);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
786 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
787
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
788 MetaWord* BlockFreelist::get_block(size_t word_size) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
789 if (dictionary() == NULL) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
790 return NULL;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
791 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
792
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
793 if (word_size < TreeChunk<Metablock, FreeList>::min_size()) {
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
794 // Dark matter. Too small for dictionary.
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
795 return NULL;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
796 }
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
797
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
798 Metablock* free_block =
12231
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
799 dictionary()->get_chunk(word_size, FreeBlockDictionary<Metablock>::atLeast);
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
800 if (free_block == NULL) {
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
801 return NULL;
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
802 }
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
803
12231
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
804 const size_t block_size = free_block->size();
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
805 if (block_size > WasteMultiplier * word_size) {
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
806 return_block((MetaWord*)free_block, block_size);
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
807 return NULL;
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
808 }
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
809
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
810 MetaWord* new_block = (MetaWord*)free_block;
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
811 assert(block_size >= word_size, "Incorrect size of block from freelist");
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
812 const size_t unused = block_size - word_size;
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
813 if (unused >= TreeChunk<Metablock, FreeList>::min_size()) {
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
814 return_block(new_block + word_size, unused);
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
815 }
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
816
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
817 return new_block;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
818 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
819
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
820 void BlockFreelist::print_on(outputStream* st) const {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
821 if (dictionary() == NULL) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
822 return;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
823 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
824 dictionary()->print_free_lists(st);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
825 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
826
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
827 // VirtualSpaceNode methods
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
828
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
829 VirtualSpaceNode::~VirtualSpaceNode() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
830 _rs.release();
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
831 #ifdef ASSERT
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
832 size_t word_size = sizeof(*this) / BytesPerWord;
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
833 Copy::fill_to_words((HeapWord*) this, word_size, 0xf1f1f1f1);
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
834 #endif
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
835 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
836
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
837 size_t VirtualSpaceNode::used_words_in_vs() const {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
838 return pointer_delta(top(), bottom(), sizeof(MetaWord));
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
839 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
840
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
841 // Space committed in the VirtualSpace
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
842 size_t VirtualSpaceNode::capacity_words_in_vs() const {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
843 return pointer_delta(end(), bottom(), sizeof(MetaWord));
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
844 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
845
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
846 size_t VirtualSpaceNode::free_words_in_vs() const {
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
847 return pointer_delta(end(), top(), sizeof(MetaWord));
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
848 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
849
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
850 // Allocates the chunk from the virtual space only.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
851 // This interface is also used internally for debugging. Not all
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
852 // chunks removed here are necessarily used for allocation.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
853 Metachunk* VirtualSpaceNode::take_from_committed(size_t chunk_word_size) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
854 // Bottom of the new chunk
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
855 MetaWord* chunk_limit = top();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
856 assert(chunk_limit != NULL, "Not safe to call this method");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
857
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
858 // The virtual spaces are always expanded by the
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
859 // commit granularity to enforce the following condition.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
860 // Without this the is_available check will not work correctly.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
861 assert(_virtual_space.committed_size() == _virtual_space.actual_committed_size(),
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
862 "The committed memory doesn't match the expanded memory.");
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
863
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
864 if (!is_available(chunk_word_size)) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
865 if (TraceMetadataChunkAllocation) {
12240
8c5e6482cbfc 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 12239
diff changeset
866 gclog_or_tty->print("VirtualSpaceNode::take_from_committed() not available %d words ", chunk_word_size);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
867 // Dump some information about the virtual space that is nearly full
12240
8c5e6482cbfc 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 12239
diff changeset
868 print_on(gclog_or_tty);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
869 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
870 return NULL;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
871 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
872
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
873 // Take the space (bump top on the current virtual space).
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
874 inc_top(chunk_word_size);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
875
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
876 // Initialize the chunk
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
877 Metachunk* result = ::new (chunk_limit) Metachunk(chunk_word_size, this);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
878 return result;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
879 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
880
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
881
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
882 // Expand the virtual space (commit more of the reserved space)
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
883 bool VirtualSpaceNode::expand_by(size_t min_words, size_t preferred_words) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
884 size_t min_bytes = min_words * BytesPerWord;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
885 size_t preferred_bytes = preferred_words * BytesPerWord;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
886
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
887 size_t uncommitted = virtual_space()->reserved_size() - virtual_space()->actual_committed_size();
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
888
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
889 if (uncommitted < min_bytes) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
890 return false;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
891 }
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
892
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
893 size_t commit = MIN2(preferred_bytes, uncommitted);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
894 bool result = virtual_space()->expand_by(commit, false);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
895
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
896 assert(result, "Failed to commit memory");
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
897
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
898 return result;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
899 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
900
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
901 Metachunk* VirtualSpaceNode::get_chunk_vs(size_t chunk_word_size) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
902 assert_lock_strong(SpaceManager::expand_lock());
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
903 Metachunk* result = take_from_committed(chunk_word_size);
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
904 if (result != NULL) {
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
905 inc_container_count();
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
906 }
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
907 return result;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
908 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
909
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
910 bool VirtualSpaceNode::initialize() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
911
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
912 if (!_rs.is_reserved()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
913 return false;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
914 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
915
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
916 // These are necessary restriction to make sure that the virtual space always
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
917 // grows in steps of Metaspace::commit_alignment(). If both base and size are
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
918 // aligned only the middle alignment of the VirtualSpace is used.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
919 assert_is_ptr_aligned(_rs.base(), Metaspace::commit_alignment());
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
920 assert_is_size_aligned(_rs.size(), Metaspace::commit_alignment());
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
921
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
922 // ReservedSpaces marked as special will have the entire memory
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
923 // pre-committed. Setting a committed size will make sure that
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
924 // committed_size and actual_committed_size agrees.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
925 size_t pre_committed_size = _rs.special() ? _rs.size() : 0;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
926
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
927 bool result = virtual_space()->initialize_with_granularity(_rs, pre_committed_size,
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
928 Metaspace::commit_alignment());
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
929 if (result) {
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
930 assert(virtual_space()->committed_size() == virtual_space()->actual_committed_size(),
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
931 "Checking that the pre-committed memory was registered by the VirtualSpace");
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
932
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
933 set_top((MetaWord*)virtual_space()->low());
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
934 set_reserved(MemRegion((HeapWord*)_rs.base(),
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
935 (HeapWord*)(_rs.base() + _rs.size())));
6726
03049e0e8544 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 6725
diff changeset
936
03049e0e8544 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 6725
diff changeset
937 assert(reserved()->start() == (HeapWord*) _rs.base(),
03049e0e8544 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 6725
diff changeset
938 err_msg("Reserved start was not set properly " PTR_FORMAT
03049e0e8544 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 6725
diff changeset
939 " != " PTR_FORMAT, reserved()->start(), _rs.base()));
03049e0e8544 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 6725
diff changeset
940 assert(reserved()->word_size() == _rs.size() / BytesPerWord,
03049e0e8544 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 6725
diff changeset
941 err_msg("Reserved size was not set properly " SIZE_FORMAT
03049e0e8544 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 6725
diff changeset
942 " != " SIZE_FORMAT, reserved()->word_size(),
03049e0e8544 7195823: NPG: CMS reserved() doesn't match _rs.base().
coleenp
parents: 6725
diff changeset
943 _rs.size() / BytesPerWord));
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
944 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
945
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
946 return result;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
947 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
948
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
949 void VirtualSpaceNode::print_on(outputStream* st) const {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
950 size_t used = used_words_in_vs();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
951 size_t capacity = capacity_words_in_vs();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
952 VirtualSpace* vs = virtual_space();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
953 st->print_cr(" space @ " PTR_FORMAT " " SIZE_FORMAT "K, %3d%% used "
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
954 "[" PTR_FORMAT ", " PTR_FORMAT ", "
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
955 PTR_FORMAT ", " PTR_FORMAT ")",
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
956 vs, capacity / K,
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
957 capacity == 0 ? 0 : used * 100 / capacity,
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
958 bottom(), top(), end(),
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
959 vs->high_boundary());
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
960 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
961
7185
90273fc0a981 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 6969
diff changeset
962 #ifdef ASSERT
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
963 void VirtualSpaceNode::mangle() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
964 size_t word_size = capacity_words_in_vs();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
965 Copy::fill_to_words((HeapWord*) low(), word_size, 0xf1f1f1f1);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
966 }
7185
90273fc0a981 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 6969
diff changeset
967 #endif // ASSERT
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
968
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
969 // VirtualSpaceList methods
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
970 // Space allocated from the VirtualSpace
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
971
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
972 VirtualSpaceList::~VirtualSpaceList() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
973 VirtualSpaceListIterator iter(virtual_space_list());
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
974 while (iter.repeat()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
975 VirtualSpaceNode* vsl = iter.get_next();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
976 delete vsl;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
977 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
978 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
979
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
980 void VirtualSpaceList::inc_reserved_words(size_t v) {
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
981 assert_lock_strong(SpaceManager::expand_lock());
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
982 _reserved_words = _reserved_words + v;
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
983 }
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
984 void VirtualSpaceList::dec_reserved_words(size_t v) {
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
985 assert_lock_strong(SpaceManager::expand_lock());
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
986 _reserved_words = _reserved_words - v;
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
987 }
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
988
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
989 #define assert_committed_below_limit() \
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
990 assert(MetaspaceAux::committed_bytes() <= MaxMetaspaceSize, \
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
991 err_msg("Too much committed memory. Committed: " SIZE_FORMAT \
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
992 " limit (MaxMetaspaceSize): " SIZE_FORMAT, \
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
993 MetaspaceAux::committed_bytes(), MaxMetaspaceSize));
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
994
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
995 void VirtualSpaceList::inc_committed_words(size_t v) {
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
996 assert_lock_strong(SpaceManager::expand_lock());
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
997 _committed_words = _committed_words + v;
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
998
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
999 assert_committed_below_limit();
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1000 }
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1001 void VirtualSpaceList::dec_committed_words(size_t v) {
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1002 assert_lock_strong(SpaceManager::expand_lock());
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1003 _committed_words = _committed_words - v;
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1004
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1005 assert_committed_below_limit();
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1006 }
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1007
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1008 void VirtualSpaceList::inc_virtual_space_count() {
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1009 assert_lock_strong(SpaceManager::expand_lock());
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1010 _virtual_space_count++;
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1011 }
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1012 void VirtualSpaceList::dec_virtual_space_count() {
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1013 assert_lock_strong(SpaceManager::expand_lock());
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1014 _virtual_space_count--;
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1015 }
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1016
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1017 void ChunkManager::remove_chunk(Metachunk* chunk) {
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1018 size_t word_size = chunk->word_size();
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1019 ChunkIndex index = list_index(word_size);
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1020 if (index != HumongousIndex) {
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1021 free_chunks(index)->remove_chunk(chunk);
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1022 } else {
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1023 humongous_dictionary()->remove_chunk(chunk);
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1024 }
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1025
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1026 // Chunk is being removed from the chunks free list.
12902
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
1027 dec_free_chunks_total(chunk->word_size());
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1028 }
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1029
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1030 // Walk the list of VirtualSpaceNodes and delete
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1031 // nodes with a 0 container_count. Remove Metachunks in
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1032 // the node from their respective freelists.
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
1033 void VirtualSpaceList::purge(ChunkManager* chunk_manager) {
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1034 assert_lock_strong(SpaceManager::expand_lock());
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1035 // Don't use a VirtualSpaceListIterator because this
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1036 // list is being changed and a straightforward use of an iterator is not safe.
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1037 VirtualSpaceNode* purged_vsl = NULL;
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1038 VirtualSpaceNode* prev_vsl = virtual_space_list();
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1039 VirtualSpaceNode* next_vsl = prev_vsl;
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1040 while (next_vsl != NULL) {
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1041 VirtualSpaceNode* vsl = next_vsl;
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1042 next_vsl = vsl->next();
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1043 // Don't free the current virtual space since it will likely
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1044 // be needed soon.
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1045 if (vsl->container_count() == 0 && vsl != current_virtual_space()) {
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1046 // Unlink it from the list
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1047 if (prev_vsl == vsl) {
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1048 // This is the case of the current node being the first node.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1049 assert(vsl == virtual_space_list(), "Expected to be the first node");
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1050 set_virtual_space_list(vsl->next());
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1051 } else {
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1052 prev_vsl->set_next(vsl->next());
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1053 }
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1054
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
1055 vsl->purge(chunk_manager);
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1056 dec_reserved_words(vsl->reserved_words());
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1057 dec_committed_words(vsl->committed_words());
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1058 dec_virtual_space_count();
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1059 purged_vsl = vsl;
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1060 delete vsl;
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1061 } else {
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1062 prev_vsl = vsl;
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1063 }
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1064 }
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1065 #ifdef ASSERT
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1066 if (purged_vsl != NULL) {
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1067 // List should be stable enough to use an iterator here.
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1068 VirtualSpaceListIterator iter(virtual_space_list());
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1069 while (iter.repeat()) {
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1070 VirtualSpaceNode* vsl = iter.get_next();
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1071 assert(vsl != purged_vsl, "Purge of vsl failed");
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1072 }
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1073 }
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1074 #endif
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1075 }
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1076
12979
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1077 void VirtualSpaceList::retire_current_virtual_space() {
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1078 assert_lock_strong(SpaceManager::expand_lock());
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1079
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1080 VirtualSpaceNode* vsn = current_virtual_space();
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1081
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1082 ChunkManager* cm = is_class() ? Metaspace::chunk_manager_class() :
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1083 Metaspace::chunk_manager_metadata();
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1084
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1085 vsn->retire(cm);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1086 }
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1087
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1088 void VirtualSpaceNode::retire(ChunkManager* chunk_manager) {
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1089 for (int i = (int)MediumIndex; i >= (int)ZeroIndex; --i) {
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1090 ChunkIndex index = (ChunkIndex)i;
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1091 size_t chunk_size = chunk_manager->free_chunks(index)->size();
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1092
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1093 while (free_words_in_vs() >= chunk_size) {
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1094 DEBUG_ONLY(verify_container_count();)
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1095 Metachunk* chunk = get_chunk_vs(chunk_size);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1096 assert(chunk != NULL, "allocation should have been successful");
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1097
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1098 chunk_manager->return_chunks(index, chunk);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1099 chunk_manager->inc_free_chunks_total(chunk_size);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1100 DEBUG_ONLY(verify_container_count();)
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1101 }
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1102 }
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1103 assert(free_words_in_vs() == 0, "should be empty now");
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1104 }
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1105
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1106 VirtualSpaceList::VirtualSpaceList(size_t word_size) :
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1107 _is_class(false),
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1108 _virtual_space_list(NULL),
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1109 _current_virtual_space(NULL),
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1110 _reserved_words(0),
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1111 _committed_words(0),
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1112 _virtual_space_count(0) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1113 MutexLockerEx cl(SpaceManager::expand_lock(),
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1114 Mutex::_no_safepoint_check_flag);
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1115 create_new_virtual_space(word_size);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1116 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1117
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1118 VirtualSpaceList::VirtualSpaceList(ReservedSpace rs) :
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1119 _is_class(true),
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1120 _virtual_space_list(NULL),
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1121 _current_virtual_space(NULL),
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1122 _reserved_words(0),
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1123 _committed_words(0),
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1124 _virtual_space_count(0) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1125 MutexLockerEx cl(SpaceManager::expand_lock(),
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1126 Mutex::_no_safepoint_check_flag);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1127 VirtualSpaceNode* class_entry = new VirtualSpaceNode(rs);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1128 bool succeeded = class_entry->initialize();
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1129 if (succeeded) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1130 link_vs(class_entry);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1131 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1132 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1133
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1134 size_t VirtualSpaceList::free_bytes() {
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1135 return virtual_space_list()->free_words_in_vs() * BytesPerWord;
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1136 }
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1137
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1138 // Allocate another meta virtual space and add it to the list.
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1139 bool VirtualSpaceList::create_new_virtual_space(size_t vs_word_size) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1140 assert_lock_strong(SpaceManager::expand_lock());
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1141
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1142 if (is_class()) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1143 assert(false, "We currently don't support more than one VirtualSpace for"
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1144 " the compressed class space. The initialization of the"
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1145 " CCS uses another code path and should not hit this path.");
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1146 return false;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1147 }
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1148
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1149 if (vs_word_size == 0) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1150 assert(false, "vs_word_size should always be at least _reserve_alignment large.");
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1151 return false;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1152 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1153
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1154 // Reserve the space
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1155 size_t vs_byte_size = vs_word_size * BytesPerWord;
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1156 assert_is_size_aligned(vs_byte_size, Metaspace::reserve_alignment());
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1157
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1158 // Allocate the meta virtual space and initialize it.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1159 VirtualSpaceNode* new_entry = new VirtualSpaceNode(vs_byte_size);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1160 if (!new_entry->initialize()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1161 delete new_entry;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1162 return false;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1163 } else {
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1164 assert(new_entry->reserved_words() == vs_word_size,
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1165 "Reserved memory size differs from requested memory size");
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1166 link_vs(new_entry);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1167 return true;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1168 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1169 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1170
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1171 void VirtualSpaceList::link_vs(VirtualSpaceNode* new_entry) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1172 if (virtual_space_list() == NULL) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1173 set_virtual_space_list(new_entry);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1174 } else {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1175 current_virtual_space()->set_next(new_entry);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1176 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1177 set_current_virtual_space(new_entry);
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1178 inc_reserved_words(new_entry->reserved_words());
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1179 inc_committed_words(new_entry->committed_words());
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1180 inc_virtual_space_count();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1181 #ifdef ASSERT
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1182 new_entry->mangle();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1183 #endif
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1184 if (TraceMetavirtualspaceAllocation && Verbose) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1185 VirtualSpaceNode* vsl = current_virtual_space();
12240
8c5e6482cbfc 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 12239
diff changeset
1186 vsl->print_on(gclog_or_tty);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1187 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1188 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1189
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1190 bool VirtualSpaceList::expand_node_by(VirtualSpaceNode* node,
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1191 size_t min_words,
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1192 size_t preferred_words) {
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1193 size_t before = node->committed_words();
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1194
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1195 bool result = node->expand_by(min_words, preferred_words);
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1196
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1197 size_t after = node->committed_words();
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1198
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1199 // after and before can be the same if the memory was pre-committed.
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1200 assert(after >= before, "Inconsistency");
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1201 inc_committed_words(after - before);
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1202
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1203 return result;
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1204 }
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
1205
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1206 bool VirtualSpaceList::expand_by(size_t min_words, size_t preferred_words) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1207 assert_is_size_aligned(min_words, Metaspace::commit_alignment_words());
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1208 assert_is_size_aligned(preferred_words, Metaspace::commit_alignment_words());
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1209 assert(min_words <= preferred_words, "Invalid arguments");
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1210
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1211 if (!MetaspaceGC::can_expand(min_words, this->is_class())) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1212 return false;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1213 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1214
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1215 size_t allowed_expansion_words = MetaspaceGC::allowed_expansion();
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1216 if (allowed_expansion_words < min_words) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1217 return false;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1218 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1219
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1220 size_t max_expansion_words = MIN2(preferred_words, allowed_expansion_words);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1221
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1222 // Commit more memory from the the current virtual space.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1223 bool vs_expanded = expand_node_by(current_virtual_space(),
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1224 min_words,
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1225 max_expansion_words);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1226 if (vs_expanded) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1227 return true;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1228 }
12979
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1229 retire_current_virtual_space();
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1230
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1231 // Get another virtual space.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1232 size_t grow_vs_words = MAX2((size_t)VirtualSpaceSize, preferred_words);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1233 grow_vs_words = align_size_up(grow_vs_words, Metaspace::reserve_alignment_words());
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1234
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1235 if (create_new_virtual_space(grow_vs_words)) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1236 if (current_virtual_space()->is_pre_committed()) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1237 // The memory was pre-committed, so we are done here.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1238 assert(min_words <= current_virtual_space()->committed_words(),
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1239 "The new VirtualSpace was pre-committed, so it"
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1240 "should be large enough to fit the alloc request.");
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1241 return true;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1242 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1243
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1244 return expand_node_by(current_virtual_space(),
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1245 min_words,
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1246 max_expansion_words);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1247 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1248
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1249 return false;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1250 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1251
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1252 Metachunk* VirtualSpaceList::get_new_chunk(size_t word_size,
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1253 size_t grow_chunks_by_words,
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1254 size_t medium_chunk_bunch) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1255
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
1256 // Allocate a chunk out of the current virtual space.
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
1257 Metachunk* next = current_virtual_space()->get_chunk_vs(grow_chunks_by_words);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1258
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1259 if (next != NULL) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1260 return next;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1261 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1262
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1263 // The expand amount is currently only determined by the requested sizes
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1264 // and not how much committed memory is left in the current virtual space.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1265
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1266 size_t min_word_size = align_size_up(grow_chunks_by_words, Metaspace::commit_alignment_words());
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1267 size_t preferred_word_size = align_size_up(medium_chunk_bunch, Metaspace::commit_alignment_words());
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1268 if (min_word_size >= preferred_word_size) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1269 // Can happen when humongous chunks are allocated.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1270 preferred_word_size = min_word_size;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1271 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1272
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1273 bool expanded = expand_by(min_word_size, preferred_word_size);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1274 if (expanded) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1275 next = current_virtual_space()->get_chunk_vs(grow_chunks_by_words);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1276 assert(next != NULL, "The allocation was expected to succeed after the expansion");
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1277 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1278
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1279 return next;
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1280 }
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1281
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1282 void VirtualSpaceList::print_on(outputStream* st) const {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1283 if (TraceMetadataChunkAllocation && Verbose) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1284 VirtualSpaceListIterator iter(virtual_space_list());
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1285 while (iter.repeat()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1286 VirtualSpaceNode* node = iter.get_next();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1287 node->print_on(st);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1288 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1289 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1290 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1291
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1292 // MetaspaceGC methods
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1293
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1294 // VM_CollectForMetadataAllocation is the vm operation used to GC.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1295 // Within the VM operation after the GC the attempt to allocate the metadata
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1296 // should succeed. If the GC did not free enough space for the metaspace
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1297 // allocation, the HWM is increased so that another virtualspace will be
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1298 // allocated for the metadata. With perm gen the increase in the perm
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1299 // gen had bounds, MinMetaspaceExpansion and MaxMetaspaceExpansion. The
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1300 // metaspace policy uses those as the small and large steps for the HWM.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1301 //
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1302 // After the GC the compute_new_size() for MetaspaceGC is called to
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1303 // resize the capacity of the metaspaces. The current implementation
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1304 // is based on the flags MinMetaspaceFreeRatio and MaxMetaspaceFreeRatio used
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1305 // to resize the Java heap by some GC's. New flags can be implemented
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1306 // if really needed. MinMetaspaceFreeRatio is used to calculate how much
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1307 // free space is desirable in the metaspace capacity to decide how much
8040
a83cd101fd62 8005452: NPG: Create new flags for Metaspace resizing policy
jmasa
parents: 8007
diff changeset
1308 // to increase the HWM. MaxMetaspaceFreeRatio is used to decide how much
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1309 // free space is desirable in the metaspace capacity before decreasing
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1310 // the HWM.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1311
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1312 // Calculate the amount to increase the high water mark (HWM).
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1313 // Increase by a minimum amount (MinMetaspaceExpansion) so that
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1314 // another expansion is not requested too soon. If that is not
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1315 // enough to satisfy the allocation, increase by MaxMetaspaceExpansion.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1316 // If that is still not enough, expand by the size of the allocation
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1317 // plus some.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1318 size_t MetaspaceGC::delta_capacity_until_GC(size_t bytes) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1319 size_t min_delta = MinMetaspaceExpansion;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1320 size_t max_delta = MaxMetaspaceExpansion;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1321 size_t delta = align_size_up(bytes, Metaspace::commit_alignment());
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1322
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1323 if (delta <= min_delta) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1324 delta = min_delta;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1325 } else if (delta <= max_delta) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1326 // Don't want to hit the high water mark on the next
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1327 // allocation so make the delta greater than just enough
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1328 // for this allocation.
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1329 delta = max_delta;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1330 } else {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1331 // This allocation is large but the next ones are probably not
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1332 // so increase by the minimum.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1333 delta = delta + min_delta;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1334 }
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1335
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1336 assert_is_size_aligned(delta, Metaspace::commit_alignment());
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1337
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1338 return delta;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1339 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1340
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1341 size_t MetaspaceGC::capacity_until_GC() {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1342 size_t value = (size_t)OrderAccess::load_ptr_acquire(&_capacity_until_GC);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1343 assert(value >= MetaspaceSize, "Not initialied properly?");
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1344 return value;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1345 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1346
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1347 size_t MetaspaceGC::inc_capacity_until_GC(size_t v) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1348 assert_is_size_aligned(v, Metaspace::commit_alignment());
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1349
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1350 return (size_t)Atomic::add_ptr(v, &_capacity_until_GC);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1351 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1352
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1353 size_t MetaspaceGC::dec_capacity_until_GC(size_t v) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1354 assert_is_size_aligned(v, Metaspace::commit_alignment());
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1355
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1356 return (size_t)Atomic::add_ptr(-(intptr_t)v, &_capacity_until_GC);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1357 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1358
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1359 bool MetaspaceGC::can_expand(size_t word_size, bool is_class) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1360 // Check if the compressed class space is full.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1361 if (is_class && Metaspace::using_class_space()) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1362 size_t class_committed = MetaspaceAux::committed_bytes(Metaspace::ClassType);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1363 if (class_committed + word_size * BytesPerWord > CompressedClassSpaceSize) {
11064
de2d15ce3d4a 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 10376
diff changeset
1364 return false;
de2d15ce3d4a 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 10376
diff changeset
1365 }
8790
7f0cb32dd233 8004241: NPG: Metaspace occupies more memory than specified by -XX:MaxMetaspaceSize option
mgerdin
parents: 8786
diff changeset
1366 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1367
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1368 // Check if the user has imposed a limit on the metaspace memory.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1369 size_t committed_bytes = MetaspaceAux::committed_bytes();
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1370 if (committed_bytes + word_size * BytesPerWord > MaxMetaspaceSize) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1371 return false;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1372 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1373
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1374 return true;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1375 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1376
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1377 size_t MetaspaceGC::allowed_expansion() {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1378 size_t committed_bytes = MetaspaceAux::committed_bytes();
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1379
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1380 size_t left_until_max = MaxMetaspaceSize - committed_bytes;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1381
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1382 // Always grant expansion if we are initiating the JVM,
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1383 // or if the GC_locker is preventing GCs.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1384 if (!is_init_completed() || GC_locker::is_active_and_needs_gc()) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1385 return left_until_max / BytesPerWord;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1386 }
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1387
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1388 size_t capacity_until_gc = capacity_until_GC();
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1389
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1390 if (capacity_until_gc <= committed_bytes) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1391 return 0;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1392 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1393
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1394 size_t left_until_GC = capacity_until_gc - committed_bytes;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1395 size_t left_to_commit = MIN2(left_until_GC, left_until_max);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1396
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1397 return left_to_commit / BytesPerWord;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1398 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1399
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1400 void MetaspaceGC::compute_new_size() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1401 assert(_shrink_factor <= 100, "invalid shrink factor");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1402 uint current_shrink_factor = _shrink_factor;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1403 _shrink_factor = 0;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1404
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1405 const size_t used_after_gc = MetaspaceAux::allocated_capacity_bytes();
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1406 const size_t capacity_until_GC = MetaspaceGC::capacity_until_GC();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1407
8040
a83cd101fd62 8005452: NPG: Create new flags for Metaspace resizing policy
jmasa
parents: 8007
diff changeset
1408 const double minimum_free_percentage = MinMetaspaceFreeRatio / 100.0;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1409 const double maximum_used_percentage = 1.0 - minimum_free_percentage;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1410
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1411 const double min_tmp = used_after_gc / maximum_used_percentage;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1412 size_t minimum_desired_capacity =
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1413 (size_t)MIN2(min_tmp, double(max_uintx));
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1414 // Don't shrink less than the initial generation size
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1415 minimum_desired_capacity = MAX2(minimum_desired_capacity,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1416 MetaspaceSize);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1417
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1418 if (PrintGCDetails && Verbose) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1419 gclog_or_tty->print_cr("\nMetaspaceGC::compute_new_size: ");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1420 gclog_or_tty->print_cr(" "
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1421 " minimum_free_percentage: %6.2f"
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1422 " maximum_used_percentage: %6.2f",
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1423 minimum_free_percentage,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1424 maximum_used_percentage);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1425 gclog_or_tty->print_cr(" "
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1426 " used_after_gc : %6.1fKB",
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1427 used_after_gc / (double) K);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1428 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1429
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1430
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1431 size_t shrink_bytes = 0;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1432 if (capacity_until_GC < minimum_desired_capacity) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1433 // If we have less capacity below the metaspace HWM, then
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1434 // increment the HWM.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1435 size_t expand_bytes = minimum_desired_capacity - capacity_until_GC;
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1436 expand_bytes = align_size_up(expand_bytes, Metaspace::commit_alignment());
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1437 // Don't expand unless it's significant
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1438 if (expand_bytes >= MinMetaspaceExpansion) {
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1439 MetaspaceGC::inc_capacity_until_GC(expand_bytes);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1440 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1441 if (PrintGCDetails && Verbose) {
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1442 size_t new_capacity_until_GC = capacity_until_GC;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1443 gclog_or_tty->print_cr(" expanding:"
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1444 " minimum_desired_capacity: %6.1fKB"
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1445 " expand_bytes: %6.1fKB"
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1446 " MinMetaspaceExpansion: %6.1fKB"
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1447 " new metaspace HWM: %6.1fKB",
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1448 minimum_desired_capacity / (double) K,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1449 expand_bytes / (double) K,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1450 MinMetaspaceExpansion / (double) K,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1451 new_capacity_until_GC / (double) K);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1452 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1453 return;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1454 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1455
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1456 // No expansion, now see if we want to shrink
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1457 // We would never want to shrink more than this
14255
e4e941b83466 8031779: Assert in MetaspaceGC is always true
ehelin
parents: 14237
diff changeset
1458 assert(capacity_until_GC >= minimum_desired_capacity,
e4e941b83466 8031779: Assert in MetaspaceGC is always true
ehelin
parents: 14237
diff changeset
1459 err_msg(SIZE_FORMAT " >= " SIZE_FORMAT,
e4e941b83466 8031779: Assert in MetaspaceGC is always true
ehelin
parents: 14237
diff changeset
1460 capacity_until_GC, minimum_desired_capacity));
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1461 size_t max_shrink_bytes = capacity_until_GC - minimum_desired_capacity;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1462
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1463 // Should shrinking be considered?
8040
a83cd101fd62 8005452: NPG: Create new flags for Metaspace resizing policy
jmasa
parents: 8007
diff changeset
1464 if (MaxMetaspaceFreeRatio < 100) {
a83cd101fd62 8005452: NPG: Create new flags for Metaspace resizing policy
jmasa
parents: 8007
diff changeset
1465 const double maximum_free_percentage = MaxMetaspaceFreeRatio / 100.0;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1466 const double minimum_used_percentage = 1.0 - maximum_free_percentage;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1467 const double max_tmp = used_after_gc / minimum_used_percentage;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1468 size_t maximum_desired_capacity = (size_t)MIN2(max_tmp, double(max_uintx));
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1469 maximum_desired_capacity = MAX2(maximum_desired_capacity,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1470 MetaspaceSize);
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1471 if (PrintGCDetails && Verbose) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1472 gclog_or_tty->print_cr(" "
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1473 " maximum_free_percentage: %6.2f"
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1474 " minimum_used_percentage: %6.2f",
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1475 maximum_free_percentage,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1476 minimum_used_percentage);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1477 gclog_or_tty->print_cr(" "
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1478 " minimum_desired_capacity: %6.1fKB"
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1479 " maximum_desired_capacity: %6.1fKB",
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1480 minimum_desired_capacity / (double) K,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1481 maximum_desired_capacity / (double) K);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1482 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1483
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1484 assert(minimum_desired_capacity <= maximum_desired_capacity,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1485 "sanity check");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1486
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1487 if (capacity_until_GC > maximum_desired_capacity) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1488 // Capacity too large, compute shrinking size
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1489 shrink_bytes = capacity_until_GC - maximum_desired_capacity;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1490 // We don't want shrink all the way back to initSize if people call
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1491 // System.gc(), because some programs do that between "phases" and then
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1492 // we'd just have to grow the heap up again for the next phase. So we
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1493 // damp the shrinking: 0% on the first call, 10% on the second call, 40%
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1494 // on the third call, and 100% by the fourth call. But if we recompute
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1495 // size without shrinking, it goes back to 0%.
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1496 shrink_bytes = shrink_bytes / 100 * current_shrink_factor;
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1497
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1498 shrink_bytes = align_size_down(shrink_bytes, Metaspace::commit_alignment());
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1499
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1500 assert(shrink_bytes <= max_shrink_bytes,
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1501 err_msg("invalid shrink size " SIZE_FORMAT " not <= " SIZE_FORMAT,
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1502 shrink_bytes, max_shrink_bytes));
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1503 if (current_shrink_factor == 0) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1504 _shrink_factor = 10;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1505 } else {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1506 _shrink_factor = MIN2(current_shrink_factor * 4, (uint) 100);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1507 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1508 if (PrintGCDetails && Verbose) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1509 gclog_or_tty->print_cr(" "
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1510 " shrinking:"
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1511 " initSize: %.1fK"
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1512 " maximum_desired_capacity: %.1fK",
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1513 MetaspaceSize / (double) K,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1514 maximum_desired_capacity / (double) K);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1515 gclog_or_tty->print_cr(" "
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1516 " shrink_bytes: %.1fK"
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1517 " current_shrink_factor: %d"
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1518 " new shrink factor: %d"
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1519 " MinMetaspaceExpansion: %.1fK",
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1520 shrink_bytes / (double) K,
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1521 current_shrink_factor,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1522 _shrink_factor,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1523 MinMetaspaceExpansion / (double) K);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1524 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1525 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1526 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1527
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1528 // Don't shrink unless it's significant
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1529 if (shrink_bytes >= MinMetaspaceExpansion &&
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1530 ((capacity_until_GC - shrink_bytes) >= MetaspaceSize)) {
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1531 MetaspaceGC::dec_capacity_until_GC(shrink_bytes);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1532 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1533 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1534
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1535 // Metadebug methods
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1536
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1537 void Metadebug::init_allocation_fail_alot_count() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1538 if (MetadataAllocationFailALot) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1539 _allocation_fail_alot_count =
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1540 1+(long)((double)MetadataAllocationFailALotInterval*os::random()/(max_jint+1.0));
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1541 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1542 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1543
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1544 #ifdef ASSERT
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1545 bool Metadebug::test_metadata_failure() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1546 if (MetadataAllocationFailALot &&
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1547 Threads::is_vm_complete()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1548 if (_allocation_fail_alot_count > 0) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1549 _allocation_fail_alot_count--;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1550 } else {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1551 if (TraceMetadataChunkAllocation && Verbose) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1552 gclog_or_tty->print_cr("Metadata allocation failing for "
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1553 "MetadataAllocationFailALot");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1554 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1555 init_allocation_fail_alot_count();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1556 return true;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1557 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1558 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1559 return false;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1560 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1561 #endif
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1562
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1563 // ChunkManager methods
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1564
12235
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
1565 size_t ChunkManager::free_chunks_total_words() {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1566 return _free_chunks_total;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1567 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1568
12235
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
1569 size_t ChunkManager::free_chunks_total_bytes() {
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
1570 return free_chunks_total_words() * BytesPerWord;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1571 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1572
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1573 size_t ChunkManager::free_chunks_count() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1574 #ifdef ASSERT
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1575 if (!UseConcMarkSweepGC && !SpaceManager::expand_lock()->is_locked()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1576 MutexLockerEx cl(SpaceManager::expand_lock(),
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1577 Mutex::_no_safepoint_check_flag);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1578 // This lock is only needed in debug because the verification
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1579 // of the _free_chunks_totals walks the list of free chunks
6969
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
1580 slow_locked_verify_free_chunks_count();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1581 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1582 #endif
6969
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
1583 return _free_chunks_count;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1584 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1585
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1586 void ChunkManager::locked_verify_free_chunks_total() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1587 assert_lock_strong(SpaceManager::expand_lock());
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1588 assert(sum_free_chunks() == _free_chunks_total,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1589 err_msg("_free_chunks_total " SIZE_FORMAT " is not the"
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1590 " same as sum " SIZE_FORMAT, _free_chunks_total,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1591 sum_free_chunks()));
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1592 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1593
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1594 void ChunkManager::verify_free_chunks_total() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1595 MutexLockerEx cl(SpaceManager::expand_lock(),
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1596 Mutex::_no_safepoint_check_flag);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1597 locked_verify_free_chunks_total();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1598 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1599
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1600 void ChunkManager::locked_verify_free_chunks_count() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1601 assert_lock_strong(SpaceManager::expand_lock());
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1602 assert(sum_free_chunks_count() == _free_chunks_count,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1603 err_msg("_free_chunks_count " SIZE_FORMAT " is not the"
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1604 " same as sum " SIZE_FORMAT, _free_chunks_count,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1605 sum_free_chunks_count()));
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1606 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1607
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1608 void ChunkManager::verify_free_chunks_count() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1609 #ifdef ASSERT
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1610 MutexLockerEx cl(SpaceManager::expand_lock(),
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1611 Mutex::_no_safepoint_check_flag);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1612 locked_verify_free_chunks_count();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1613 #endif
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1614 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1615
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1616 void ChunkManager::verify() {
6969
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
1617 MutexLockerEx cl(SpaceManager::expand_lock(),
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
1618 Mutex::_no_safepoint_check_flag);
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
1619 locked_verify();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1620 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1621
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1622 void ChunkManager::locked_verify() {
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1623 locked_verify_free_chunks_count();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1624 locked_verify_free_chunks_total();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1625 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1626
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1627 void ChunkManager::locked_print_free_chunks(outputStream* st) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1628 assert_lock_strong(SpaceManager::expand_lock());
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1629 st->print_cr("Free chunk total " SIZE_FORMAT " count " SIZE_FORMAT,
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1630 _free_chunks_total, _free_chunks_count);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1631 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1632
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1633 void ChunkManager::locked_print_sum_free_chunks(outputStream* st) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1634 assert_lock_strong(SpaceManager::expand_lock());
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1635 st->print_cr("Sum free chunk total " SIZE_FORMAT " count " SIZE_FORMAT,
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1636 sum_free_chunks(), sum_free_chunks_count());
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1637 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1638 ChunkList* ChunkManager::free_chunks(ChunkIndex index) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1639 return &_free_chunks[index];
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1640 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1641
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1642 // These methods that sum the free chunk lists are used in printing
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1643 // methods that are used in product builds.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1644 size_t ChunkManager::sum_free_chunks() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1645 assert_lock_strong(SpaceManager::expand_lock());
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1646 size_t result = 0;
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1647 for (ChunkIndex i = ZeroIndex; i < NumberOfFreeLists; i = next_chunk_index(i)) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1648 ChunkList* list = free_chunks(i);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1649
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1650 if (list == NULL) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1651 continue;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1652 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1653
10101
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
1654 result = result + list->count() * list->size();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1655 }
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1656 result = result + humongous_dictionary()->total_size();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1657 return result;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1658 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1659
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1660 size_t ChunkManager::sum_free_chunks_count() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1661 assert_lock_strong(SpaceManager::expand_lock());
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1662 size_t count = 0;
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1663 for (ChunkIndex i = ZeroIndex; i < NumberOfFreeLists; i = next_chunk_index(i)) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1664 ChunkList* list = free_chunks(i);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1665 if (list == NULL) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1666 continue;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1667 }
10101
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
1668 count = count + list->count();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1669 }
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1670 count = count + humongous_dictionary()->total_free_blocks();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1671 return count;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1672 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1673
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1674 ChunkList* ChunkManager::find_free_chunks_list(size_t word_size) {
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1675 ChunkIndex index = list_index(word_size);
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1676 assert(index < HumongousIndex, "No humongous list");
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1677 return free_chunks(index);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1678 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1679
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1680 Metachunk* ChunkManager::free_chunks_get(size_t word_size) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1681 assert_lock_strong(SpaceManager::expand_lock());
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1682
6969
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
1683 slow_locked_verify();
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1684
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1685 Metachunk* chunk = NULL;
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1686 if (list_index(word_size) != HumongousIndex) {
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1687 ChunkList* free_list = find_free_chunks_list(word_size);
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1688 assert(free_list != NULL, "Sanity check");
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1689
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1690 chunk = free_list->head();
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1691
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1692 if (chunk == NULL) {
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1693 return NULL;
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1694 }
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1695
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1696 // Remove the chunk as the head of the list.
10101
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
1697 free_list->remove_chunk(chunk);
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1698
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1699 if (TraceMetadataChunkAllocation && Verbose) {
12240
8c5e6482cbfc 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 12239
diff changeset
1700 gclog_or_tty->print_cr("ChunkManager::free_chunks_get: free_list "
8c5e6482cbfc 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 12239
diff changeset
1701 PTR_FORMAT " head " PTR_FORMAT " size " SIZE_FORMAT,
8c5e6482cbfc 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 12239
diff changeset
1702 free_list, chunk, chunk->word_size());
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1703 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1704 } else {
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1705 chunk = humongous_dictionary()->get_chunk(
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1706 word_size,
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1707 FreeBlockDictionary<Metachunk>::atLeast);
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1708
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1709 if (chunk == NULL) {
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1710 return NULL;
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1711 }
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1712
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1713 if (TraceMetadataHumongousAllocation) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1714 size_t waste = chunk->word_size() - word_size;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1715 gclog_or_tty->print_cr("Free list allocate humongous chunk size "
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1716 SIZE_FORMAT " for requested size " SIZE_FORMAT
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1717 " waste " SIZE_FORMAT,
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1718 chunk->word_size(), word_size, waste);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1719 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1720 }
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1721
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1722 // Chunk is being removed from the chunks free list.
12902
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
1723 dec_free_chunks_total(chunk->word_size());
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1724
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1725 // Remove it from the links to this freelist
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1726 chunk->set_next(NULL);
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1727 chunk->set_prev(NULL);
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1728 #ifdef ASSERT
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1729 // Chunk is no longer on any freelist. Setting to false make container_count_slow()
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1730 // work.
12902
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
1731 chunk->set_is_tagged_free(false);
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
1732 #endif
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
1733 chunk->container()->inc_container_count();
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
1734
6969
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
1735 slow_locked_verify();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1736 return chunk;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1737 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1738
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1739 Metachunk* ChunkManager::chunk_freelist_allocate(size_t word_size) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1740 assert_lock_strong(SpaceManager::expand_lock());
6969
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
1741 slow_locked_verify();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1742
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1743 // Take from the beginning of the list
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1744 Metachunk* chunk = free_chunks_get(word_size);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1745 if (chunk == NULL) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1746 return NULL;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1747 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1748
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1749 assert((word_size <= chunk->word_size()) ||
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1750 list_index(chunk->word_size() == HumongousIndex),
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1751 "Non-humongous variable sized chunk");
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1752 if (TraceMetadataChunkAllocation) {
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1753 size_t list_count;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1754 if (list_index(word_size) < HumongousIndex) {
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1755 ChunkList* list = find_free_chunks_list(word_size);
10101
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
1756 list_count = list->count();
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1757 } else {
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1758 list_count = humongous_dictionary()->total_count();
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1759 }
12240
8c5e6482cbfc 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 12239
diff changeset
1760 gclog_or_tty->print("ChunkManager::chunk_freelist_allocate: " PTR_FORMAT " chunk "
8c5e6482cbfc 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 12239
diff changeset
1761 PTR_FORMAT " size " SIZE_FORMAT " count " SIZE_FORMAT " ",
8c5e6482cbfc 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 12239
diff changeset
1762 this, chunk, chunk->word_size(), list_count);
8c5e6482cbfc 8024752: Log TraceMetadata* output to gclog_or_tty instead of tty
stefank
parents: 12239
diff changeset
1763 locked_print_free_chunks(gclog_or_tty);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1764 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1765
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1766 return chunk;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1767 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1768
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
1769 void ChunkManager::print_on(outputStream* out) const {
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1770 if (PrintFLSStatistics != 0) {
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
1771 const_cast<ChunkManager *>(this)->humongous_dictionary()->report_statistics();
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1772 }
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1773 }
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1774
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1775 // SpaceManager methods
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1776
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1777 void SpaceManager::get_initial_chunk_sizes(Metaspace::MetaspaceType type,
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1778 size_t* chunk_word_size,
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1779 size_t* class_chunk_word_size) {
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1780 switch (type) {
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1781 case Metaspace::BootMetaspaceType:
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1782 *chunk_word_size = Metaspace::first_chunk_word_size();
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1783 *class_chunk_word_size = Metaspace::first_class_chunk_word_size();
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1784 break;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1785 case Metaspace::ROMetaspaceType:
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1786 *chunk_word_size = SharedReadOnlySize / wordSize;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1787 *class_chunk_word_size = ClassSpecializedChunk;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1788 break;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1789 case Metaspace::ReadWriteMetaspaceType:
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1790 *chunk_word_size = SharedReadWriteSize / wordSize;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1791 *class_chunk_word_size = ClassSpecializedChunk;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1792 break;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1793 case Metaspace::AnonymousMetaspaceType:
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1794 case Metaspace::ReflectionMetaspaceType:
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1795 *chunk_word_size = SpecializedChunk;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1796 *class_chunk_word_size = ClassSpecializedChunk;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1797 break;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1798 default:
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1799 *chunk_word_size = SmallChunk;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1800 *class_chunk_word_size = ClassSmallChunk;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1801 break;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1802 }
8007
d9058e388631 8007257: NPG: metaspace.cpp: Incorrect arguments in calls to err_msg
mikael
parents: 7447
diff changeset
1803 assert(*chunk_word_size != 0 && *class_chunk_word_size != 0,
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1804 err_msg("Initial chunks sizes bad: data " SIZE_FORMAT
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1805 " class " SIZE_FORMAT,
8007
d9058e388631 8007257: NPG: metaspace.cpp: Incorrect arguments in calls to err_msg
mikael
parents: 7447
diff changeset
1806 *chunk_word_size, *class_chunk_word_size));
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1807 }
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1808
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1809 size_t SpaceManager::sum_free_in_chunks_in_use() const {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1810 MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1811 size_t free = 0;
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1812 for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1813 Metachunk* chunk = chunks_in_use(i);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1814 while (chunk != NULL) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1815 free += chunk->free_word_size();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1816 chunk = chunk->next();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1817 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1818 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1819 return free;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1820 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1821
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1822 size_t SpaceManager::sum_waste_in_chunks_in_use() const {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1823 MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1824 size_t result = 0;
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1825 for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1826 result += sum_waste_in_chunks_in_use(i);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1827 }
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1828
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1829 return result;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1830 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1831
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1832 size_t SpaceManager::sum_waste_in_chunks_in_use(ChunkIndex index) const {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1833 size_t result = 0;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1834 Metachunk* chunk = chunks_in_use(index);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1835 // Count the free space in all the chunk but not the
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1836 // current chunk from which allocations are still being done.
11064
de2d15ce3d4a 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 10376
diff changeset
1837 while (chunk != NULL) {
de2d15ce3d4a 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 10376
diff changeset
1838 if (chunk != current_chunk()) {
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1839 result += chunk->free_word_size();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1840 }
11064
de2d15ce3d4a 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 10376
diff changeset
1841 chunk = chunk->next();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1842 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1843 return result;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1844 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1845
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1846 size_t SpaceManager::sum_capacity_in_chunks_in_use() const {
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1847 // For CMS use "allocated_chunks_words()" which does not need the
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1848 // Metaspace lock. For the other collectors sum over the
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1849 // lists. Use both methods as a check that "allocated_chunks_words()"
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1850 // is correct. That is, sum_capacity_in_chunks() is too expensive
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1851 // to use in the product and allocated_chunks_words() should be used
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1852 // but allow for checking that allocated_chunks_words() returns the same
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1853 // value as sum_capacity_in_chunks_in_use() which is the definitive
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1854 // answer.
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1855 if (UseConcMarkSweepGC) {
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1856 return allocated_chunks_words();
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1857 } else {
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1858 MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1859 size_t sum = 0;
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1860 for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1861 Metachunk* chunk = chunks_in_use(i);
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1862 while (chunk != NULL) {
12902
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
1863 sum += chunk->word_size();
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1864 chunk = chunk->next();
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1865 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1866 }
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
1867 return sum;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1868 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1869 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1870
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1871 size_t SpaceManager::sum_count_in_chunks_in_use() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1872 size_t count = 0;
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1873 for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1874 count = count + sum_count_in_chunks_in_use(i);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1875 }
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1876
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1877 return count;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1878 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1879
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1880 size_t SpaceManager::sum_count_in_chunks_in_use(ChunkIndex i) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1881 size_t count = 0;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1882 Metachunk* chunk = chunks_in_use(i);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1883 while (chunk != NULL) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1884 count++;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1885 chunk = chunk->next();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1886 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1887 return count;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1888 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1889
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1890
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1891 size_t SpaceManager::sum_used_in_chunks_in_use() const {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1892 MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1893 size_t used = 0;
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1894 for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1895 Metachunk* chunk = chunks_in_use(i);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1896 while (chunk != NULL) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1897 used += chunk->used_word_size();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1898 chunk = chunk->next();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1899 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1900 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1901 return used;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1902 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1903
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1904 void SpaceManager::locked_print_chunks_in_use_on(outputStream* st) const {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1905
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1906 for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1907 Metachunk* chunk = chunks_in_use(i);
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1908 st->print("SpaceManager: %s " PTR_FORMAT,
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1909 chunk_size_name(i), chunk);
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1910 if (chunk != NULL) {
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1911 st->print_cr(" free " SIZE_FORMAT,
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1912 chunk->free_word_size());
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1913 } else {
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1914 st->print_cr("");
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1915 }
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1916 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1917
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
1918 chunk_manager()->locked_print_free_chunks(st);
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
1919 chunk_manager()->locked_print_sum_free_chunks(st);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1920 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1921
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1922 size_t SpaceManager::calc_chunk_size(size_t word_size) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1923
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1924 // Decide between a small chunk and a medium chunk. Up to
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1925 // _small_chunk_limit small chunks can be allocated but
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1926 // once a medium chunk has been allocated, no more small
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1927 // chunks will be allocated.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1928 size_t chunk_word_size;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1929 if (chunks_in_use(MediumIndex) == NULL &&
11064
de2d15ce3d4a 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 10376
diff changeset
1930 sum_count_in_chunks_in_use(SmallIndex) < _small_chunk_limit) {
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1931 chunk_word_size = (size_t) small_chunk_size();
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1932 if (word_size + Metachunk::overhead() > small_chunk_size()) {
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1933 chunk_word_size = medium_chunk_size();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1934 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1935 } else {
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1936 chunk_word_size = medium_chunk_size();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1937 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1938
12979
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1939 // Might still need a humongous chunk. Enforce
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1940 // humongous allocations sizes to be aligned up to
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1941 // the smallest chunk size.
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1942 size_t if_humongous_sized_chunk =
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1943 align_size_up(word_size + Metachunk::overhead(),
12979
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
1944 smallest_chunk_size());
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1945 chunk_word_size =
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1946 MAX2((size_t) chunk_word_size, if_humongous_sized_chunk);
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1947
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1948 assert(!SpaceManager::is_humongous(word_size) ||
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1949 chunk_word_size == if_humongous_sized_chunk,
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1950 err_msg("Size calculation is wrong, word_size " SIZE_FORMAT
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1951 " chunk_word_size " SIZE_FORMAT,
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1952 word_size, chunk_word_size));
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1953 if (TraceMetadataHumongousAllocation &&
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1954 SpaceManager::is_humongous(word_size)) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1955 gclog_or_tty->print_cr("Metadata humongous allocation:");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1956 gclog_or_tty->print_cr(" word_size " PTR_FORMAT, word_size);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1957 gclog_or_tty->print_cr(" chunk_word_size " PTR_FORMAT,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1958 chunk_word_size);
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1959 gclog_or_tty->print_cr(" chunk overhead " PTR_FORMAT,
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1960 Metachunk::overhead());
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1961 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1962 return chunk_word_size;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1963 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1964
12839
a6414751d537 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 12838
diff changeset
1965 void SpaceManager::track_metaspace_memory_usage() {
a6414751d537 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 12838
diff changeset
1966 if (is_init_completed()) {
a6414751d537 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 12838
diff changeset
1967 if (is_class()) {
a6414751d537 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 12838
diff changeset
1968 MemoryService::track_compressed_class_memory_usage();
a6414751d537 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 12838
diff changeset
1969 }
a6414751d537 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 12838
diff changeset
1970 MemoryService::track_metaspace_memory_usage();
a6414751d537 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 12838
diff changeset
1971 }
a6414751d537 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 12838
diff changeset
1972 }
a6414751d537 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 12838
diff changeset
1973
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
1974 MetaWord* SpaceManager::grow_and_allocate(size_t word_size) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1975 assert(vs_list()->current_virtual_space() != NULL,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1976 "Should have been set");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1977 assert(current_chunk() == NULL ||
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1978 current_chunk()->allocate(word_size) == NULL,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1979 "Don't need to expand");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1980 MutexLockerEx cl(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1981
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1982 if (TraceMetadataChunkAllocation && Verbose) {
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1983 size_t words_left = 0;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1984 size_t words_used = 0;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1985 if (current_chunk() != NULL) {
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1986 words_left = current_chunk()->free_word_size();
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1987 words_used = current_chunk()->used_word_size();
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1988 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1989 gclog_or_tty->print_cr("SpaceManager::grow_and_allocate for " SIZE_FORMAT
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1990 " words " SIZE_FORMAT " words used " SIZE_FORMAT
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1991 " words left",
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1992 word_size, words_used, words_left);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1993 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1994
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1995 // Get another chunk out of the virtual space
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1996 size_t grow_chunks_by_words = calc_chunk_size(word_size);
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
1997 Metachunk* next = get_new_chunk(word_size, grow_chunks_by_words);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
1998
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
1999 MetaWord* mem = NULL;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2000
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2001 // If a chunk was available, add it to the in-use chunk list
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2002 // and do an allocation from it.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2003 if (next != NULL) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2004 // Add to this manager's list of chunks in use.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2005 add_chunk(next, false);
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2006 mem = next->allocate(word_size);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2007 }
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2008
12839
a6414751d537 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 12838
diff changeset
2009 // Track metaspace memory usage statistic.
a6414751d537 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 12838
diff changeset
2010 track_metaspace_memory_usage();
a6414751d537 8025996: Track metaspace usage when metaspace is expanded
stefank
parents: 12838
diff changeset
2011
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2012 return mem;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2013 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2014
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2015 void SpaceManager::print_on(outputStream* st) const {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2016
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2017 for (ChunkIndex i = ZeroIndex;
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2018 i < NumberOfInUseLists ;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2019 i = next_chunk_index(i) ) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2020 st->print_cr(" chunks_in_use " PTR_FORMAT " chunk size " PTR_FORMAT,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2021 chunks_in_use(i),
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2022 chunks_in_use(i) == NULL ? 0 : chunks_in_use(i)->word_size());
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2023 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2024 st->print_cr(" waste: Small " SIZE_FORMAT " Medium " SIZE_FORMAT
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2025 " Humongous " SIZE_FORMAT,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2026 sum_waste_in_chunks_in_use(SmallIndex),
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2027 sum_waste_in_chunks_in_use(MediumIndex),
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2028 sum_waste_in_chunks_in_use(HumongousIndex));
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2029 // block free lists
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2030 if (block_freelists() != NULL) {
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2031 st->print_cr("total in block free lists " SIZE_FORMAT,
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2032 block_freelists()->total_size());
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2033 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2034 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2035
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2036 SpaceManager::SpaceManager(Metaspace::MetadataType mdtype,
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2037 Mutex* lock) :
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2038 _mdtype(mdtype),
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2039 _allocated_blocks_words(0),
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2040 _allocated_chunks_words(0),
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2041 _allocated_chunks_count(0),
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2042 _lock(lock)
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2043 {
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2044 initialize();
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2045 }
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2046
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2047 void SpaceManager::inc_size_metrics(size_t words) {
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2048 assert_lock_strong(SpaceManager::expand_lock());
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2049 // Total of allocated Metachunks and allocated Metachunks count
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2050 // for each SpaceManager
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2051 _allocated_chunks_words = _allocated_chunks_words + words;
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2052 _allocated_chunks_count++;
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2053 // Global total of capacity in allocated Metachunks
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2054 MetaspaceAux::inc_capacity(mdtype(), words);
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2055 // Global total of allocated Metablocks.
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2056 // used_words_slow() includes the overhead in each
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2057 // Metachunk so include it in the used when the
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2058 // Metachunk is first added (so only added once per
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2059 // Metachunk).
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2060 MetaspaceAux::inc_used(mdtype(), Metachunk::overhead());
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2061 }
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2062
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2063 void SpaceManager::inc_used_metrics(size_t words) {
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2064 // Add to the per SpaceManager total
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2065 Atomic::add_ptr(words, &_allocated_blocks_words);
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2066 // Add to the global total
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2067 MetaspaceAux::inc_used(mdtype(), words);
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2068 }
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2069
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2070 void SpaceManager::dec_total_from_size_metrics() {
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2071 MetaspaceAux::dec_capacity(mdtype(), allocated_chunks_words());
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2072 MetaspaceAux::dec_used(mdtype(), allocated_blocks_words());
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2073 // Also deduct the overhead per Metachunk
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2074 MetaspaceAux::dec_used(mdtype(), allocated_chunks_count() * Metachunk::overhead());
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2075 }
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2076
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2077 void SpaceManager::initialize() {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2078 Metadebug::init_allocation_fail_alot_count();
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2079 for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2080 _chunks_in_use[i] = NULL;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2081 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2082 _current_chunk = NULL;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2083 if (TraceMetadataChunkAllocation && Verbose) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2084 gclog_or_tty->print_cr("SpaceManager(): " PTR_FORMAT, this);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2085 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2086 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2087
10101
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
2088 void ChunkManager::return_chunks(ChunkIndex index, Metachunk* chunks) {
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
2089 if (chunks == NULL) {
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
2090 return;
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
2091 }
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
2092 ChunkList* list = free_chunks(index);
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
2093 assert(list->size() == chunks->word_size(), "Mismatch in chunk sizes");
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
2094 assert_lock_strong(SpaceManager::expand_lock());
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
2095 Metachunk* cur = chunks;
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
2096
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
2097 // This returns chunks one at a time. If a new
10101
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
2098 // class List can be created that is a base class
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
2099 // of FreeList then something like FreeList::prepend()
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
2100 // can be used in place of this loop
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
2101 while (cur != NULL) {
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
2102 assert(cur->container() != NULL, "Container should have been set");
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
2103 cur->container()->dec_container_count();
10101
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
2104 // Capture the next link before it is changed
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
2105 // by the call to return_chunk_at_head();
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
2106 Metachunk* next = cur->next();
12902
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
2107 DEBUG_ONLY(cur->set_is_tagged_free(true);)
10101
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
2108 list->return_chunk_at_head(cur);
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
2109 cur = next;
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
2110 }
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
2111 }
df254344edf1 8011173: NPG: Replace the ChunkList implementation with class FreeList<Metachunk>
jmasa
parents: 8813
diff changeset
2112
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2113 SpaceManager::~SpaceManager() {
8784
79af1312fc2c 8005602: NPG: classunloading does not happen while CMS GC with -XX:+CMSClassUnloadingEnabled is used
mgerdin
parents: 8738
diff changeset
2114 // This call this->_lock which can't be done while holding expand_lock()
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2115 assert(sum_capacity_in_chunks_in_use() == allocated_chunks_words(),
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2116 err_msg("sum_capacity_in_chunks_in_use() " SIZE_FORMAT
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2117 " allocated_chunks_words() " SIZE_FORMAT,
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2118 sum_capacity_in_chunks_in_use(), allocated_chunks_words()));
8784
79af1312fc2c 8005602: NPG: classunloading does not happen while CMS GC with -XX:+CMSClassUnloadingEnabled is used
mgerdin
parents: 8738
diff changeset
2119
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2120 MutexLockerEx fcl(SpaceManager::expand_lock(),
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2121 Mutex::_no_safepoint_check_flag);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2122
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2123 chunk_manager()->slow_locked_verify();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2124
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2125 dec_total_from_size_metrics();
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2126
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2127 if (TraceMetadataChunkAllocation && Verbose) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2128 gclog_or_tty->print_cr("~SpaceManager(): " PTR_FORMAT, this);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2129 locked_print_chunks_in_use_on(gclog_or_tty);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2130 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2131
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
2132 // Do not mangle freed Metachunks. The chunk size inside Metachunks
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
2133 // is during the freeing of a VirtualSpaceNodes.
7185
90273fc0a981 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 6969
diff changeset
2134
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2135 // Have to update before the chunks_in_use lists are emptied
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2136 // below.
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2137 chunk_manager()->inc_free_chunks_total(allocated_chunks_words(),
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2138 sum_count_in_chunks_in_use());
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2139
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2140 // Add all the chunks in use by this space manager
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2141 // to the global list of free chunks.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2142
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2143 // Follow each list of chunks-in-use and add them to the
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2144 // free lists. Each list is NULL terminated.
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2145
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2146 for (ChunkIndex i = ZeroIndex; i < HumongousIndex; i = next_chunk_index(i)) {
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2147 if (TraceMetadataChunkAllocation && Verbose) {
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2148 gclog_or_tty->print_cr("returned %d %s chunks to freelist",
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2149 sum_count_in_chunks_in_use(i),
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2150 chunk_size_name(i));
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2151 }
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2152 Metachunk* chunks = chunks_in_use(i);
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2153 chunk_manager()->return_chunks(i, chunks);
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2154 set_chunks_in_use(i, NULL);
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2155 if (TraceMetadataChunkAllocation && Verbose) {
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2156 gclog_or_tty->print_cr("updated freelist count %d %s",
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2157 chunk_manager()->free_chunks(i)->count(),
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2158 chunk_size_name(i));
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2159 }
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2160 assert(i != HumongousIndex, "Humongous chunks are handled explicitly later");
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2161 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2162
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2163 // The medium chunk case may be optimized by passing the head and
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2164 // tail of the medium chunk list to add_at_head(). The tail is often
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2165 // the current chunk but there are probably exceptions.
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2166
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2167 // Humongous chunks
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2168 if (TraceMetadataChunkAllocation && Verbose) {
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2169 gclog_or_tty->print_cr("returned %d %s humongous chunks to dictionary",
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2170 sum_count_in_chunks_in_use(HumongousIndex),
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2171 chunk_size_name(HumongousIndex));
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2172 gclog_or_tty->print("Humongous chunk dictionary: ");
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2173 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2174 // Humongous chunks are never the current chunk.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2175 Metachunk* humongous_chunks = chunks_in_use(HumongousIndex);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2176
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2177 while (humongous_chunks != NULL) {
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2178 #ifdef ASSERT
12902
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
2179 humongous_chunks->set_is_tagged_free(true);
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2180 #endif
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2181 if (TraceMetadataChunkAllocation && Verbose) {
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2182 gclog_or_tty->print(PTR_FORMAT " (" SIZE_FORMAT ") ",
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2183 humongous_chunks,
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2184 humongous_chunks->word_size());
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2185 }
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2186 assert(humongous_chunks->word_size() == (size_t)
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2187 align_size_up(humongous_chunks->word_size(),
12979
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
2188 smallest_chunk_size()),
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2189 err_msg("Humongous chunk size is wrong: word size " SIZE_FORMAT
8007
d9058e388631 8007257: NPG: metaspace.cpp: Incorrect arguments in calls to err_msg
mikael
parents: 7447
diff changeset
2190 " granularity %d",
12979
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
2191 humongous_chunks->word_size(), smallest_chunk_size()));
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2192 Metachunk* next_humongous_chunks = humongous_chunks->next();
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
2193 humongous_chunks->container()->dec_container_count();
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2194 chunk_manager()->humongous_dictionary()->return_chunk(humongous_chunks);
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2195 humongous_chunks = next_humongous_chunks;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2196 }
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2197 if (TraceMetadataChunkAllocation && Verbose) {
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2198 gclog_or_tty->print_cr("");
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2199 gclog_or_tty->print_cr("updated dictionary count %d %s",
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2200 chunk_manager()->humongous_dictionary()->total_count(),
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2201 chunk_size_name(HumongousIndex));
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2202 }
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2203 chunk_manager()->slow_locked_verify();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2204 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2205
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2206 const char* SpaceManager::chunk_size_name(ChunkIndex index) const {
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2207 switch (index) {
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2208 case SpecializedIndex:
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2209 return "Specialized";
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2210 case SmallIndex:
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2211 return "Small";
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2212 case MediumIndex:
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2213 return "Medium";
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2214 case HumongousIndex:
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2215 return "Humongous";
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2216 default:
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2217 return NULL;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2218 }
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2219 }
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2220
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2221 ChunkIndex ChunkManager::list_index(size_t size) {
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2222 switch (size) {
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2223 case SpecializedChunk:
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2224 assert(SpecializedChunk == ClassSpecializedChunk,
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2225 "Need branch for ClassSpecializedChunk");
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2226 return SpecializedIndex;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2227 case SmallChunk:
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2228 case ClassSmallChunk:
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2229 return SmallIndex;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2230 case MediumChunk:
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2231 case ClassMediumChunk:
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2232 return MediumIndex;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2233 default:
7447
1de1b145f6bc 8005486: NPG: Incorrect assertion in ChunkManager::list_index()
jmasa
parents: 7446
diff changeset
2234 assert(size > MediumChunk || size > ClassMediumChunk,
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2235 "Not a humongous chunk");
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2236 return HumongousIndex;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2237 }
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2238 }
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2239
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2240 void SpaceManager::deallocate(MetaWord* p, size_t word_size) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2241 assert_lock_strong(_lock);
11966
83ca9dc4564d 8019845: Memory leak during class redefinition
fparain
parents: 11065
diff changeset
2242 size_t raw_word_size = get_raw_word_size(word_size);
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2243 size_t min_size = TreeChunk<Metablock, FreeList>::min_size();
11966
83ca9dc4564d 8019845: Memory leak during class redefinition
fparain
parents: 11065
diff changeset
2244 assert(raw_word_size >= min_size,
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2245 err_msg("Should not deallocate dark matter " SIZE_FORMAT "<" SIZE_FORMAT, word_size, min_size));
11966
83ca9dc4564d 8019845: Memory leak during class redefinition
fparain
parents: 11065
diff changeset
2246 block_freelists()->return_block(p, raw_word_size);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2247 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2248
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2249 // Adds a chunk to the list of chunks in use.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2250 void SpaceManager::add_chunk(Metachunk* new_chunk, bool make_current) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2251
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2252 assert(new_chunk != NULL, "Should not be NULL");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2253 assert(new_chunk->next() == NULL, "Should not be on a list");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2254
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2255 new_chunk->reset_empty();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2256
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2257 // Find the correct list and and set the current
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2258 // chunk for that list.
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2259 ChunkIndex index = ChunkManager::list_index(new_chunk->word_size());
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2260
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2261 if (index != HumongousIndex) {
12231
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
2262 retire_current_chunk();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2263 set_current_chunk(new_chunk);
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2264 new_chunk->set_next(chunks_in_use(index));
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2265 set_chunks_in_use(index, new_chunk);
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2266 } else {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2267 // For null class loader data and DumpSharedSpaces, the first chunk isn't
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2268 // small, so small will be null. Link this first chunk as the current
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2269 // chunk.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2270 if (make_current) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2271 // Set as the current chunk but otherwise treat as a humongous chunk.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2272 set_current_chunk(new_chunk);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2273 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2274 // Link at head. The _current_chunk only points to a humongous chunk for
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2275 // the null class loader metaspace (class and data virtual space managers)
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2276 // any humongous chunks so will not point to the tail
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2277 // of the humongous chunks list.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2278 new_chunk->set_next(chunks_in_use(HumongousIndex));
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2279 set_chunks_in_use(HumongousIndex, new_chunk);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2280
7447
1de1b145f6bc 8005486: NPG: Incorrect assertion in ChunkManager::list_index()
jmasa
parents: 7446
diff changeset
2281 assert(new_chunk->word_size() > medium_chunk_size(), "List inconsistency");
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2282 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2283
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2284 // Add to the running sum of capacity
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2285 inc_size_metrics(new_chunk->word_size());
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2286
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2287 assert(new_chunk->is_empty(), "Not ready for reuse");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2288 if (TraceMetadataChunkAllocation && Verbose) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2289 gclog_or_tty->print("SpaceManager::add_chunk: %d) ",
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2290 sum_count_in_chunks_in_use());
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2291 new_chunk->print_on(gclog_or_tty);
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2292 chunk_manager()->locked_print_free_chunks(gclog_or_tty);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2293 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2294 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2295
12231
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
2296 void SpaceManager::retire_current_chunk() {
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
2297 if (current_chunk() != NULL) {
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
2298 size_t remaining_words = current_chunk()->free_word_size();
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
2299 if (remaining_words >= TreeChunk<Metablock, FreeList>::min_size()) {
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
2300 block_freelists()->return_block(current_chunk()->allocate(remaining_words), remaining_words);
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
2301 inc_used_metrics(remaining_words);
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
2302 }
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
2303 }
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
2304 }
24e87613ee58 8009561: NPG: Metaspace fragmentation when retiring a Metachunk
mgerdin
parents: 12226
diff changeset
2305
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2306 Metachunk* SpaceManager::get_new_chunk(size_t word_size,
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2307 size_t grow_chunks_by_words) {
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2308 // Get a chunk from the chunk freelist
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2309 Metachunk* next = chunk_manager()->chunk_freelist_allocate(grow_chunks_by_words);
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2310
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2311 if (next == NULL) {
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2312 next = vs_list()->get_new_chunk(word_size,
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2313 grow_chunks_by_words,
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2314 medium_chunk_bunch());
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2315 }
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2316
12239
8227700da288 8024751: Fix bugs in TraceMetadata
stefank
parents: 12237
diff changeset
2317 if (TraceMetadataHumongousAllocation && next != NULL &&
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2318 SpaceManager::is_humongous(next->word_size())) {
12239
8227700da288 8024751: Fix bugs in TraceMetadata
stefank
parents: 12237
diff changeset
2319 gclog_or_tty->print_cr(" new humongous chunk word size "
8227700da288 8024751: Fix bugs in TraceMetadata
stefank
parents: 12237
diff changeset
2320 PTR_FORMAT, next->word_size());
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2321 }
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2322
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2323 return next;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2324 }
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2325
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2326 MetaWord* SpaceManager::allocate(size_t word_size) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2327 MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2328
10376
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
2329 size_t raw_word_size = get_raw_word_size(word_size);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2330 BlockFreelist* fl = block_freelists();
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2331 MetaWord* p = NULL;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2332 // Allocation from the dictionary is expensive in the sense that
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2333 // the dictionary has to be searched for a size. Don't allocate
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2334 // from the dictionary until it starts to get fat. Is this
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2335 // a reasonable policy? Maybe an skinny dictionary is fast enough
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2336 // for allocations. Do some profiling. JJJ
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2337 if (fl->total_size() > allocation_from_dictionary_limit) {
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2338 p = fl->get_block(raw_word_size);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2339 }
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2340 if (p == NULL) {
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2341 p = allocate_work(raw_word_size);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2342 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2343
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2344 return p;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2345 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2346
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2347 // Returns the address of spaced allocated for "word_size".
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2348 // This methods does not know about blocks (Metablocks)
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2349 MetaWord* SpaceManager::allocate_work(size_t word_size) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2350 assert_lock_strong(_lock);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2351 #ifdef ASSERT
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2352 if (Metadebug::test_metadata_failure()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2353 return NULL;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2354 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2355 #endif
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2356 // Is there space in the current chunk?
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2357 MetaWord* result = NULL;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2358
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2359 // For DumpSharedSpaces, only allocate out of the current chunk which is
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2360 // never null because we gave it the size we wanted. Caller reports out
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2361 // of memory if this returns null.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2362 if (DumpSharedSpaces) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2363 assert(current_chunk() != NULL, "should never happen");
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2364 inc_used_metrics(word_size);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2365 return current_chunk()->allocate(word_size); // caller handles null result
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2366 }
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2367
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2368 if (current_chunk() != NULL) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2369 result = current_chunk()->allocate(word_size);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2370 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2371
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2372 if (result == NULL) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2373 result = grow_and_allocate(word_size);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2374 }
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2375
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2376 if (result != NULL) {
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2377 inc_used_metrics(word_size);
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2378 assert(result != (MetaWord*) chunks_in_use(MediumIndex),
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2379 "Head of the list is being allocated");
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2380 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2381
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2382 return result;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2383 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2384
14190
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
2385 // This function looks at the chunks in the metaspace without locking.
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
2386 // The chunks are added with store ordering and not deleted except for at
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
2387 // unloading time.
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
2388 bool SpaceManager::contains(const void *ptr) {
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
2389 for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i))
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
2390 {
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
2391 Metachunk* curr = chunks_in_use(i);
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
2392 while (curr != NULL) {
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
2393 if (curr->contains(ptr)) return true;
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
2394 curr = curr->next();
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
2395 }
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
2396 }
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
2397 return false;
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
2398 }
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
2399
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2400 void SpaceManager::verify() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2401 // If there are blocks in the dictionary, then
14309
63a4eb8bcd23 8025856: Fix typos in the GC code
jwilhelm
parents: 14255
diff changeset
2402 // verification of chunks does not work since
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2403 // being in the dictionary alters a chunk.
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2404 if (block_freelists()->total_size() == 0) {
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2405 for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2406 Metachunk* curr = chunks_in_use(i);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2407 while (curr != NULL) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2408 curr->verify();
7208
eade6b2e4782 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 7187
diff changeset
2409 verify_chunk_size(curr);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2410 curr = curr->next();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2411 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2412 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2413 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2414 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2415
7208
eade6b2e4782 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 7187
diff changeset
2416 void SpaceManager::verify_chunk_size(Metachunk* chunk) {
eade6b2e4782 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 7187
diff changeset
2417 assert(is_humongous(chunk->word_size()) ||
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2418 chunk->word_size() == medium_chunk_size() ||
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2419 chunk->word_size() == small_chunk_size() ||
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2420 chunk->word_size() == specialized_chunk_size(),
7208
eade6b2e4782 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 7187
diff changeset
2421 "Chunk size is wrong");
eade6b2e4782 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 7187
diff changeset
2422 return;
eade6b2e4782 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 7187
diff changeset
2423 }
eade6b2e4782 8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents: 7187
diff changeset
2424
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2425 #ifdef ASSERT
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2426 void SpaceManager::verify_allocated_blocks_words() {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2427 // Verification is only guaranteed at a safepoint.
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2428 assert(SafepointSynchronize::is_at_safepoint() || !Universe::is_fully_initialized(),
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2429 "Verification can fail if the applications is running");
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2430 assert(allocated_blocks_words() == sum_used_in_chunks_in_use(),
8007
d9058e388631 8007257: NPG: metaspace.cpp: Incorrect arguments in calls to err_msg
mikael
parents: 7447
diff changeset
2431 err_msg("allocation total is not consistent " SIZE_FORMAT
d9058e388631 8007257: NPG: metaspace.cpp: Incorrect arguments in calls to err_msg
mikael
parents: 7447
diff changeset
2432 " vs " SIZE_FORMAT,
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2433 allocated_blocks_words(), sum_used_in_chunks_in_use()));
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2434 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2435
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2436 #endif
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2437
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2438 void SpaceManager::dump(outputStream* const out) const {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2439 size_t curr_total = 0;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2440 size_t waste = 0;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2441 uint i = 0;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2442 size_t used = 0;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2443 size_t capacity = 0;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2444
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2445 // Add up statistics for all chunks in this SpaceManager.
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2446 for (ChunkIndex index = ZeroIndex;
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2447 index < NumberOfInUseLists;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2448 index = next_chunk_index(index)) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2449 for (Metachunk* curr = chunks_in_use(index);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2450 curr != NULL;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2451 curr = curr->next()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2452 out->print("%d) ", i++);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2453 curr->print_on(out);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2454 curr_total += curr->word_size();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2455 used += curr->used_word_size();
12902
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
2456 capacity += curr->word_size();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2457 waste += curr->free_word_size() + curr->overhead();;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2458 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2459 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2460
12239
8227700da288 8024751: Fix bugs in TraceMetadata
stefank
parents: 12237
diff changeset
2461 if (TraceMetadataChunkAllocation && Verbose) {
8227700da288 8024751: Fix bugs in TraceMetadata
stefank
parents: 12237
diff changeset
2462 block_freelists()->print_on(out);
8227700da288 8024751: Fix bugs in TraceMetadata
stefank
parents: 12237
diff changeset
2463 }
8227700da288 8024751: Fix bugs in TraceMetadata
stefank
parents: 12237
diff changeset
2464
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2465 size_t free = current_chunk() == NULL ? 0 : current_chunk()->free_word_size();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2466 // Free space isn't wasted.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2467 waste -= free;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2468
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2469 out->print_cr("total of all chunks " SIZE_FORMAT " used " SIZE_FORMAT
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2470 " free " SIZE_FORMAT " capacity " SIZE_FORMAT
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2471 " waste " SIZE_FORMAT, curr_total, used, free, capacity, waste);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2472 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2473
7185
90273fc0a981 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 6969
diff changeset
2474 #ifndef PRODUCT
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2475 void SpaceManager::mangle_freed_chunks() {
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2476 for (ChunkIndex index = ZeroIndex;
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
2477 index < NumberOfInUseLists;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2478 index = next_chunk_index(index)) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2479 for (Metachunk* curr = chunks_in_use(index);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2480 curr != NULL;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2481 curr = curr->next()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2482 curr->mangle();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2483 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2484 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2485 }
7185
90273fc0a981 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 6969
diff changeset
2486 #endif // PRODUCT
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2487
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2488 // MetaspaceAux
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2489
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2490
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2491 size_t MetaspaceAux::_allocated_capacity_words[] = {0, 0};
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2492 size_t MetaspaceAux::_allocated_used_words[] = {0, 0};
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2493
12063
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 12056
diff changeset
2494 size_t MetaspaceAux::free_bytes(Metaspace::MetadataType mdtype) {
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 12056
diff changeset
2495 VirtualSpaceList* list = Metaspace::get_space_list(mdtype);
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 12056
diff changeset
2496 return list == NULL ? 0 : list->free_bytes();
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 12056
diff changeset
2497 }
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 12056
diff changeset
2498
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2499 size_t MetaspaceAux::free_bytes() {
12063
1a8fb39bdbc4 8014659: NPG: performance counters for compressed klass space
ehelin
parents: 12056
diff changeset
2500 return free_bytes(Metaspace::ClassType) + free_bytes(Metaspace::NonClassType);
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2501 }
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2502
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2503 void MetaspaceAux::dec_capacity(Metaspace::MetadataType mdtype, size_t words) {
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2504 assert_lock_strong(SpaceManager::expand_lock());
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2505 assert(words <= allocated_capacity_words(mdtype),
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2506 err_msg("About to decrement below 0: words " SIZE_FORMAT
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2507 " is greater than _allocated_capacity_words[%u] " SIZE_FORMAT,
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2508 words, mdtype, allocated_capacity_words(mdtype)));
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2509 _allocated_capacity_words[mdtype] -= words;
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2510 }
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2511
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2512 void MetaspaceAux::inc_capacity(Metaspace::MetadataType mdtype, size_t words) {
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2513 assert_lock_strong(SpaceManager::expand_lock());
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2514 // Needs to be atomic
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2515 _allocated_capacity_words[mdtype] += words;
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2516 }
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2517
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2518 void MetaspaceAux::dec_used(Metaspace::MetadataType mdtype, size_t words) {
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2519 assert(words <= allocated_used_words(mdtype),
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2520 err_msg("About to decrement below 0: words " SIZE_FORMAT
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2521 " is greater than _allocated_used_words[%u] " SIZE_FORMAT,
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2522 words, mdtype, allocated_used_words(mdtype)));
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2523 // For CMS deallocation of the Metaspaces occurs during the
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2524 // sweep which is a concurrent phase. Protection by the expand_lock()
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2525 // is not enough since allocation is on a per Metaspace basis
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2526 // and protected by the Metaspace lock.
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2527 jlong minus_words = (jlong) - (jlong) words;
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2528 Atomic::add_ptr(minus_words, &_allocated_used_words[mdtype]);
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2529 }
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2530
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2531 void MetaspaceAux::inc_used(Metaspace::MetadataType mdtype, size_t words) {
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2532 // _allocated_used_words tracks allocations for
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2533 // each piece of metadata. Those allocations are
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2534 // generally done concurrently by different application
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2535 // threads so must be done atomically.
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2536 Atomic::add_ptr(words, &_allocated_used_words[mdtype]);
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2537 }
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2538
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2539 size_t MetaspaceAux::used_bytes_slow(Metaspace::MetadataType mdtype) {
6730
5d2156bcb78b 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 6726
diff changeset
2540 size_t used = 0;
5d2156bcb78b 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 6726
diff changeset
2541 ClassLoaderDataGraphMetaspaceIterator iter;
5d2156bcb78b 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 6726
diff changeset
2542 while (iter.repeat()) {
5d2156bcb78b 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 6726
diff changeset
2543 Metaspace* msp = iter.get_next();
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2544 // Sum allocated_blocks_words for each metaspace
6730
5d2156bcb78b 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 6726
diff changeset
2545 if (msp != NULL) {
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2546 used += msp->used_words_slow(mdtype);
6730
5d2156bcb78b 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 6726
diff changeset
2547 }
5d2156bcb78b 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 6726
diff changeset
2548 }
5d2156bcb78b 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 6726
diff changeset
2549 return used * BytesPerWord;
5d2156bcb78b 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 6726
diff changeset
2550 }
5d2156bcb78b 7195789: NPG: assert(used + free == capacity) failed: Accounting is wrong
jmasa
parents: 6726
diff changeset
2551
12235
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2552 size_t MetaspaceAux::free_bytes_slow(Metaspace::MetadataType mdtype) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2553 size_t free = 0;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2554 ClassLoaderDataGraphMetaspaceIterator iter;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2555 while (iter.repeat()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2556 Metaspace* msp = iter.get_next();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2557 if (msp != NULL) {
12235
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2558 free += msp->free_words_slow(mdtype);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2559 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2560 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2561 return free * BytesPerWord;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2562 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2563
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2564 size_t MetaspaceAux::capacity_bytes_slow(Metaspace::MetadataType mdtype) {
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2565 if ((mdtype == Metaspace::ClassType) && !Metaspace::using_class_space()) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2566 return 0;
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2567 }
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2568 // Don't count the space in the freelists. That space will be
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2569 // added to the capacity calculation as needed.
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2570 size_t capacity = 0;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2571 ClassLoaderDataGraphMetaspaceIterator iter;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2572 while (iter.repeat()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2573 Metaspace* msp = iter.get_next();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2574 if (msp != NULL) {
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2575 capacity += msp->capacity_words_slow(mdtype);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2576 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2577 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2578 return capacity * BytesPerWord;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2579 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2580
12235
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2581 size_t MetaspaceAux::capacity_bytes_slow() {
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2582 #ifdef PRODUCT
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2583 // Use allocated_capacity_bytes() in PRODUCT instead of this function.
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2584 guarantee(false, "Should not call capacity_bytes_slow() in the PRODUCT");
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2585 #endif
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2586 size_t class_capacity = capacity_bytes_slow(Metaspace::ClassType);
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2587 size_t non_class_capacity = capacity_bytes_slow(Metaspace::NonClassType);
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2588 assert(allocated_capacity_bytes() == class_capacity + non_class_capacity,
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2589 err_msg("bad accounting: allocated_capacity_bytes() " SIZE_FORMAT
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2590 " class_capacity + non_class_capacity " SIZE_FORMAT
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2591 " class_capacity " SIZE_FORMAT " non_class_capacity " SIZE_FORMAT,
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2592 allocated_capacity_bytes(), class_capacity + non_class_capacity,
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2593 class_capacity, non_class_capacity));
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2594
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2595 return class_capacity + non_class_capacity;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2596 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2597
12235
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2598 size_t MetaspaceAux::reserved_bytes(Metaspace::MetadataType mdtype) {
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2599 VirtualSpaceList* list = Metaspace::get_space_list(mdtype);
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
2600 return list == NULL ? 0 : list->reserved_bytes();
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
2601 }
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
2602
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
2603 size_t MetaspaceAux::committed_bytes(Metaspace::MetadataType mdtype) {
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
2604 VirtualSpaceList* list = Metaspace::get_space_list(mdtype);
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
2605 return list == NULL ? 0 : list->committed_bytes();
12235
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2606 }
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2607
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2608 size_t MetaspaceAux::min_chunk_size_words() { return Metaspace::first_chunk_word_size(); }
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2609
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2610 size_t MetaspaceAux::free_chunks_total_words(Metaspace::MetadataType mdtype) {
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2611 ChunkManager* chunk_manager = Metaspace::get_chunk_manager(mdtype);
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2612 if (chunk_manager == NULL) {
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2613 return 0;
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2614 }
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2615 chunk_manager->slow_verify();
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2616 return chunk_manager->free_chunks_total_words();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2617 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2618
12235
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2619 size_t MetaspaceAux::free_chunks_total_bytes(Metaspace::MetadataType mdtype) {
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2620 return free_chunks_total_words(mdtype) * BytesPerWord;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2621 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2622
12235
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2623 size_t MetaspaceAux::free_chunks_total_words() {
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2624 return free_chunks_total_words(Metaspace::ClassType) +
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2625 free_chunks_total_words(Metaspace::NonClassType);
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2626 }
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2627
12235
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2628 size_t MetaspaceAux::free_chunks_total_bytes() {
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2629 return free_chunks_total_words() * BytesPerWord;
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2630 }
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2631
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2632 void MetaspaceAux::print_metaspace_change(size_t prev_metadata_used) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2633 gclog_or_tty->print(", [Metaspace:");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2634 if (PrintGCDetails && Verbose) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2635 gclog_or_tty->print(" " SIZE_FORMAT
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2636 "->" SIZE_FORMAT
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2637 "(" SIZE_FORMAT ")",
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2638 prev_metadata_used,
11037
df7e1c0e3dc1 8014546: MetaspaceAux print_metaspace_change() should print "used" after GC not capacity
jmasa
parents: 10376
diff changeset
2639 allocated_used_bytes(),
12235
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2640 reserved_bytes());
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2641 } else {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2642 gclog_or_tty->print(" " SIZE_FORMAT "K"
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2643 "->" SIZE_FORMAT "K"
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2644 "(" SIZE_FORMAT "K)",
12235
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2645 prev_metadata_used/K,
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2646 allocated_used_bytes()/K,
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2647 reserved_bytes()/K);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2648 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2649
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2650 gclog_or_tty->print("]");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2651 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2652
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2653 // This is printed when PrintGCDetails
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2654 void MetaspaceAux::print_on(outputStream* out) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2655 Metaspace::MetadataType nct = Metaspace::NonClassType;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2656
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2657 out->print_cr(" Metaspace "
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2658 "used " SIZE_FORMAT "K, "
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2659 "capacity " SIZE_FORMAT "K, "
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2660 "committed " SIZE_FORMAT "K, "
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2661 "reserved " SIZE_FORMAT "K",
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2662 allocated_used_bytes()/K,
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2663 allocated_capacity_bytes()/K,
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2664 committed_bytes()/K,
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2665 reserved_bytes()/K);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2666
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2667 if (Metaspace::using_class_space()) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2668 Metaspace::MetadataType ct = Metaspace::ClassType;
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2669 out->print_cr(" class space "
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2670 "used " SIZE_FORMAT "K, "
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2671 "capacity " SIZE_FORMAT "K, "
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2672 "committed " SIZE_FORMAT "K, "
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2673 "reserved " SIZE_FORMAT "K",
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2674 allocated_used_bytes(ct)/K,
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2675 allocated_capacity_bytes(ct)/K,
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2676 committed_bytes(ct)/K,
12235
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2677 reserved_bytes(ct)/K);
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2678 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2679 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2680
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2681 // Print information for class space and data space separately.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2682 // This is almost the same as above.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2683 void MetaspaceAux::print_on(outputStream* out, Metaspace::MetadataType mdtype) {
12235
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2684 size_t free_chunks_capacity_bytes = free_chunks_total_bytes(mdtype);
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2685 size_t capacity_bytes = capacity_bytes_slow(mdtype);
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2686 size_t used_bytes = used_bytes_slow(mdtype);
12235
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
2687 size_t free_bytes = free_bytes_slow(mdtype);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2688 size_t used_and_free = used_bytes + free_bytes +
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2689 free_chunks_capacity_bytes;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2690 out->print_cr(" Chunk accounting: used in chunks " SIZE_FORMAT
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2691 "K + unused in chunks " SIZE_FORMAT "K + "
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2692 " capacity in free chunks " SIZE_FORMAT "K = " SIZE_FORMAT
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2693 "K capacity in allocated chunks " SIZE_FORMAT "K",
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2694 used_bytes / K,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2695 free_bytes / K,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2696 free_chunks_capacity_bytes / K,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2697 used_and_free / K,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2698 capacity_bytes / K);
8738
1c88b99a2b01 8009282: Assertion "assert(used_and_free == capacity_bytes) failed: Accounting is wrong" failed with -XX:+Verbose -XX:+TraceMetadataChunkAllocation
mgerdin
parents: 8040
diff changeset
2699 // Accounting can only be correct if we got the values during a safepoint
1c88b99a2b01 8009282: Assertion "assert(used_and_free == capacity_bytes) failed: Accounting is wrong" failed with -XX:+Verbose -XX:+TraceMetadataChunkAllocation
mgerdin
parents: 8040
diff changeset
2700 assert(!SafepointSynchronize::is_at_safepoint() || used_and_free == capacity_bytes, "Accounting is wrong");
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2701 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2702
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2703 // Print total fragmentation for class metaspaces
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2704 void MetaspaceAux::print_class_waste(outputStream* out) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2705 assert(Metaspace::using_class_space(), "class metaspace not used");
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2706 size_t cls_specialized_waste = 0, cls_small_waste = 0, cls_medium_waste = 0;
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2707 size_t cls_specialized_count = 0, cls_small_count = 0, cls_medium_count = 0, cls_humongous_count = 0;
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2708 ClassLoaderDataGraphMetaspaceIterator iter;
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2709 while (iter.repeat()) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2710 Metaspace* msp = iter.get_next();
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2711 if (msp != NULL) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2712 cls_specialized_waste += msp->class_vsm()->sum_waste_in_chunks_in_use(SpecializedIndex);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2713 cls_specialized_count += msp->class_vsm()->sum_count_in_chunks_in_use(SpecializedIndex);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2714 cls_small_waste += msp->class_vsm()->sum_waste_in_chunks_in_use(SmallIndex);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2715 cls_small_count += msp->class_vsm()->sum_count_in_chunks_in_use(SmallIndex);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2716 cls_medium_waste += msp->class_vsm()->sum_waste_in_chunks_in_use(MediumIndex);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2717 cls_medium_count += msp->class_vsm()->sum_count_in_chunks_in_use(MediumIndex);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2718 cls_humongous_count += msp->class_vsm()->sum_count_in_chunks_in_use(HumongousIndex);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2719 }
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2720 }
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2721 out->print_cr(" class: " SIZE_FORMAT " specialized(s) " SIZE_FORMAT ", "
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2722 SIZE_FORMAT " small(s) " SIZE_FORMAT ", "
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2723 SIZE_FORMAT " medium(s) " SIZE_FORMAT ", "
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2724 "large count " SIZE_FORMAT,
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2725 cls_specialized_count, cls_specialized_waste,
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2726 cls_small_count, cls_small_waste,
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2727 cls_medium_count, cls_medium_waste, cls_humongous_count);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2728 }
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2729
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2730 // Print total fragmentation for data and class metaspaces separately
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2731 void MetaspaceAux::print_waste(outputStream* out) {
11064
de2d15ce3d4a 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 10376
diff changeset
2732 size_t specialized_waste = 0, small_waste = 0, medium_waste = 0;
de2d15ce3d4a 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 10376
diff changeset
2733 size_t specialized_count = 0, small_count = 0, medium_count = 0, humongous_count = 0;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2734
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2735 ClassLoaderDataGraphMetaspaceIterator iter;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2736 while (iter.repeat()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2737 Metaspace* msp = iter.get_next();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2738 if (msp != NULL) {
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2739 specialized_waste += msp->vsm()->sum_waste_in_chunks_in_use(SpecializedIndex);
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2740 specialized_count += msp->vsm()->sum_count_in_chunks_in_use(SpecializedIndex);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2741 small_waste += msp->vsm()->sum_waste_in_chunks_in_use(SmallIndex);
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2742 small_count += msp->vsm()->sum_count_in_chunks_in_use(SmallIndex);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2743 medium_waste += msp->vsm()->sum_waste_in_chunks_in_use(MediumIndex);
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2744 medium_count += msp->vsm()->sum_count_in_chunks_in_use(MediumIndex);
11064
de2d15ce3d4a 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 10376
diff changeset
2745 humongous_count += msp->vsm()->sum_count_in_chunks_in_use(HumongousIndex);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2746 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2747 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2748 out->print_cr("Total fragmentation waste (words) doesn't count free space");
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2749 out->print_cr(" data: " SIZE_FORMAT " specialized(s) " SIZE_FORMAT ", "
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2750 SIZE_FORMAT " small(s) " SIZE_FORMAT ", "
11064
de2d15ce3d4a 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 10376
diff changeset
2751 SIZE_FORMAT " medium(s) " SIZE_FORMAT ", "
de2d15ce3d4a 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 10376
diff changeset
2752 "large count " SIZE_FORMAT,
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2753 specialized_count, specialized_waste, small_count,
11064
de2d15ce3d4a 8015391: NPG: With -XX:+UseCompressedKlassPointers OOME due to exhausted metadata space could occur when metaspace is almost empty
coleenp
parents: 10376
diff changeset
2754 small_waste, medium_count, medium_waste, humongous_count);
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2755 if (Metaspace::using_class_space()) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2756 print_class_waste(out);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2757 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2758 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2759
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2760 // Dump global metaspace things from the end of ClassLoaderDataGraph
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2761 void MetaspaceAux::dump(outputStream* out) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2762 out->print_cr("All Metaspace:");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2763 out->print("data space: "); print_on(out, Metaspace::NonClassType);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2764 out->print("class space: "); print_on(out, Metaspace::ClassType);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2765 print_waste(out);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2766 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2767
6969
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
2768 void MetaspaceAux::verify_free_chunks() {
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2769 Metaspace::chunk_manager_metadata()->verify();
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2770 if (Metaspace::using_class_space()) {
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2771 Metaspace::chunk_manager_class()->verify();
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2772 }
6969
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
2773 }
6bc207d87e5d 7200229: NPG: possible performance issue exposed by closed/runtime/6559877/Test6559877.java
mgerdin
parents: 6885
diff changeset
2774
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2775 void MetaspaceAux::verify_capacity() {
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2776 #ifdef ASSERT
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2777 size_t running_sum_capacity_bytes = allocated_capacity_bytes();
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2778 // For purposes of the running sum of capacity, verify against capacity
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2779 size_t capacity_in_use_bytes = capacity_bytes_slow();
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2780 assert(running_sum_capacity_bytes == capacity_in_use_bytes,
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2781 err_msg("allocated_capacity_words() * BytesPerWord " SIZE_FORMAT
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2782 " capacity_bytes_slow()" SIZE_FORMAT,
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2783 running_sum_capacity_bytes, capacity_in_use_bytes));
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2784 for (Metaspace::MetadataType i = Metaspace::ClassType;
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2785 i < Metaspace:: MetadataTypeCount;
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2786 i = (Metaspace::MetadataType)(i + 1)) {
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2787 size_t capacity_in_use_bytes = capacity_bytes_slow(i);
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2788 assert(allocated_capacity_bytes(i) == capacity_in_use_bytes,
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2789 err_msg("allocated_capacity_bytes(%u) " SIZE_FORMAT
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2790 " capacity_bytes_slow(%u)" SIZE_FORMAT,
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2791 i, allocated_capacity_bytes(i), i, capacity_in_use_bytes));
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2792 }
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2793 #endif
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2794 }
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2795
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2796 void MetaspaceAux::verify_used() {
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2797 #ifdef ASSERT
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2798 size_t running_sum_used_bytes = allocated_used_bytes();
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2799 // For purposes of the running sum of used, verify against used
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2800 size_t used_in_use_bytes = used_bytes_slow();
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2801 assert(allocated_used_bytes() == used_in_use_bytes,
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2802 err_msg("allocated_used_bytes() " SIZE_FORMAT
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2803 " used_bytes_slow()" SIZE_FORMAT,
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2804 allocated_used_bytes(), used_in_use_bytes));
10330
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2805 for (Metaspace::MetadataType i = Metaspace::ClassType;
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2806 i < Metaspace:: MetadataTypeCount;
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2807 i = (Metaspace::MetadataType)(i + 1)) {
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2808 size_t used_in_use_bytes = used_bytes_slow(i);
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2809 assert(allocated_used_bytes(i) == used_in_use_bytes,
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2810 err_msg("allocated_used_bytes(%u) " SIZE_FORMAT
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2811 " used_bytes_slow(%u)" SIZE_FORMAT,
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2812 i, allocated_used_bytes(i), i, used_in_use_bytes));
2b1a9d972fc2 8014862: Add fast Metasapce capacity and used per MetadataType
jmasa
parents: 10191
diff changeset
2813 }
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2814 #endif
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2815 }
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2816
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2817 void MetaspaceAux::verify_metrics() {
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2818 verify_capacity();
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2819 verify_used();
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2820 }
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2821
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
2822
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2823 // Metaspace methods
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2824
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2825 size_t Metaspace::_first_chunk_word_size = 0;
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2826 size_t Metaspace::_first_class_chunk_word_size = 0;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2827
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2828 size_t Metaspace::_commit_alignment = 0;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2829 size_t Metaspace::_reserve_alignment = 0;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2830
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2831 Metaspace::Metaspace(Mutex* lock, MetaspaceType type) {
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
2832 initialize(lock, type);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2833 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2834
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2835 Metaspace::~Metaspace() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2836 delete _vsm;
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2837 if (using_class_space()) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2838 delete _class_vsm;
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2839 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2840 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2841
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2842 VirtualSpaceList* Metaspace::_space_list = NULL;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2843 VirtualSpaceList* Metaspace::_class_space_list = NULL;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2844
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2845 ChunkManager* Metaspace::_chunk_manager_metadata = NULL;
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2846 ChunkManager* Metaspace::_chunk_manager_class = NULL;
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2847
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2848 #define VIRTUALSPACEMULTIPLIER 2
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
2849
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2850 #ifdef _LP64
13000
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
2851 static const uint64_t UnscaledClassSpaceMax = (uint64_t(max_juint) + 1);
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
2852
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2853 void Metaspace::set_narrow_klass_base_and_shift(address metaspace_base, address cds_base) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2854 // Figure out the narrow_klass_base and the narrow_klass_shift. The
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2855 // narrow_klass_base is the lower of the metaspace base and the cds base
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2856 // (if cds is enabled). The narrow_klass_shift depends on the distance
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2857 // between the lower base and higher address.
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2858 address lower_base;
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2859 address higher_address;
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2860 if (UseSharedSpaces) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2861 higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()),
13000
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
2862 (address)(metaspace_base + compressed_class_space_size()));
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2863 lower_base = MIN2(metaspace_base, cds_base);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2864 } else {
13000
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
2865 higher_address = metaspace_base + compressed_class_space_size();
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2866 lower_base = metaspace_base;
13000
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
2867
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
2868 uint64_t klass_encoding_max = UnscaledClassSpaceMax << LogKlassAlignmentInBytes;
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
2869 // If compressed class space fits in lower 32G, we don't need a base.
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
2870 if (higher_address <= (address)klass_encoding_max) {
14309
63a4eb8bcd23 8025856: Fix typos in the GC code
jwilhelm
parents: 14255
diff changeset
2871 lower_base = 0; // Effectively lower base is zero.
13000
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
2872 }
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2873 }
13000
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
2874
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2875 Universe::set_narrow_klass_base(lower_base);
13000
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
2876
13037
c8fc12209830 8027616: Off by one error in putback for compressed oops nashorn performance improvement
coleenp
parents: 13001
diff changeset
2877 if ((uint64_t)(higher_address - lower_base) <= UnscaledClassSpaceMax) {
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2878 Universe::set_narrow_klass_shift(0);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2879 } else {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2880 assert(!UseSharedSpaces, "Cannot shift with UseSharedSpaces");
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2881 Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2882 }
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2883 }
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2884
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2885 // Return TRUE if the specified metaspace_base and cds_base are close enough
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2886 // to work with compressed klass pointers.
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2887 bool Metaspace::can_use_cds_with_metaspace_addr(char* metaspace_base, address cds_base) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2888 assert(cds_base != 0 && UseSharedSpaces, "Only use with CDS");
12226
7944aba7ba41 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 12110
diff changeset
2889 assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs");
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2890 address lower_base = MIN2((address)metaspace_base, cds_base);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2891 address higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()),
13000
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
2892 (address)(metaspace_base + compressed_class_space_size()));
13037
c8fc12209830 8027616: Off by one error in putback for compressed oops nashorn performance improvement
coleenp
parents: 13001
diff changeset
2893 return ((uint64_t)(higher_address - lower_base) <= UnscaledClassSpaceMax);
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2894 }
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2895
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2896 // Try to allocate the metaspace at the requested addr.
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2897 void Metaspace::allocate_metaspace_compressed_klass_ptrs(char* requested_addr, address cds_base) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2898 assert(using_class_space(), "called improperly");
12226
7944aba7ba41 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 12110
diff changeset
2899 assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs");
13000
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
2900 assert(compressed_class_space_size() < KlassEncodingMetaspaceMax,
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2901 "Metaspace size is too big");
13000
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
2902 assert_is_ptr_aligned(requested_addr, _reserve_alignment);
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
2903 assert_is_ptr_aligned(cds_base, _reserve_alignment);
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
2904 assert_is_size_aligned(compressed_class_space_size(), _reserve_alignment);
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2905
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2906 // Don't use large pages for the class space.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2907 bool large_pages = false;
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2908
13000
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
2909 ReservedSpace metaspace_rs = ReservedSpace(compressed_class_space_size(),
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2910 _reserve_alignment,
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2911 large_pages,
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2912 requested_addr, 0);
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2913 if (!metaspace_rs.is_reserved()) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2914 if (UseSharedSpaces) {
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2915 size_t increment = align_size_up(1*G, _reserve_alignment);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2916
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2917 // Keep trying to allocate the metaspace, increasing the requested_addr
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2918 // by 1GB each time, until we reach an address that will no longer allow
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2919 // use of CDS with compressed klass pointers.
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2920 char *addr = requested_addr;
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2921 while (!metaspace_rs.is_reserved() && (addr + increment > addr) &&
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2922 can_use_cds_with_metaspace_addr(addr + increment, cds_base)) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2923 addr = addr + increment;
13000
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
2924 metaspace_rs = ReservedSpace(compressed_class_space_size(),
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2925 _reserve_alignment, large_pages, addr, 0);
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2926 }
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2927 }
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2928
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2929 // If no successful allocation then try to allocate the space anywhere. If
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2930 // that fails then OOM doom. At this point we cannot try allocating the
12226
7944aba7ba41 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 12110
diff changeset
2931 // metaspace as if UseCompressedClassPointers is off because too much
7944aba7ba41 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 12110
diff changeset
2932 // initialization has happened that depends on UseCompressedClassPointers.
7944aba7ba41 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 12110
diff changeset
2933 // So, UseCompressedClassPointers cannot be turned off at this point.
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2934 if (!metaspace_rs.is_reserved()) {
13000
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
2935 metaspace_rs = ReservedSpace(compressed_class_space_size(),
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2936 _reserve_alignment, large_pages);
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2937 if (!metaspace_rs.is_reserved()) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2938 vm_exit_during_initialization(err_msg("Could not allocate metaspace: %d bytes",
13000
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
2939 compressed_class_space_size()));
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2940 }
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2941 }
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2942 }
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2943
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2944 // If we got here then the metaspace got allocated.
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2945 MemTracker::record_virtual_memory_type((address)metaspace_rs.base(), mtClass);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2946
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2947 // Verify that we can use shared spaces. Otherwise, turn off CDS.
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2948 if (UseSharedSpaces && !can_use_cds_with_metaspace_addr(metaspace_rs.base(), cds_base)) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2949 FileMapInfo::stop_sharing_and_unmap(
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2950 "Could not allocate metaspace at a compatible address");
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2951 }
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2952
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2953 set_narrow_klass_base_and_shift((address)metaspace_rs.base(),
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2954 UseSharedSpaces ? (address)cds_base : 0);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2955
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2956 initialize_class_space(metaspace_rs);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2957
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2958 if (PrintCompressedOopsMode || (PrintMiscellaneous && Verbose)) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2959 gclog_or_tty->print_cr("Narrow klass base: " PTR_FORMAT ", Narrow klass shift: " SIZE_FORMAT,
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2960 Universe::narrow_klass_base(), Universe::narrow_klass_shift());
13000
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
2961 gclog_or_tty->print_cr("Compressed class space size: " SIZE_FORMAT " Address: " PTR_FORMAT " Req Addr: " PTR_FORMAT,
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
2962 compressed_class_space_size(), metaspace_rs.base(), requested_addr);
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2963 }
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2964 }
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2965
12226
7944aba7ba41 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 12110
diff changeset
2966 // For UseCompressedClassPointers the class space is reserved above the top of
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2967 // the Java heap. The argument passed in is at the base of the compressed space.
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2968 void Metaspace::initialize_class_space(ReservedSpace rs) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2969 // The reserved space size may be bigger because of alignment, esp with UseLargePages
12226
7944aba7ba41 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 12110
diff changeset
2970 assert(rs.size() >= CompressedClassSpaceSize,
7944aba7ba41 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 12110
diff changeset
2971 err_msg(SIZE_FORMAT " != " UINTX_FORMAT, rs.size(), CompressedClassSpaceSize));
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2972 assert(using_class_space(), "Must be using class space");
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2973 _class_space_list = new VirtualSpaceList(rs);
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
2974 _chunk_manager_class = new ChunkManager(SpecializedChunk, ClassSmallChunk, ClassMediumChunk);
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2975
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2976 if (!_class_space_list->initialization_succeeded()) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2977 vm_exit_during_initialization("Failed to setup compressed class space virtual space list.");
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2978 }
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2979 }
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2980
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2981 #endif
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
2982
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2983 void Metaspace::ergo_initialize() {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2984 if (DumpSharedSpaces) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2985 // Using large pages when dumping the shared archive is currently not implemented.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2986 FLAG_SET_ERGO(bool, UseLargePagesInMetaspace, false);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2987 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2988
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2989 size_t page_size = os::vm_page_size();
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2990 if (UseLargePages && UseLargePagesInMetaspace) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2991 page_size = os::large_page_size();
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2992 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2993
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2994 _commit_alignment = page_size;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2995 _reserve_alignment = MAX2(page_size, (size_t)os::vm_allocation_granularity());
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2996
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2997 // Do not use FLAG_SET_ERGO to update MaxMetaspaceSize, since this will
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2998 // override if MaxMetaspaceSize was set on the command line or not.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
2999 // This information is needed later to conform to the specification of the
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3000 // java.lang.management.MemoryUsage API.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3001 //
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3002 // Ideally, we would be able to set the default value of MaxMetaspaceSize in
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3003 // globals.hpp to the aligned value, but this is not possible, since the
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3004 // alignment depends on other flags being parsed.
13058
3aee6bc29547 8026852: Use restricted_align_down in collector policy code
jwilhelm
parents: 12980
diff changeset
3005 MaxMetaspaceSize = align_size_down_bounded(MaxMetaspaceSize, _reserve_alignment);
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3006
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3007 if (MetaspaceSize > MaxMetaspaceSize) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3008 MetaspaceSize = MaxMetaspaceSize;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3009 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3010
13058
3aee6bc29547 8026852: Use restricted_align_down in collector policy code
jwilhelm
parents: 12980
diff changeset
3011 MetaspaceSize = align_size_down_bounded(MetaspaceSize, _commit_alignment);
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3012
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3013 assert(MetaspaceSize <= MaxMetaspaceSize, "MetaspaceSize should be limited by MaxMetaspaceSize");
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3014
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3015 if (MetaspaceSize < 256*K) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3016 vm_exit_during_initialization("Too small initial Metaspace size");
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3017 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3018
13058
3aee6bc29547 8026852: Use restricted_align_down in collector policy code
jwilhelm
parents: 12980
diff changeset
3019 MinMetaspaceExpansion = align_size_down_bounded(MinMetaspaceExpansion, _commit_alignment);
3aee6bc29547 8026852: Use restricted_align_down in collector policy code
jwilhelm
parents: 12980
diff changeset
3020 MaxMetaspaceExpansion = align_size_down_bounded(MaxMetaspaceExpansion, _commit_alignment);
3aee6bc29547 8026852: Use restricted_align_down in collector policy code
jwilhelm
parents: 12980
diff changeset
3021
3aee6bc29547 8026852: Use restricted_align_down in collector policy code
jwilhelm
parents: 12980
diff changeset
3022 CompressedClassSpaceSize = align_size_down_bounded(CompressedClassSpaceSize, _reserve_alignment);
13000
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
3023 set_compressed_class_space_size(CompressedClassSpaceSize);
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3024 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3025
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3026 void Metaspace::global_initialize() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3027 // Initialize the alignment for shared spaces.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3028 int max_alignment = os::vm_page_size();
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3029 size_t cds_total = 0;
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3030
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3031 MetaspaceShared::set_max_alignment(max_alignment);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3032
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3033 if (DumpSharedSpaces) {
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3034 SharedReadOnlySize = align_size_up(SharedReadOnlySize, max_alignment);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3035 SharedReadWriteSize = align_size_up(SharedReadWriteSize, max_alignment);
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3036 SharedMiscDataSize = align_size_up(SharedMiscDataSize, max_alignment);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3037 SharedMiscCodeSize = align_size_up(SharedMiscCodeSize, max_alignment);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3038
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3039 // Initialize with the sum of the shared space sizes. The read-only
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3040 // and read write metaspace chunks will be allocated out of this and the
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3041 // remainder is the misc code and data chunks.
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3042 cds_total = FileMapInfo::shared_spaces_size();
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3043 cds_total = align_size_up(cds_total, _reserve_alignment);
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3044 _space_list = new VirtualSpaceList(cds_total/wordSize);
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3045 _chunk_manager_metadata = new ChunkManager(SpecializedChunk, SmallChunk, MediumChunk);
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3046
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3047 if (!_space_list->initialization_succeeded()) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3048 vm_exit_during_initialization("Unable to dump shared archive.", NULL);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3049 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3050
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3051 #ifdef _LP64
13000
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
3052 if (cds_total + compressed_class_space_size() > UnscaledClassSpaceMax) {
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3053 vm_exit_during_initialization("Unable to dump shared archive.",
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3054 err_msg("Size of archive (" SIZE_FORMAT ") + compressed class space ("
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3055 SIZE_FORMAT ") == total (" SIZE_FORMAT ") is larger than compressed "
13000
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
3056 "klass limit: " SIZE_FORMAT, cds_total, compressed_class_space_size(),
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
3057 cds_total + compressed_class_space_size(), UnscaledClassSpaceMax));
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3058 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3059
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3060 // Set the compressed klass pointer base so that decoding of these pointers works
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3061 // properly when creating the shared archive.
12226
7944aba7ba41 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 12110
diff changeset
3062 assert(UseCompressedOops && UseCompressedClassPointers,
7944aba7ba41 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 12110
diff changeset
3063 "UseCompressedOops and UseCompressedClassPointers must be set");
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3064 Universe::set_narrow_klass_base((address)_space_list->current_virtual_space()->bottom());
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3065 if (TraceMetavirtualspaceAllocation && Verbose) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3066 gclog_or_tty->print_cr("Setting_narrow_klass_base to Address: " PTR_FORMAT,
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3067 _space_list->current_virtual_space()->bottom());
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3068 }
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3069
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3070 Universe::set_narrow_klass_shift(0);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3071 #endif
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3072
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3073 } else {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3074 // If using shared space, open the file that contains the shared space
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3075 // and map in the memory before initializing the rest of metaspace (so
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3076 // the addresses don't conflict)
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3077 address cds_address = NULL;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3078 if (UseSharedSpaces) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3079 FileMapInfo* mapinfo = new FileMapInfo();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3080 memset(mapinfo, 0, sizeof(FileMapInfo));
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3081
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3082 // Open the shared archive file, read and validate the header. If
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3083 // initialization fails, shared spaces [UseSharedSpaces] are
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3084 // disabled and the file is closed.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3085 // Map in spaces now also
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3086 if (mapinfo->initialize() && MetaspaceShared::map_shared_spaces(mapinfo)) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3087 FileMapInfo::set_current_info(mapinfo);
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3088 cds_total = FileMapInfo::shared_spaces_size();
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3089 cds_address = (address)mapinfo->region_base(0);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3090 } else {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3091 assert(!mapinfo->is_open() && !UseSharedSpaces,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3092 "archive file not closed or shared spaces not disabled.");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3093 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3094 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3095
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3096 #ifdef _LP64
12226
7944aba7ba41 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 12110
diff changeset
3097 // If UseCompressedClassPointers is set then allocate the metaspace area
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3098 // above the heap and above the CDS area (if it exists).
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3099 if (using_class_space()) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3100 if (UseSharedSpaces) {
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3101 char* cds_end = (char*)(cds_address + cds_total);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3102 cds_end = (char *)align_ptr_up(cds_end, _reserve_alignment);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3103 allocate_metaspace_compressed_klass_ptrs(cds_end, cds_address);
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3104 } else {
13000
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
3105 char* base = (char*)align_ptr_up(Universe::heap()->reserved_region().end(), _reserve_alignment);
209aa13ab8c0 8024927: Nashorn performance regression with CompressedOops
coleenp
parents: 12998
diff changeset
3106 allocate_metaspace_compressed_klass_ptrs(base, 0);
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3107 }
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3108 }
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3109 #endif
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3110
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
3111 // Initialize these before initializing the VirtualSpaceList
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3112 _first_chunk_word_size = InitialBootClassLoaderMetaspaceSize / BytesPerWord;
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
3113 _first_chunk_word_size = align_word_size_up(_first_chunk_word_size);
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
3114 // Make the first class chunk bigger than a medium chunk so it's not put
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
3115 // on the medium chunk list. The next chunk will be small and progress
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
3116 // from there. This size calculated by -version.
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
3117 _first_class_chunk_word_size = MIN2((size_t)MediumChunk*6,
12226
7944aba7ba41 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 12110
diff changeset
3118 (CompressedClassSpaceSize/BytesPerWord)*2);
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
3119 _first_class_chunk_word_size = align_word_size_up(_first_class_chunk_word_size);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3120 // Arbitrarily set the initial virtual space to a multiple
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3121 // of the boot class loader size.
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3122 size_t word_size = VIRTUALSPACEMULTIPLIER * _first_chunk_word_size;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3123 word_size = align_size_up(word_size, Metaspace::reserve_alignment_words());
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3124
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3125 // Initialize the list of virtual spaces.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3126 _space_list = new VirtualSpaceList(word_size);
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3127 _chunk_manager_metadata = new ChunkManager(SpecializedChunk, SmallChunk, MediumChunk);
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3128
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3129 if (!_space_list->initialization_succeeded()) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3130 vm_exit_during_initialization("Unable to setup metadata virtual space list.", NULL);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3131 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3132 }
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3133
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3134 MetaspaceGC::initialize();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3135 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3136
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3137 Metachunk* Metaspace::get_initialization_chunk(MetadataType mdtype,
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3138 size_t chunk_word_size,
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3139 size_t chunk_bunch) {
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3140 // Get a chunk from the chunk freelist
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3141 Metachunk* chunk = get_chunk_manager(mdtype)->chunk_freelist_allocate(chunk_word_size);
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3142 if (chunk != NULL) {
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3143 return chunk;
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3144 }
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3145
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3146 return get_space_list(mdtype)->get_new_chunk(chunk_word_size, chunk_word_size, chunk_bunch);
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3147 }
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3148
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3149 void Metaspace::initialize(Mutex* lock, MetaspaceType type) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3150
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3151 assert(space_list() != NULL,
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3152 "Metadata VirtualSpaceList has not been initialized");
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3153 assert(chunk_manager_metadata() != NULL,
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3154 "Metadata ChunkManager has not been initialized");
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3155
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3156 _vsm = new SpaceManager(NonClassType, lock);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3157 if (_vsm == NULL) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3158 return;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3159 }
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
3160 size_t word_size;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
3161 size_t class_word_size;
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3162 vsm()->get_initial_chunk_sizes(type, &word_size, &class_word_size);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3163
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3164 if (using_class_space()) {
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3165 assert(class_space_list() != NULL,
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3166 "Class VirtualSpaceList has not been initialized");
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3167 assert(chunk_manager_class() != NULL,
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3168 "Class ChunkManager has not been initialized");
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3169
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3170 // Allocate SpaceManager for classes.
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3171 _class_vsm = new SpaceManager(ClassType, lock);
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3172 if (_class_vsm == NULL) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3173 return;
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3174 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3175 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3176
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3177 MutexLockerEx cl(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3178
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3179 // Allocate chunk for metadata objects
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3180 Metachunk* new_chunk = get_initialization_chunk(NonClassType,
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3181 word_size,
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3182 vsm()->medium_chunk_bunch());
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3183 assert(!DumpSharedSpaces || new_chunk != NULL, "should have enough space for both chunks");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3184 if (new_chunk != NULL) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3185 // Add to this manager's list of chunks in use and current_chunk().
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3186 vsm()->add_chunk(new_chunk, true);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3187 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3188
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3189 // Allocate chunk for class metadata objects
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3190 if (using_class_space()) {
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3191 Metachunk* class_chunk = get_initialization_chunk(ClassType,
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3192 class_word_size,
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3193 class_vsm()->medium_chunk_bunch());
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3194 if (class_chunk != NULL) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3195 class_vsm()->add_chunk(class_chunk, true);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3196 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3197 }
10376
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3198
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3199 _alloc_record_head = NULL;
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3200 _alloc_record_tail = NULL;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3201 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3202
7446
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
3203 size_t Metaspace::align_word_size_up(size_t word_size) {
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
3204 size_t byte_size = word_size * wordSize;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
3205 return ReservedSpace::allocation_align_size_up(byte_size) / wordSize;
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
3206 }
e51c9860cf66 8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents: 7435
diff changeset
3207
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3208 MetaWord* Metaspace::allocate(size_t word_size, MetadataType mdtype) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3209 // DumpSharedSpaces doesn't use class metadata area (yet)
12226
7944aba7ba41 8015107: NPG: Use consistent naming for metaspace concepts
ehelin
parents: 12110
diff changeset
3210 // Also, don't use class_vsm() unless UseCompressedClassPointers is true.
12340
bc918fd1e584 8025279: metaspace/flags/maxMetaspaceSize throws OOM: out of Compressed Klass space
mgerdin
parents: 12306
diff changeset
3211 if (is_class_space_allocation(mdtype)) {
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
3212 return class_vsm()->allocate(word_size);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3213 } else {
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
3214 return vsm()->allocate(word_size);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3215 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3216 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3217
6753
8da5e203b993 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 6736
diff changeset
3218 MetaWord* Metaspace::expand_and_allocate(size_t word_size, MetadataType mdtype) {
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3219 size_t delta_bytes = MetaspaceGC::delta_capacity_until_GC(word_size * BytesPerWord);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3220 assert(delta_bytes > 0, "Must be");
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3221
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3222 size_t after_inc = MetaspaceGC::inc_capacity_until_GC(delta_bytes);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3223 size_t before_inc = after_inc - delta_bytes;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3224
6753
8da5e203b993 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 6736
diff changeset
3225 if (PrintGCDetails && Verbose) {
8da5e203b993 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 6736
diff changeset
3226 gclog_or_tty->print_cr("Increase capacity to GC from " SIZE_FORMAT
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3227 " to " SIZE_FORMAT, before_inc, after_inc);
6753
8da5e203b993 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 6736
diff changeset
3228 }
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
3229
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3230 return allocate(word_size, mdtype);
6753
8da5e203b993 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 6736
diff changeset
3231 }
8da5e203b993 7197557: NPG: nsk/sysdict/vm/stress/chain/chain004 hangs intermittently
jmasa
parents: 6736
diff changeset
3232
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3233 // Space allocated in the Metaspace. This may
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3234 // be across several metadata virtual spaces.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3235 char* Metaspace::bottom() const {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3236 assert(DumpSharedSpaces, "only useful and valid for dumping shared spaces");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3237 return (char*)vsm()->current_chunk()->bottom();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3238 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3239
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
3240 size_t Metaspace::used_words_slow(MetadataType mdtype) const {
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3241 if (mdtype == ClassType) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3242 return using_class_space() ? class_vsm()->sum_used_in_chunks_in_use() : 0;
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3243 } else {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3244 return vsm()->sum_used_in_chunks_in_use(); // includes overhead!
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3245 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3246 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3247
12235
d6c266999345 8023476: Metaspace capacity > reserved
ehelin
parents: 12231
diff changeset
3248 size_t Metaspace::free_words_slow(MetadataType mdtype) const {
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3249 if (mdtype == ClassType) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3250 return using_class_space() ? class_vsm()->sum_free_in_chunks_in_use() : 0;
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3251 } else {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3252 return vsm()->sum_free_in_chunks_in_use();
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3253 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3254 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3255
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3256 // Space capacity in the Metaspace. It includes
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3257 // space in the list of chunks from which allocations
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3258 // have been made. Don't include space in the global freelist and
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3259 // in the space available in the dictionary which
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3260 // is already counted in some chunk.
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
3261 size_t Metaspace::capacity_words_slow(MetadataType mdtype) const {
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3262 if (mdtype == ClassType) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3263 return using_class_space() ? class_vsm()->sum_capacity_in_chunks_in_use() : 0;
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3264 } else {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3265 return vsm()->sum_capacity_in_chunks_in_use();
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3266 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3267 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3268
10183
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
3269 size_t Metaspace::used_bytes_slow(MetadataType mdtype) const {
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
3270 return used_words_slow(mdtype) * BytesPerWord;
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
3271 }
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
3272
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
3273 size_t Metaspace::capacity_bytes_slow(MetadataType mdtype) const {
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
3274 return capacity_words_slow(mdtype) * BytesPerWord;
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
3275 }
868d87ed63c8 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 10175
diff changeset
3276
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3277 void Metaspace::deallocate(MetaWord* ptr, size_t word_size, bool is_class) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3278 if (SafepointSynchronize::is_at_safepoint()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3279 assert(Thread::current()->is_VM_thread(), "should be the VM thread");
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
3280 // Don't take Heap_lock
10191
601183f604b2 8013129: Possible deadlock with Metaspace locks due to mixed usage of safepoint aware and non-safepoint aware locking
mgerdin
parents: 10183
diff changeset
3281 MutexLockerEx ml(vsm()->lock(), Mutex::_no_safepoint_check_flag);
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
3282 if (word_size < TreeChunk<Metablock, FreeList>::min_size()) {
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
3283 // Dark matter. Too small for dictionary.
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
3284 #ifdef ASSERT
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
3285 Copy::fill_to_words((HeapWord*)ptr, word_size, 0xf5f5f5f5);
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
3286 #endif
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
3287 return;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3288 }
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3289 if (is_class && using_class_space()) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3290 class_vsm()->deallocate(ptr, word_size);
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
3291 } else {
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
3292 vsm()->deallocate(ptr, word_size);
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
3293 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3294 } else {
10191
601183f604b2 8013129: Possible deadlock with Metaspace locks due to mixed usage of safepoint aware and non-safepoint aware locking
mgerdin
parents: 10183
diff changeset
3295 MutexLockerEx ml(vsm()->lock(), Mutex::_no_safepoint_check_flag);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3296
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
3297 if (word_size < TreeChunk<Metablock, FreeList>::min_size()) {
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
3298 // Dark matter. Too small for dictionary.
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
3299 #ifdef ASSERT
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
3300 Copy::fill_to_words((HeapWord*)ptr, word_size, 0xf5f5f5f5);
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
3301 #endif
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
3302 return;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3303 }
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3304 if (is_class && using_class_space()) {
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
3305 class_vsm()->deallocate(ptr, word_size);
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
3306 } else {
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
3307 vsm()->deallocate(ptr, word_size);
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6786
diff changeset
3308 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3309 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3310 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3311
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3312
12902
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
3313 MetaWord* Metaspace::allocate(ClassLoaderData* loader_data, size_t word_size,
10376
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3314 bool read_only, MetaspaceObj::Type type, TRAPS) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3315 if (HAS_PENDING_EXCEPTION) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3316 assert(false, "Should not allocate with exception pending");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3317 return NULL; // caller does a CHECK_NULL too
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3318 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3319
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3320 assert(loader_data != NULL, "Should never pass around a NULL loader_data. "
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3321 "ClassLoaderData::the_null_class_loader_data() should have been used.");
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3322
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3323 // Allocate in metaspaces without taking out a lock, because it deadlocks
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3324 // with the SymbolTable_lock. Dumping is single threaded for now. We'll have
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3325 // to revisit this for application class data sharing.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3326 if (DumpSharedSpaces) {
10376
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3327 assert(type > MetaspaceObj::UnknownType && type < MetaspaceObj::_number_of_types, "sanity");
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3328 Metaspace* space = read_only ? loader_data->ro_metaspace() : loader_data->rw_metaspace();
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3329 MetaWord* result = space->allocate(word_size, NonClassType);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3330 if (result == NULL) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3331 report_out_of_shared_space(read_only ? SharedReadOnly : SharedReadWrite);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3332 }
12902
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
3333
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
3334 space->record_allocation(result, type, space->vsm()->get_raw_word_size(word_size));
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
3335
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
3336 // Zero initialize.
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
3337 Copy::fill_to_aligned_words((HeapWord*)result, word_size, 0);
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
3338
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
3339 return result;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3340 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3341
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3342 MetadataType mdtype = (type == MetaspaceObj::ClassType) ? ClassType : NonClassType;
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3343
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3344 // Try to allocate metadata.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3345 MetaWord* result = loader_data->metaspace_non_null()->allocate(word_size, mdtype);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3346
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3347 if (result == NULL) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3348 // Allocation failed.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3349 if (is_init_completed()) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3350 // Only start a GC if the bootstrapping has completed.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3351
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3352 // Try to clean out some memory and retry.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3353 result = Universe::heap()->collector_policy()->satisfy_failed_metadata_allocation(
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3354 loader_data, word_size, mdtype);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3355 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3356 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3357
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3358 if (result == NULL) {
12980
91a88c8450f4 8026698: Incorrect error handling in Metaspace::allocate
mgerdin
parents: 12979
diff changeset
3359 report_metadata_oome(loader_data, word_size, mdtype, CHECK_NULL);
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3360 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3361
12902
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
3362 // Zero initialize.
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
3363 Copy::fill_to_aligned_words((HeapWord*)result, word_size, 0);
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
3364
bdfbb1fb19ca 8026391: The Metachunk header wastes memory
stefank
parents: 12839
diff changeset
3365 return result;
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3366 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3367
12998
a6177f601c64 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 12906
diff changeset
3368 size_t Metaspace::class_chunk_size(size_t word_size) {
a6177f601c64 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 12906
diff changeset
3369 assert(using_class_space(), "Has to use class space");
a6177f601c64 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 12906
diff changeset
3370 return class_vsm()->calc_chunk_size(word_size);
a6177f601c64 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 12906
diff changeset
3371 }
a6177f601c64 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 12906
diff changeset
3372
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3373 void Metaspace::report_metadata_oome(ClassLoaderData* loader_data, size_t word_size, MetadataType mdtype, TRAPS) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3374 // If result is still null, we are out of memory.
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3375 if (Verbose && TraceMetadataChunkAllocation) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3376 gclog_or_tty->print_cr("Metaspace allocation failed for size "
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3377 SIZE_FORMAT, word_size);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3378 if (loader_data->metaspace_or_null() != NULL) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3379 loader_data->dump(gclog_or_tty);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3380 }
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3381 MetaspaceAux::dump(gclog_or_tty);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3382 }
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3383
12998
a6177f601c64 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 12906
diff changeset
3384 bool out_of_compressed_class_space = false;
a6177f601c64 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 12906
diff changeset
3385 if (is_class_space_allocation(mdtype)) {
a6177f601c64 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 12906
diff changeset
3386 Metaspace* metaspace = loader_data->metaspace_non_null();
a6177f601c64 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 12906
diff changeset
3387 out_of_compressed_class_space =
a6177f601c64 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 12906
diff changeset
3388 MetaspaceAux::committed_bytes(Metaspace::ClassType) +
a6177f601c64 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 12906
diff changeset
3389 (metaspace->class_chunk_size(word_size) * BytesPerWord) >
a6177f601c64 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 12906
diff changeset
3390 CompressedClassSpaceSize;
a6177f601c64 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 12906
diff changeset
3391 }
a6177f601c64 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 12906
diff changeset
3392
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3393 // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support
12998
a6177f601c64 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 12906
diff changeset
3394 const char* space_string = out_of_compressed_class_space ?
a6177f601c64 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 12906
diff changeset
3395 "Compressed class space" : "Metaspace";
a6177f601c64 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 12906
diff changeset
3396
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3397 report_java_out_of_memory(space_string);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3398
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3399 if (JvmtiExport::should_post_resource_exhausted()) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3400 JvmtiExport::post_resource_exhausted(
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3401 JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR,
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3402 space_string);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3403 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3404
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3405 if (!is_init_completed()) {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3406 vm_exit_during_initialization("OutOfMemoryError", space_string);
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3407 }
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3408
12998
a6177f601c64 8026822: metaspace/flags/maxMetaspaceSize throws OOM of unexpected type.java.lang.OutOfMemoryError: Compressed class space
hseigel
parents: 12906
diff changeset
3409 if (out_of_compressed_class_space) {
12838
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3410 THROW_OOP(Universe::out_of_memory_error_class_metaspace());
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3411 } else {
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3412 THROW_OOP(Universe::out_of_memory_error_metaspace());
85c1ca43713f 8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
stefank
parents: 12340
diff changeset
3413 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3414 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3415
10376
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3416 void Metaspace::record_allocation(void* ptr, MetaspaceObj::Type type, size_t word_size) {
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3417 assert(DumpSharedSpaces, "sanity");
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3418
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3419 AllocRecord *rec = new AllocRecord((address)ptr, type, (int)word_size * HeapWordSize);
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3420 if (_alloc_record_head == NULL) {
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3421 _alloc_record_head = _alloc_record_tail = rec;
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3422 } else {
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3423 _alloc_record_tail->_next = rec;
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3424 _alloc_record_tail = rec;
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3425 }
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3426 }
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3427
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3428 void Metaspace::iterate(Metaspace::AllocRecordClosure *closure) {
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3429 assert(DumpSharedSpaces, "unimplemented for !DumpSharedSpaces");
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3430
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3431 address last_addr = (address)bottom();
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3432
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3433 for (AllocRecord *rec = _alloc_record_head; rec; rec = rec->_next) {
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3434 address ptr = rec->_ptr;
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3435 if (last_addr < ptr) {
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3436 closure->doit(last_addr, MetaspaceObj::UnknownType, ptr - last_addr);
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3437 }
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3438 closure->doit(ptr, rec->_type, rec->_byte_size);
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3439 last_addr = ptr + rec->_byte_size;
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3440 }
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3441
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3442 address top = ((address)bottom()) + used_bytes_slow(Metaspace::NonClassType);
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3443 if (last_addr < top) {
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3444 closure->doit(last_addr, MetaspaceObj::UnknownType, top - last_addr);
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3445 }
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3446 }
a1ebd310d5c1 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 10330
diff changeset
3447
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3448 void Metaspace::purge(MetadataType mdtype) {
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3449 get_space_list(mdtype)->purge(get_chunk_manager(mdtype));
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3450 }
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3451
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
3452 void Metaspace::purge() {
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
3453 MutexLockerEx cl(SpaceManager::expand_lock(),
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
3454 Mutex::_no_safepoint_check_flag);
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3455 purge(NonClassType);
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3456 if (using_class_space()) {
12303
b960c9df4f11 8025096: Move the ChunkManager instances out of the VirtualSpaceLists
stefank
parents: 12302
diff changeset
3457 purge(ClassType);
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3458 }
10175
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
3459 }
c23dbf0e8ab7 8011268: NPG: Free unused VirtualSpaceNodes
jmasa
parents: 10101
diff changeset
3460
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3461 void Metaspace::print_on(outputStream* out) const {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3462 // Print both class virtual space counts and metaspace.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3463 if (Verbose) {
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3464 vsm()->print_on(out);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3465 if (using_class_space()) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3466 class_vsm()->print_on(out);
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3467 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3468 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3469 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3470
14190
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
3471 bool Metaspace::contains(const void* ptr) {
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
3472 if (vsm()->contains(ptr)) return true;
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
3473 if (using_class_space()) {
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
3474 return class_vsm()->contains(ptr);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3475 }
14190
ce86c36b8921 8029178: Parallel class loading test anonymous-simple gets SIGSEGV in Metaspace::contains
coleenp
parents: 13068
diff changeset
3476 return false;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3477 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3478
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3479 void Metaspace::verify() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3480 vsm()->verify();
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3481 if (using_class_space()) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3482 class_vsm()->verify();
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3483 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3484 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3485
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3486 void Metaspace::dump(outputStream* const out) const {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3487 out->print_cr("\nVirtual space manager: " INTPTR_FORMAT, vsm());
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3488 vsm()->dump(out);
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3489 if (using_class_space()) {
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3490 out->print_cr("\nClass space manager: " INTPTR_FORMAT, class_vsm());
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3491 class_vsm()->dump(out);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 11966
diff changeset
3492 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
3493 }
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3494
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3495 /////////////// Unit tests ///////////////
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3496
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3497 #ifndef PRODUCT
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3498
12306
03f493ce3a71 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 12303
diff changeset
3499 class TestMetaspaceAuxTest : AllStatic {
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3500 public:
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3501 static void test_reserved() {
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3502 size_t reserved = MetaspaceAux::reserved_bytes();
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3503
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3504 assert(reserved > 0, "assert");
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3505
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3506 size_t committed = MetaspaceAux::committed_bytes();
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3507 assert(committed <= reserved, "assert");
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3508
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3509 size_t reserved_metadata = MetaspaceAux::reserved_bytes(Metaspace::NonClassType);
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3510 assert(reserved_metadata > 0, "assert");
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3511 assert(reserved_metadata <= reserved, "assert");
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3512
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3513 if (UseCompressedClassPointers) {
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3514 size_t reserved_class = MetaspaceAux::reserved_bytes(Metaspace::ClassType);
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3515 assert(reserved_class > 0, "assert");
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3516 assert(reserved_class < reserved, "assert");
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3517 }
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3518 }
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3519
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3520 static void test_committed() {
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3521 size_t committed = MetaspaceAux::committed_bytes();
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3522
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3523 assert(committed > 0, "assert");
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3524
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3525 size_t reserved = MetaspaceAux::reserved_bytes();
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3526 assert(committed <= reserved, "assert");
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3527
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3528 size_t committed_metadata = MetaspaceAux::committed_bytes(Metaspace::NonClassType);
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3529 assert(committed_metadata > 0, "assert");
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3530 assert(committed_metadata <= committed, "assert");
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3531
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3532 if (UseCompressedClassPointers) {
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3533 size_t committed_class = MetaspaceAux::committed_bytes(Metaspace::ClassType);
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3534 assert(committed_class > 0, "assert");
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3535 assert(committed_class < committed, "assert");
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3536 }
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3537 }
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3538
12306
03f493ce3a71 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 12303
diff changeset
3539 static void test_virtual_space_list_large_chunk() {
03f493ce3a71 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 12303
diff changeset
3540 VirtualSpaceList* vs_list = new VirtualSpaceList(os::vm_allocation_granularity());
03f493ce3a71 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 12303
diff changeset
3541 MutexLockerEx cl(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag);
03f493ce3a71 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 12303
diff changeset
3542 // A size larger than VirtualSpaceSize (256k) and add one page to make it _not_ be
03f493ce3a71 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 12303
diff changeset
3543 // vm_allocation_granularity aligned on Windows.
03f493ce3a71 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 12303
diff changeset
3544 size_t large_size = (size_t)(2*256*K + (os::vm_page_size()/BytesPerWord));
03f493ce3a71 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 12303
diff changeset
3545 large_size += (os::vm_page_size()/BytesPerWord);
03f493ce3a71 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 12303
diff changeset
3546 vs_list->get_new_chunk(large_size, large_size, 0);
03f493ce3a71 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 12303
diff changeset
3547 }
03f493ce3a71 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 12303
diff changeset
3548
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3549 static void test() {
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3550 test_reserved();
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3551 test_committed();
12306
03f493ce3a71 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 12303
diff changeset
3552 test_virtual_space_list_large_chunk();
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3553 }
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3554 };
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3555
12306
03f493ce3a71 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 12303
diff changeset
3556 void TestMetaspaceAux_test() {
03f493ce3a71 8025228: assert(new_entry->reserved_words() == vs_word_size) fails in nightly
brutisso
parents: 12303
diff changeset
3557 TestMetaspaceAuxTest::test();
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3558 }
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3559
12979
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3560 class TestVirtualSpaceNodeTest {
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3561 static void chunk_up(size_t words_left, size_t& num_medium_chunks,
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3562 size_t& num_small_chunks,
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3563 size_t& num_specialized_chunks) {
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3564 num_medium_chunks = words_left / MediumChunk;
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3565 words_left = words_left % MediumChunk;
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3566
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3567 num_small_chunks = words_left / SmallChunk;
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3568 words_left = words_left % SmallChunk;
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3569 // how many specialized chunks can we get?
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3570 num_specialized_chunks = words_left / SpecializedChunk;
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3571 assert(words_left % SpecializedChunk == 0, "should be nothing left");
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3572 }
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3573
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3574 public:
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3575 static void test() {
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3576 MutexLockerEx ml(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3577 const size_t vsn_test_size_words = MediumChunk * 4;
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3578 const size_t vsn_test_size_bytes = vsn_test_size_words * BytesPerWord;
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3579
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3580 // The chunk sizes must be multiples of eachother, or this will fail
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3581 STATIC_ASSERT(MediumChunk % SmallChunk == 0);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3582 STATIC_ASSERT(SmallChunk % SpecializedChunk == 0);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3583
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3584 { // No committed memory in VSN
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3585 ChunkManager cm(SpecializedChunk, SmallChunk, MediumChunk);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3586 VirtualSpaceNode vsn(vsn_test_size_bytes);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3587 vsn.initialize();
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3588 vsn.retire(&cm);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3589 assert(cm.sum_free_chunks_count() == 0, "did not commit any memory in the VSN");
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3590 }
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3591
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3592 { // All of VSN is committed, half is used by chunks
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3593 ChunkManager cm(SpecializedChunk, SmallChunk, MediumChunk);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3594 VirtualSpaceNode vsn(vsn_test_size_bytes);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3595 vsn.initialize();
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3596 vsn.expand_by(vsn_test_size_words, vsn_test_size_words);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3597 vsn.get_chunk_vs(MediumChunk);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3598 vsn.get_chunk_vs(MediumChunk);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3599 vsn.retire(&cm);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3600 assert(cm.sum_free_chunks_count() == 2, "should have been memory left for 2 medium chunks");
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3601 assert(cm.sum_free_chunks() == 2*MediumChunk, "sizes should add up");
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3602 }
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3603
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3604 { // 4 pages of VSN is committed, some is used by chunks
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3605 ChunkManager cm(SpecializedChunk, SmallChunk, MediumChunk);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3606 VirtualSpaceNode vsn(vsn_test_size_bytes);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3607 const size_t page_chunks = 4 * (size_t)os::vm_page_size() / BytesPerWord;
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3608 assert(page_chunks < MediumChunk, "Test expects medium chunks to be at least 4*page_size");
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3609 vsn.initialize();
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3610 vsn.expand_by(page_chunks, page_chunks);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3611 vsn.get_chunk_vs(SmallChunk);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3612 vsn.get_chunk_vs(SpecializedChunk);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3613 vsn.retire(&cm);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3614
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3615 // committed - used = words left to retire
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3616 const size_t words_left = page_chunks - SmallChunk - SpecializedChunk;
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3617
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3618 size_t num_medium_chunks, num_small_chunks, num_spec_chunks;
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3619 chunk_up(words_left, num_medium_chunks, num_small_chunks, num_spec_chunks);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3620
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3621 assert(num_medium_chunks == 0, "should not get any medium chunks");
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3622 assert(cm.sum_free_chunks_count() == (num_small_chunks + num_spec_chunks), "should be space for 3 chunks");
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3623 assert(cm.sum_free_chunks() == words_left, "sizes should add up");
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3624 }
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3625
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3626 { // Half of VSN is committed, a humongous chunk is used
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3627 ChunkManager cm(SpecializedChunk, SmallChunk, MediumChunk);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3628 VirtualSpaceNode vsn(vsn_test_size_bytes);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3629 vsn.initialize();
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3630 vsn.expand_by(MediumChunk * 2, MediumChunk * 2);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3631 vsn.get_chunk_vs(MediumChunk + SpecializedChunk); // Humongous chunks will be aligned up to MediumChunk + SpecializedChunk
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3632 vsn.retire(&cm);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3633
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3634 const size_t words_left = MediumChunk * 2 - (MediumChunk + SpecializedChunk);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3635 size_t num_medium_chunks, num_small_chunks, num_spec_chunks;
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3636 chunk_up(words_left, num_medium_chunks, num_small_chunks, num_spec_chunks);
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3637
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3638 assert(num_medium_chunks == 0, "should not get any medium chunks");
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3639 assert(cm.sum_free_chunks_count() == (num_small_chunks + num_spec_chunks), "should be space for 3 chunks");
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3640 assert(cm.sum_free_chunks() == words_left, "sizes should add up");
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3641 }
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3642
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3643 }
14211
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3644
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3645 #define assert_is_available_positive(word_size) \
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3646 assert(vsn.is_available(word_size), \
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3647 err_msg(#word_size ": " PTR_FORMAT " bytes were not available in " \
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3648 "VirtualSpaceNode [" PTR_FORMAT ", " PTR_FORMAT ")", \
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3649 (uintptr_t)(word_size * BytesPerWord), vsn.bottom(), vsn.end()));
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3650
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3651 #define assert_is_available_negative(word_size) \
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3652 assert(!vsn.is_available(word_size), \
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3653 err_msg(#word_size ": " PTR_FORMAT " bytes should not be available in " \
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3654 "VirtualSpaceNode [" PTR_FORMAT ", " PTR_FORMAT ")", \
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3655 (uintptr_t)(word_size * BytesPerWord), vsn.bottom(), vsn.end()));
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3656
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3657 static void test_is_available_positive() {
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3658 // Reserve some memory.
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3659 VirtualSpaceNode vsn(os::vm_allocation_granularity());
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3660 assert(vsn.initialize(), "Failed to setup VirtualSpaceNode");
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3661
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3662 // Commit some memory.
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3663 size_t commit_word_size = os::vm_allocation_granularity() / BytesPerWord;
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3664 bool expanded = vsn.expand_by(commit_word_size, commit_word_size);
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3665 assert(expanded, "Failed to commit");
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3666
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3667 // Check that is_available accepts the committed size.
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3668 assert_is_available_positive(commit_word_size);
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3669
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3670 // Check that is_available accepts half the committed size.
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3671 size_t expand_word_size = commit_word_size / 2;
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3672 assert_is_available_positive(expand_word_size);
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3673 }
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3674
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3675 static void test_is_available_negative() {
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3676 // Reserve some memory.
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3677 VirtualSpaceNode vsn(os::vm_allocation_granularity());
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3678 assert(vsn.initialize(), "Failed to setup VirtualSpaceNode");
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3679
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3680 // Commit some memory.
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3681 size_t commit_word_size = os::vm_allocation_granularity() / BytesPerWord;
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3682 bool expanded = vsn.expand_by(commit_word_size, commit_word_size);
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3683 assert(expanded, "Failed to commit");
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3684
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3685 // Check that is_available doesn't accept a too large size.
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3686 size_t two_times_commit_word_size = commit_word_size * 2;
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3687 assert_is_available_negative(two_times_commit_word_size);
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3688 }
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3689
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3690 static void test_is_available_overflow() {
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3691 // Reserve some memory.
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3692 VirtualSpaceNode vsn(os::vm_allocation_granularity());
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3693 assert(vsn.initialize(), "Failed to setup VirtualSpaceNode");
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3694
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3695 // Commit some memory.
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3696 size_t commit_word_size = os::vm_allocation_granularity() / BytesPerWord;
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3697 bool expanded = vsn.expand_by(commit_word_size, commit_word_size);
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3698 assert(expanded, "Failed to commit");
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3699
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3700 // Calculate a size that will overflow the virtual space size.
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3701 void* virtual_space_max = (void*)(uintptr_t)-1;
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3702 size_t bottom_to_max = pointer_delta(virtual_space_max, vsn.bottom(), 1);
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3703 size_t overflow_size = bottom_to_max + BytesPerWord;
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3704 size_t overflow_word_size = overflow_size / BytesPerWord;
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3705
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3706 // Check that is_available can handle the overflow.
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3707 assert_is_available_negative(overflow_word_size);
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3708 }
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3709
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3710 static void test_is_available() {
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3711 TestVirtualSpaceNodeTest::test_is_available_positive();
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3712 TestVirtualSpaceNodeTest::test_is_available_negative();
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3713 TestVirtualSpaceNodeTest::test_is_available_overflow();
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3714 }
12979
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3715 };
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3716
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3717 void TestVirtualSpaceNode_test() {
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3718 TestVirtualSpaceNodeTest::test();
14211
a2a3f08b96fa 8029106: JVM crashes in Metachunk::Metachunk during parallel class redefinition (PrivateMLetController, anonymous-simple_copy_1)
stefank
parents: 13068
diff changeset
3719 TestVirtualSpaceNodeTest::test_is_available();
12979
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3720 }
1d1ea10fe09f 8015255: NPG: Don't waste fragment at the end of a VirtualSpaceNode before retiring it.
mgerdin
parents: 12906
diff changeset
3721
12236
c4c768305a8f 8024638: Count and expose the amount of committed memory in the metaspaces
stefank
parents: 12235
diff changeset
3722 #endif