author | stuefe |
Tue, 06 Mar 2018 19:24:13 +0100 | |
changeset 49365 | 825f006619e5 |
parent 47808 | 57752bd5d1b4 |
child 50066 | bd3e4517dfa3 |
permissions | -rw-r--r-- |
14635
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
1 |
/* |
42017 | 2 |
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. |
14635
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
4 |
* |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
8 |
* |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
13 |
* accompanied this code). |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
14 |
* |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
18 |
* |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
21 |
* questions. |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
22 |
* |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
23 |
*/ |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
24 |
|
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
25 |
#include "precompiled.hpp" |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
26 |
#include "memory/allocation.hpp" |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
27 |
#include "memory/metachunk.hpp" |
46625 | 28 |
#include "utilities/align.hpp" |
14635
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
29 |
#include "utilities/copy.hpp" |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
30 |
#include "utilities/debug.hpp" |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
31 |
|
17101 | 32 |
class VirtualSpaceNode; |
14635
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
33 |
|
20729 | 34 |
size_t Metachunk::object_alignment() { |
20730
59f433c86d9d
8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents:
20729
diff
changeset
|
35 |
// Must align pointers and sizes to 8, |
59f433c86d9d
8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents:
20729
diff
changeset
|
36 |
// so that 64 bit types get correctly aligned. |
59f433c86d9d
8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents:
20729
diff
changeset
|
37 |
const size_t alignment = 8; |
59f433c86d9d
8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents:
20729
diff
changeset
|
38 |
|
59f433c86d9d
8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents:
20729
diff
changeset
|
39 |
// Make sure that the Klass alignment also agree. |
59f433c86d9d
8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents:
20729
diff
changeset
|
40 |
STATIC_ASSERT(alignment == (size_t)KlassAlignmentInBytes); |
59f433c86d9d
8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents:
20729
diff
changeset
|
41 |
|
59f433c86d9d
8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents:
20729
diff
changeset
|
42 |
return alignment; |
20729 | 43 |
} |
44 |
||
45 |
size_t Metachunk::overhead() { |
|
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
42017
diff
changeset
|
46 |
return align_up(sizeof(Metachunk), object_alignment()) / BytesPerWord; |
20729 | 47 |
} |
14635
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
48 |
|
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
49 |
// Metachunk methods |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
50 |
|
49365 | 51 |
Metachunk::Metachunk(ChunkIndex chunktype, bool is_class, size_t word_size, |
20729 | 52 |
VirtualSpaceNode* container) |
53 |
: Metabase<Metachunk>(word_size), |
|
49365 | 54 |
_chunk_type(chunktype), |
55 |
_is_class(is_class), |
|
56 |
_sentinel(CHUNK_SENTINEL), |
|
57 |
_origin(origin_normal), |
|
58 |
_use_count(0), |
|
17101 | 59 |
_top(NULL), |
60 |
_container(container) |
|
61 |
{ |
|
20729 | 62 |
_top = initial_top(); |
47808
57752bd5d1b4
8189864: Provide an ascii map to visualize metaspace fragmentation
stuefe
parents:
47216
diff
changeset
|
63 |
set_is_tagged_free(false); |
14635
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
64 |
#ifdef ASSERT |
36829
dd6004c32d75
8151623: Zap freed Metaspace chunks in non-product binaries
vlivanov
parents:
29800
diff
changeset
|
65 |
mangle(uninitMetaWordVal); |
49365 | 66 |
verify(); |
14635
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
67 |
#endif |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
68 |
} |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
69 |
|
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
70 |
MetaWord* Metachunk::allocate(size_t word_size) { |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
71 |
MetaWord* result = NULL; |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
72 |
// If available, bump the pointer to allocate. |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
73 |
if (free_word_size() >= word_size) { |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
74 |
result = _top; |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
75 |
_top = _top + word_size; |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
76 |
} |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
77 |
return result; |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
78 |
} |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
79 |
|
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
80 |
// _bottom points to the start of the chunk including the overhead. |
15086
2bfd799e9147
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
14635
diff
changeset
|
81 |
size_t Metachunk::used_word_size() const { |
20729 | 82 |
return pointer_delta(_top, bottom(), sizeof(MetaWord)); |
14635
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
83 |
} |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
84 |
|
15086
2bfd799e9147
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
14635
diff
changeset
|
85 |
size_t Metachunk::free_word_size() const { |
20729 | 86 |
return pointer_delta(end(), _top, sizeof(MetaWord)); |
14635
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
87 |
} |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
88 |
|
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
89 |
void Metachunk::print_on(outputStream* st) const { |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
90 |
st->print_cr("Metachunk:" |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
91 |
" bottom " PTR_FORMAT " top " PTR_FORMAT |
49365 | 92 |
" end " PTR_FORMAT " size " SIZE_FORMAT " (%s)", |
93 |
p2i(bottom()), p2i(_top), p2i(end()), word_size(), |
|
94 |
chunk_size_name(get_chunk_type())); |
|
15086
2bfd799e9147
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
14635
diff
changeset
|
95 |
if (Verbose) { |
2bfd799e9147
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
14635
diff
changeset
|
96 |
st->print_cr(" used " SIZE_FORMAT " free " SIZE_FORMAT, |
2bfd799e9147
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
14635
diff
changeset
|
97 |
used_word_size(), free_word_size()); |
2bfd799e9147
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
14635
diff
changeset
|
98 |
} |
14635
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
99 |
} |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
100 |
|
49365 | 101 |
#ifdef ASSERT |
36829
dd6004c32d75
8151623: Zap freed Metaspace chunks in non-product binaries
vlivanov
parents:
29800
diff
changeset
|
102 |
void Metachunk::mangle(juint word_value) { |
dd6004c32d75
8151623: Zap freed Metaspace chunks in non-product binaries
vlivanov
parents:
29800
diff
changeset
|
103 |
// Overwrite the payload of the chunk and not the links that |
14635
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
104 |
// maintain list of chunks. |
36829
dd6004c32d75
8151623: Zap freed Metaspace chunks in non-product binaries
vlivanov
parents:
29800
diff
changeset
|
105 |
HeapWord* start = (HeapWord*)initial_top(); |
20729 | 106 |
size_t size = word_size() - overhead(); |
36829
dd6004c32d75
8151623: Zap freed Metaspace chunks in non-product binaries
vlivanov
parents:
29800
diff
changeset
|
107 |
Copy::fill_to_words(start, size, word_value); |
14635
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
108 |
} |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
109 |
|
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
110 |
void Metachunk::verify() { |
49365 | 111 |
assert(is_valid_sentinel(), "Chunk " PTR_FORMAT ": sentinel invalid", p2i(this)); |
112 |
const ChunkIndex chunk_type = get_chunk_type(); |
|
113 |
assert(is_valid_chunktype(chunk_type), "Chunk " PTR_FORMAT ": Invalid chunk type.", p2i(this)); |
|
114 |
if (chunk_type != HumongousIndex) { |
|
115 |
assert(word_size() == get_size_for_nonhumongous_chunktype(chunk_type, is_class()), |
|
116 |
"Chunk " PTR_FORMAT ": wordsize " SIZE_FORMAT " does not fit chunk type %s.", |
|
117 |
p2i(this), word_size(), chunk_size_name(chunk_type)); |
|
118 |
} |
|
119 |
assert(is_valid_chunkorigin(get_origin()), "Chunk " PTR_FORMAT ": Invalid chunk origin.", p2i(this)); |
|
120 |
assert(bottom() <= _top && _top <= (MetaWord*)end(), |
|
121 |
"Chunk " PTR_FORMAT ": Chunk top out of chunk bounds.", p2i(this)); |
|
122 |
||
123 |
// For non-humongous chunks, starting address shall be aligned |
|
124 |
// to its chunk size. Humongous chunks start address is |
|
125 |
// aligned to specialized chunk size. |
|
126 |
const size_t required_alignment = |
|
127 |
(chunk_type != HumongousIndex ? word_size() : get_size_for_nonhumongous_chunktype(SpecializedIndex, is_class())) * sizeof(MetaWord); |
|
128 |
assert(is_aligned((address)this, required_alignment), |
|
129 |
"Chunk " PTR_FORMAT ": (size " SIZE_FORMAT ") not aligned to " SIZE_FORMAT ".", |
|
130 |
p2i(this), word_size() * sizeof(MetaWord), required_alignment); |
|
14635
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
131 |
} |
20729 | 132 |
|
49365 | 133 |
#endif // ASSERT |
134 |
||
135 |
// Helper, returns a descriptive name for the given index. |
|
136 |
const char* chunk_size_name(ChunkIndex index) { |
|
137 |
switch (index) { |
|
138 |
case SpecializedIndex: |
|
139 |
return "specialized"; |
|
140 |
case SmallIndex: |
|
141 |
return "small"; |
|
142 |
case MediumIndex: |
|
143 |
return "medium"; |
|
144 |
case HumongousIndex: |
|
145 |
return "humongous"; |
|
146 |
default: |
|
147 |
return "Invalid index"; |
|
148 |
} |
|
149 |
} |