Mercurial > hg > truffle
annotate src/share/vm/memory/metachunk.cpp @ 18134:6a2f814224b1
hotspot/graal: simplify CTW logic. now, the following configurations are supported:
(1) CTW with Graal, graal compiled by itself with bootstrap (--vm graal -XX:+BootstrapGraal -XX:-TieredCompilation -XX:+CompileTheWorld)
(2) CTW with Graal, graal compiled by C1/itself aka. tiered with bootstrap (--vm graal -XX:+BootstrapGraal -XX:+TieredCompilation +XX:+CompileTheWorld)
(3) CTW with Graal, graal compiled by itself without bootstrap (--vm graal -XX:-BootstrapGraal -XX:-TieredCompilation -XX:+CompileTheWorld)
(4) CTW with Graal, graal compiled by C1/itself aka. tiered without bootstrap (--vm graal -XX:-BootstrapGraal -XX:+TieredCompilation -XX:+CompileTheWorld)
(5) CTW with Graal, graal compiled by C1/C2 aka. hosted (--vm server -XX:+CompileTheWorld)
author | Bernhard Urban <bernhard.urban@jku.at> |
---|---|
date | Tue, 21 Oct 2014 10:17:06 +0200 |
parents | 78bbf4d43a14 |
children |
rev | line source |
---|---|
7208
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
1 /* |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
12903
diff
changeset
|
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. |
7208
eade6b2e4782
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. |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
4 * |
eade6b2e4782
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 |
eade6b2e4782
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 |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
8 * |
eade6b2e4782
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 |
eade6b2e4782
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 |
eade6b2e4782
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 |
eade6b2e4782
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 |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
13 * accompanied this code). |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
14 * |
eade6b2e4782
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 |
eade6b2e4782
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, |
eade6b2e4782
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. |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
18 * |
eade6b2e4782
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 |
eade6b2e4782
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 |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
21 * questions. |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
22 * |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
23 */ |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
24 |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
25 #include "precompiled.hpp" |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
26 #include "memory/allocation.hpp" |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
27 #include "memory/metachunk.hpp" |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
28 #include "utilities/copy.hpp" |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
29 #include "utilities/debug.hpp" |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
30 |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
12903
diff
changeset
|
31 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
12903
diff
changeset
|
32 |
10175 | 33 class VirtualSpaceNode; |
7208
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
34 |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
35 const size_t metadata_chunk_initialize = 0xf7f7f7f7; |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
36 |
12902 | 37 size_t Metachunk::object_alignment() { |
12903
ec2e26e26183
8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents:
12902
diff
changeset
|
38 // Must align pointers and sizes to 8, |
ec2e26e26183
8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents:
12902
diff
changeset
|
39 // so that 64 bit types get correctly aligned. |
ec2e26e26183
8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents:
12902
diff
changeset
|
40 const size_t alignment = 8; |
ec2e26e26183
8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents:
12902
diff
changeset
|
41 |
ec2e26e26183
8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents:
12902
diff
changeset
|
42 // Make sure that the Klass alignment also agree. |
ec2e26e26183
8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents:
12902
diff
changeset
|
43 STATIC_ASSERT(alignment == (size_t)KlassAlignmentInBytes); |
ec2e26e26183
8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents:
12902
diff
changeset
|
44 |
ec2e26e26183
8026392: Metachunks and Metablocks are using a too large alignment
stefank
parents:
12902
diff
changeset
|
45 return alignment; |
12902 | 46 } |
47 | |
48 size_t Metachunk::overhead() { | |
49 return align_size_up(sizeof(Metachunk), object_alignment()) / BytesPerWord; | |
50 } | |
7208
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
51 |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
52 // Metachunk methods |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
53 |
10175 | 54 Metachunk::Metachunk(size_t word_size, |
12902 | 55 VirtualSpaceNode* container) |
56 : Metabase<Metachunk>(word_size), | |
10175 | 57 _top(NULL), |
58 _container(container) | |
59 { | |
12902 | 60 _top = initial_top(); |
7208
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
61 #ifdef ASSERT |
12902 | 62 set_is_tagged_free(false); |
10175 | 63 size_t data_word_size = pointer_delta(end(), |
12902 | 64 _top, |
10175 | 65 sizeof(MetaWord)); |
12902 | 66 Copy::fill_to_words((HeapWord*)_top, |
10175 | 67 data_word_size, |
68 metadata_chunk_initialize); | |
7208
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
69 #endif |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
70 } |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
71 |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
72 MetaWord* Metachunk::allocate(size_t word_size) { |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
73 MetaWord* result = NULL; |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
74 // If available, bump the pointer to allocate. |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
75 if (free_word_size() >= word_size) { |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
76 result = _top; |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
77 _top = _top + word_size; |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
78 } |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
79 return result; |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
80 } |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
81 |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
82 // _bottom points to the start of the chunk including the overhead. |
7446
e51c9860cf66
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
7208
diff
changeset
|
83 size_t Metachunk::used_word_size() const { |
12902 | 84 return pointer_delta(_top, bottom(), sizeof(MetaWord)); |
7208
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
85 } |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
86 |
7446
e51c9860cf66
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
7208
diff
changeset
|
87 size_t Metachunk::free_word_size() const { |
12902 | 88 return pointer_delta(end(), _top, sizeof(MetaWord)); |
7208
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
89 } |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
90 |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
91 void Metachunk::print_on(outputStream* st) const { |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
92 st->print_cr("Metachunk:" |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
93 " bottom " PTR_FORMAT " top " PTR_FORMAT |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
94 " end " PTR_FORMAT " size " SIZE_FORMAT, |
12902 | 95 bottom(), _top, end(), word_size()); |
7446
e51c9860cf66
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
7208
diff
changeset
|
96 if (Verbose) { |
e51c9860cf66
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
7208
diff
changeset
|
97 st->print_cr(" used " SIZE_FORMAT " free " SIZE_FORMAT, |
e51c9860cf66
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
7208
diff
changeset
|
98 used_word_size(), free_word_size()); |
e51c9860cf66
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
7208
diff
changeset
|
99 } |
7208
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
100 } |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
101 |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
102 #ifndef PRODUCT |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
103 void Metachunk::mangle() { |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
104 // Mangle the payload of the chunk and not the links that |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
105 // maintain list of chunks. |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
106 HeapWord* start = (HeapWord*)(bottom() + overhead()); |
12902 | 107 size_t size = word_size() - overhead(); |
108 Copy::fill_to_words(start, size, metadata_chunk_initialize); | |
7208
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
109 } |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
110 #endif // PRODUCT |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
111 |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
112 void Metachunk::verify() { |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
113 #ifdef ASSERT |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
114 // Cannot walk through the blocks unless the blocks have |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
115 // headers with sizes. |
12902 | 116 assert(bottom() <= _top && |
117 _top <= (MetaWord*)end(), | |
7208
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
118 "Chunk has been smashed"); |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
119 #endif |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
120 return; |
eade6b2e4782
8003554: NPG: move Metablock and Metachunk code out of metaspace.cpp
jmasa
parents:
diff
changeset
|
121 } |
12902 | 122 |
123 /////////////// Unit tests /////////////// | |
124 | |
125 #ifndef PRODUCT | |
126 | |
127 class TestMetachunk { | |
128 public: | |
129 static void test() { | |
130 size_t size = 2 * 1024 * 1024; | |
131 void* memory = malloc(size); | |
132 assert(memory != NULL, "Failed to malloc 2MB"); | |
133 | |
134 Metachunk* metachunk = ::new (memory) Metachunk(size / BytesPerWord, NULL); | |
135 | |
136 assert(metachunk->bottom() == (MetaWord*)metachunk, "assert"); | |
137 assert(metachunk->end() == (uintptr_t*)metachunk + metachunk->size(), "assert"); | |
138 | |
139 // Check sizes | |
140 assert(metachunk->size() == metachunk->word_size(), "assert"); | |
141 assert(metachunk->word_size() == pointer_delta(metachunk->end(), metachunk->bottom(), | |
142 sizeof(MetaWord*)), "assert"); | |
143 | |
144 // Check usage | |
145 assert(metachunk->used_word_size() == metachunk->overhead(), "assert"); | |
146 assert(metachunk->free_word_size() == metachunk->word_size() - metachunk->used_word_size(), "assert"); | |
147 assert(metachunk->top() == metachunk->initial_top(), "assert"); | |
148 assert(metachunk->is_empty(), "assert"); | |
149 | |
150 // Allocate | |
151 size_t alloc_size = 64; // Words | |
152 assert(is_size_aligned(alloc_size, Metachunk::object_alignment()), "assert"); | |
153 | |
154 MetaWord* mem = metachunk->allocate(alloc_size); | |
155 | |
156 // Check post alloc | |
157 assert(mem == metachunk->initial_top(), "assert"); | |
158 assert(mem + alloc_size == metachunk->top(), "assert"); | |
159 assert(metachunk->used_word_size() == metachunk->overhead() + alloc_size, "assert"); | |
160 assert(metachunk->free_word_size() == metachunk->word_size() - metachunk->used_word_size(), "assert"); | |
161 assert(!metachunk->is_empty(), "assert"); | |
162 | |
163 // Clear chunk | |
164 metachunk->reset_empty(); | |
165 | |
166 // Check post clear | |
167 assert(metachunk->used_word_size() == metachunk->overhead(), "assert"); | |
168 assert(metachunk->free_word_size() == metachunk->word_size() - metachunk->used_word_size(), "assert"); | |
169 assert(metachunk->top() == metachunk->initial_top(), "assert"); | |
170 assert(metachunk->is_empty(), "assert"); | |
171 | |
172 free(memory); | |
173 } | |
174 }; | |
175 | |
176 void TestMetachunk_test() { | |
177 TestMetachunk::test(); | |
178 } | |
179 | |
180 #endif |