6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "memory/allocation.hpp"
27 #include "memory/metaspace/metachunk.hpp"
28 #include "memory/metaspace/occupancyMap.hpp"
29 #include "memory/metaspace/virtualSpaceNode.hpp"
30 #include "utilities/align.hpp"
31 #include "utilities/copy.hpp"
32 #include "utilities/debug.hpp"
33
34 namespace metaspace {
35
36 size_t Metachunk::object_alignment() {
37 // Must align pointers and sizes to 8,
38 // so that 64 bit types get correctly aligned.
39 const size_t alignment = 8;
40
41 // Make sure that the Klass alignment also agree.
42 STATIC_ASSERT(alignment == (size_t)KlassAlignmentInBytes);
43
44 return alignment;
45 }
116 if (chunk_type != HumongousIndex) {
117 assert(word_size() == get_size_for_nonhumongous_chunktype(chunk_type, is_class()),
118 "Chunk " PTR_FORMAT ": wordsize " SIZE_FORMAT " does not fit chunk type %s.",
119 p2i(this), word_size(), chunk_size_name(chunk_type));
120 }
121 assert(is_valid_chunkorigin(get_origin()), "Chunk " PTR_FORMAT ": Invalid chunk origin.", p2i(this));
122 assert(bottom() <= _top && _top <= (MetaWord*)end(),
123 "Chunk " PTR_FORMAT ": Chunk top out of chunk bounds.", p2i(this));
124
125 // For non-humongous chunks, starting address shall be aligned
126 // to its chunk size. Humongous chunks start address is
127 // aligned to specialized chunk size.
128 const size_t required_alignment =
129 (chunk_type != HumongousIndex ? word_size() : get_size_for_nonhumongous_chunktype(SpecializedIndex, is_class())) * sizeof(MetaWord);
130 assert(is_aligned((address)this, required_alignment),
131 "Chunk " PTR_FORMAT ": (size " SIZE_FORMAT ") not aligned to " SIZE_FORMAT ".",
132 p2i(this), word_size() * sizeof(MetaWord), required_alignment);
133 }
134
135 #endif // ASSERT
136
137 // Helper, returns a descriptive name for the given index.
138 const char* chunk_size_name(ChunkIndex index) {
139 switch (index) {
140 case SpecializedIndex:
141 return "specialized";
142 case SmallIndex:
143 return "small";
144 case MediumIndex:
145 return "medium";
146 case HumongousIndex:
147 return "humongous";
148 default:
149 return "Invalid index";
150 }
151 }
152
153 #ifdef ASSERT
154 void do_verify_chunk(Metachunk* chunk) {
155 guarantee(chunk != NULL, "Sanity");
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "logging/log.hpp"
27 #include "memory/allocation.hpp"
28 #include "memory/metaspace/metachunk.hpp"
29 #include "memory/metaspace/occupancyMap.hpp"
30 #include "memory/metaspace/virtualSpaceNode.hpp"
31 #include "utilities/align.hpp"
32 #include "utilities/copy.hpp"
33 #include "utilities/debug.hpp"
34
35 namespace metaspace {
36
37 size_t Metachunk::object_alignment() {
38 // Must align pointers and sizes to 8,
39 // so that 64 bit types get correctly aligned.
40 const size_t alignment = 8;
41
42 // Make sure that the Klass alignment also agree.
43 STATIC_ASSERT(alignment == (size_t)KlassAlignmentInBytes);
44
45 return alignment;
46 }
117 if (chunk_type != HumongousIndex) {
118 assert(word_size() == get_size_for_nonhumongous_chunktype(chunk_type, is_class()),
119 "Chunk " PTR_FORMAT ": wordsize " SIZE_FORMAT " does not fit chunk type %s.",
120 p2i(this), word_size(), chunk_size_name(chunk_type));
121 }
122 assert(is_valid_chunkorigin(get_origin()), "Chunk " PTR_FORMAT ": Invalid chunk origin.", p2i(this));
123 assert(bottom() <= _top && _top <= (MetaWord*)end(),
124 "Chunk " PTR_FORMAT ": Chunk top out of chunk bounds.", p2i(this));
125
126 // For non-humongous chunks, starting address shall be aligned
127 // to its chunk size. Humongous chunks start address is
128 // aligned to specialized chunk size.
129 const size_t required_alignment =
130 (chunk_type != HumongousIndex ? word_size() : get_size_for_nonhumongous_chunktype(SpecializedIndex, is_class())) * sizeof(MetaWord);
131 assert(is_aligned((address)this, required_alignment),
132 "Chunk " PTR_FORMAT ": (size " SIZE_FORMAT ") not aligned to " SIZE_FORMAT ".",
133 p2i(this), word_size() * sizeof(MetaWord), required_alignment);
134 }
135
136 #endif // ASSERT
137
138 bool Metachunk::calc_uncommit_range(address* start, size_t* len) const {
139 // All but the first page (which contains the header) can be uncommitted
140 if (size() * sizeof(MetaWord) > (size_t)os::vm_page_size()) {
141 address from = align_up((address)initial_top(), os::vm_page_size());
142 address to = align_down((address)end(), os::vm_page_size());
143 if (from < to) {
144 *start = from;
145 *len = to - from;
146 return true;
147 }
148 }
149 return false;
150 }
151
152 bool Metachunk::commit() {
153 bool rc = false;
154 address p = NULL; size_t len = 0;
155 if (calc_uncommit_range(&p, &len)) {
156 rc = os::commit_memory((char*)p, len, false);
157 if (rc) {
158 log_info(gc, metaspace)("Committed chunk " PTR_FORMAT " (payload area from " PTR_FORMAT " to " PTR_FORMAT ")",
159 p2i(this), p2i(p), p2i(p + len));
160 }
161 }
162 return rc;
163 }
164
165 bool Metachunk::uncommit() {
166 bool rc = false;
167 address p = NULL; size_t len = 0;
168 if (calc_uncommit_range(&p, &len)) {
169 rc = os::uncommit_memory((char*)p, len);
170 if (rc) {
171 log_info(gc, metaspace)("Uncommitted chunk " PTR_FORMAT " (payload area from " PTR_FORMAT " to " PTR_FORMAT ")",
172 p2i(this), p2i(p), p2i(p + len));
173 }
174 }
175 return rc;
176 }
177
178 // Helper, returns a descriptive name for the given index.
179 const char* chunk_size_name(ChunkIndex index) {
180 switch (index) {
181 case SpecializedIndex:
182 return "specialized";
183 case SmallIndex:
184 return "small";
185 case MediumIndex:
186 return "medium";
187 case HumongousIndex:
188 return "humongous";
189 default:
190 return "Invalid index";
191 }
192 }
193
194 #ifdef ASSERT
195 void do_verify_chunk(Metachunk* chunk) {
196 guarantee(chunk != NULL, "Sanity");
|