author | jmasa |
Mon, 03 Dec 2012 15:09:39 -0800 | |
changeset 15086 | 2bfd799e9147 |
parent 14635 | 6a3c85b8111c |
child 17101 | 3a82a58d9aa9 |
permissions | -rw-r--r-- |
14635
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
1 |
/* |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
2 |
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
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" |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
28 |
#include "utilities/copy.hpp" |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
29 |
#include "utilities/debug.hpp" |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
30 |
|
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
31 |
// |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
32 |
// Future modification |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
33 |
// |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
34 |
// The Metachunk can conceivable be replaced by the Chunk in |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
35 |
// allocation.hpp. Note that the latter Chunk is the space for |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
36 |
// allocation (allocations from the chunk are out of the space in |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
37 |
// the Chunk after the header for the Chunk) where as Metachunks |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
38 |
// point to space in a VirtualSpace. To replace Metachunks with |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
39 |
// Chunks, change Chunks so that they can be allocated out of a VirtualSpace. |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
40 |
|
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
41 |
const size_t metadata_chunk_initialize = 0xf7f7f7f7; |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
42 |
|
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
43 |
size_t Metachunk::_overhead = |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
44 |
Chunk::aligned_overhead_size(sizeof(Metachunk)) / BytesPerWord; |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
45 |
|
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
46 |
// Metachunk methods |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
47 |
|
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
48 |
Metachunk* Metachunk::initialize(MetaWord* ptr, size_t word_size) { |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
49 |
// Set bottom, top, and end. Allow space for the Metachunk itself |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
50 |
Metachunk* chunk = (Metachunk*) ptr; |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
51 |
|
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
52 |
MetaWord* chunk_bottom = ptr + _overhead; |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
53 |
chunk->set_bottom(ptr); |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
54 |
chunk->set_top(chunk_bottom); |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
55 |
MetaWord* chunk_end = ptr + word_size; |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
56 |
assert(chunk_end > chunk_bottom, "Chunk must be too small"); |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
57 |
chunk->set_end(chunk_end); |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
58 |
chunk->set_next(NULL); |
15086
2bfd799e9147
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
14635
diff
changeset
|
59 |
chunk->set_prev(NULL); |
14635
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
60 |
chunk->set_word_size(word_size); |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
61 |
#ifdef ASSERT |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
62 |
size_t data_word_size = pointer_delta(chunk_end, chunk_bottom, sizeof(MetaWord)); |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
63 |
Copy::fill_to_words((HeapWord*) chunk_bottom, data_word_size, metadata_chunk_initialize); |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
64 |
#endif |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
65 |
return chunk; |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
66 |
} |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
67 |
|
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 |
MetaWord* Metachunk::allocate(size_t word_size) { |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
70 |
MetaWord* result = NULL; |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
71 |
// If available, bump the pointer to allocate. |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
72 |
if (free_word_size() >= word_size) { |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
73 |
result = _top; |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
74 |
_top = _top + word_size; |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
75 |
} |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
76 |
return result; |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
77 |
} |
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 |
// _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
|
80 |
size_t Metachunk::used_word_size() const { |
14635
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
81 |
return pointer_delta(_top, _bottom, sizeof(MetaWord)); |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
82 |
} |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
83 |
|
15086
2bfd799e9147
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
14635
diff
changeset
|
84 |
size_t Metachunk::free_word_size() const { |
14635
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
85 |
return pointer_delta(_end, _top, sizeof(MetaWord)); |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
86 |
} |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
87 |
|
15086
2bfd799e9147
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
14635
diff
changeset
|
88 |
size_t Metachunk::capacity_word_size() const { |
14635
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
89 |
return pointer_delta(_end, _bottom, sizeof(MetaWord)); |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
90 |
} |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
91 |
|
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
92 |
void Metachunk::print_on(outputStream* st) const { |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
93 |
st->print_cr("Metachunk:" |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
94 |
" bottom " PTR_FORMAT " top " PTR_FORMAT |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
95 |
" end " PTR_FORMAT " size " SIZE_FORMAT, |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
96 |
bottom(), top(), end(), word_size()); |
15086
2bfd799e9147
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
14635
diff
changeset
|
97 |
if (Verbose) { |
2bfd799e9147
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
14635
diff
changeset
|
98 |
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
|
99 |
used_word_size(), free_word_size()); |
2bfd799e9147
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
14635
diff
changeset
|
100 |
} |
14635
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
101 |
} |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
102 |
|
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
103 |
#ifndef PRODUCT |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
104 |
void Metachunk::mangle() { |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
105 |
// Mangle the payload of the chunk and not the links that |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
106 |
// maintain list of chunks. |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
107 |
HeapWord* start = (HeapWord*)(bottom() + overhead()); |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
108 |
size_t word_size = capacity_word_size() - overhead(); |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
109 |
Copy::fill_to_words(start, word_size, metadata_chunk_initialize); |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
110 |
} |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
111 |
#endif // PRODUCT |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
112 |
|
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
113 |
void Metachunk::verify() { |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
114 |
#ifdef ASSERT |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
115 |
// Cannot walk through the blocks unless the blocks have |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
116 |
// headers with sizes. |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
117 |
assert(_bottom <= _top && |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
118 |
_top <= _end, |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
119 |
"Chunk has been smashed"); |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
120 |
#endif |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
121 |
return; |
6a3c85b8111c
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
122 |
} |