src/share/vm/memory/metaspace.cpp

Thu, 22 Nov 2018 11:02:39 +0800

author
wanghaomin
date
Thu, 22 Nov 2018 11:02:39 +0800
changeset 9268
acf02173a790
parent 9122
024be04bb151
child 9448
73d689add964
permissions
-rw-r--r--

#7856 Compressed class space not allocated in lower regions. [Backport of JDK-8159056]
Reviewed-by: aoqi

aoqi@0 1 /*
mchinnathamb@9064 2 * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24 #include "precompiled.hpp"
aoqi@0 25 #include "gc_interface/collectedHeap.hpp"
aoqi@0 26 #include "memory/allocation.hpp"
aoqi@0 27 #include "memory/binaryTreeDictionary.hpp"
aoqi@0 28 #include "memory/freeList.hpp"
aoqi@0 29 #include "memory/collectorPolicy.hpp"
aoqi@0 30 #include "memory/filemap.hpp"
aoqi@0 31 #include "memory/freeList.hpp"
aoqi@0 32 #include "memory/gcLocker.hpp"
aoqi@0 33 #include "memory/metachunk.hpp"
aoqi@0 34 #include "memory/metaspace.hpp"
aoqi@0 35 #include "memory/metaspaceGCThresholdUpdater.hpp"
aoqi@0 36 #include "memory/metaspaceShared.hpp"
aoqi@0 37 #include "memory/metaspaceTracer.hpp"
aoqi@0 38 #include "memory/resourceArea.hpp"
aoqi@0 39 #include "memory/universe.hpp"
aoqi@0 40 #include "runtime/atomic.inline.hpp"
aoqi@0 41 #include "runtime/globals.hpp"
aoqi@0 42 #include "runtime/init.hpp"
aoqi@0 43 #include "runtime/java.hpp"
aoqi@0 44 #include "runtime/mutex.hpp"
goetz@6911 45 #include "runtime/orderAccess.inline.hpp"
aoqi@0 46 #include "services/memTracker.hpp"
aoqi@0 47 #include "services/memoryService.hpp"
aoqi@0 48 #include "utilities/copy.hpp"
aoqi@0 49 #include "utilities/debug.hpp"
aoqi@0 50
aoqi@0 51 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
aoqi@0 52
aoqi@0 53 typedef BinaryTreeDictionary<Metablock, FreeList<Metablock> > BlockTreeDictionary;
aoqi@0 54 typedef BinaryTreeDictionary<Metachunk, FreeList<Metachunk> > ChunkTreeDictionary;
aoqi@0 55
aoqi@0 56 // Set this constant to enable slow integrity checking of the free chunk lists
aoqi@0 57 const bool metaspace_slow_verify = false;
aoqi@0 58
aoqi@0 59 size_t const allocation_from_dictionary_limit = 4 * K;
aoqi@0 60
aoqi@0 61 MetaWord* last_allocated = 0;
aoqi@0 62
aoqi@0 63 size_t Metaspace::_compressed_class_space_size;
aoqi@0 64 const MetaspaceTracer* Metaspace::_tracer = NULL;
aoqi@0 65
aoqi@0 66 // Used in declarations in SpaceManager and ChunkManager
aoqi@0 67 enum ChunkIndex {
aoqi@0 68 ZeroIndex = 0,
aoqi@0 69 SpecializedIndex = ZeroIndex,
aoqi@0 70 SmallIndex = SpecializedIndex + 1,
aoqi@0 71 MediumIndex = SmallIndex + 1,
aoqi@0 72 HumongousIndex = MediumIndex + 1,
aoqi@0 73 NumberOfFreeLists = 3,
aoqi@0 74 NumberOfInUseLists = 4
aoqi@0 75 };
aoqi@0 76
aoqi@0 77 enum ChunkSizes { // in words.
aoqi@0 78 ClassSpecializedChunk = 128,
aoqi@0 79 SpecializedChunk = 128,
aoqi@0 80 ClassSmallChunk = 256,
aoqi@0 81 SmallChunk = 512,
aoqi@0 82 ClassMediumChunk = 4 * K,
aoqi@0 83 MediumChunk = 8 * K
aoqi@0 84 };
aoqi@0 85
aoqi@0 86 static ChunkIndex next_chunk_index(ChunkIndex i) {
aoqi@0 87 assert(i < NumberOfInUseLists, "Out of bound");
aoqi@0 88 return (ChunkIndex) (i+1);
aoqi@0 89 }
aoqi@0 90
aoqi@0 91 volatile intptr_t MetaspaceGC::_capacity_until_GC = 0;
aoqi@0 92 uint MetaspaceGC::_shrink_factor = 0;
aoqi@0 93 bool MetaspaceGC::_should_concurrent_collect = false;
aoqi@0 94
aoqi@0 95 typedef class FreeList<Metachunk> ChunkList;
aoqi@0 96
aoqi@0 97 // Manages the global free lists of chunks.
aoqi@0 98 class ChunkManager : public CHeapObj<mtInternal> {
aoqi@0 99 friend class TestVirtualSpaceNodeTest;
aoqi@0 100
aoqi@0 101 // Free list of chunks of different sizes.
aoqi@0 102 // SpecializedChunk
aoqi@0 103 // SmallChunk
aoqi@0 104 // MediumChunk
aoqi@0 105 // HumongousChunk
aoqi@0 106 ChunkList _free_chunks[NumberOfFreeLists];
aoqi@0 107
aoqi@0 108 // HumongousChunk
aoqi@0 109 ChunkTreeDictionary _humongous_dictionary;
aoqi@0 110
aoqi@0 111 // ChunkManager in all lists of this type
aoqi@0 112 size_t _free_chunks_total;
aoqi@0 113 size_t _free_chunks_count;
aoqi@0 114
aoqi@0 115 void dec_free_chunks_total(size_t v) {
aoqi@0 116 assert(_free_chunks_count > 0 &&
aoqi@0 117 _free_chunks_total > 0,
aoqi@0 118 "About to go negative");
aoqi@0 119 Atomic::add_ptr(-1, &_free_chunks_count);
aoqi@0 120 jlong minus_v = (jlong) - (jlong) v;
aoqi@0 121 Atomic::add_ptr(minus_v, &_free_chunks_total);
aoqi@0 122 }
aoqi@0 123
aoqi@0 124 // Debug support
aoqi@0 125
aoqi@0 126 size_t sum_free_chunks();
aoqi@0 127 size_t sum_free_chunks_count();
aoqi@0 128
aoqi@0 129 void locked_verify_free_chunks_total();
aoqi@0 130 void slow_locked_verify_free_chunks_total() {
aoqi@0 131 if (metaspace_slow_verify) {
aoqi@0 132 locked_verify_free_chunks_total();
aoqi@0 133 }
aoqi@0 134 }
aoqi@0 135 void locked_verify_free_chunks_count();
aoqi@0 136 void slow_locked_verify_free_chunks_count() {
aoqi@0 137 if (metaspace_slow_verify) {
aoqi@0 138 locked_verify_free_chunks_count();
aoqi@0 139 }
aoqi@0 140 }
aoqi@0 141 void verify_free_chunks_count();
aoqi@0 142
aoqi@0 143 public:
aoqi@0 144
aoqi@0 145 ChunkManager(size_t specialized_size, size_t small_size, size_t medium_size)
aoqi@0 146 : _free_chunks_total(0), _free_chunks_count(0) {
aoqi@0 147 _free_chunks[SpecializedIndex].set_size(specialized_size);
aoqi@0 148 _free_chunks[SmallIndex].set_size(small_size);
aoqi@0 149 _free_chunks[MediumIndex].set_size(medium_size);
aoqi@0 150 }
aoqi@0 151
aoqi@0 152 // add or delete (return) a chunk to the global freelist.
aoqi@0 153 Metachunk* chunk_freelist_allocate(size_t word_size);
aoqi@0 154
aoqi@0 155 // Map a size to a list index assuming that there are lists
aoqi@0 156 // for special, small, medium, and humongous chunks.
mchinnathamb@9064 157 ChunkIndex list_index(size_t size);
aoqi@0 158
aoqi@0 159 // Remove the chunk from its freelist. It is
aoqi@0 160 // expected to be on one of the _free_chunks[] lists.
aoqi@0 161 void remove_chunk(Metachunk* chunk);
aoqi@0 162
aoqi@0 163 // Add the simple linked list of chunks to the freelist of chunks
aoqi@0 164 // of type index.
aoqi@0 165 void return_chunks(ChunkIndex index, Metachunk* chunks);
aoqi@0 166
aoqi@0 167 // Total of the space in the free chunks list
aoqi@0 168 size_t free_chunks_total_words();
aoqi@0 169 size_t free_chunks_total_bytes();
aoqi@0 170
aoqi@0 171 // Number of chunks in the free chunks list
aoqi@0 172 size_t free_chunks_count();
aoqi@0 173
aoqi@0 174 void inc_free_chunks_total(size_t v, size_t count = 1) {
aoqi@0 175 Atomic::add_ptr(count, &_free_chunks_count);
aoqi@0 176 Atomic::add_ptr(v, &_free_chunks_total);
aoqi@0 177 }
aoqi@0 178 ChunkTreeDictionary* humongous_dictionary() {
aoqi@0 179 return &_humongous_dictionary;
aoqi@0 180 }
aoqi@0 181
aoqi@0 182 ChunkList* free_chunks(ChunkIndex index);
aoqi@0 183
aoqi@0 184 // Returns the list for the given chunk word size.
aoqi@0 185 ChunkList* find_free_chunks_list(size_t word_size);
aoqi@0 186
aoqi@0 187 // Remove from a list by size. Selects list based on size of chunk.
aoqi@0 188 Metachunk* free_chunks_get(size_t chunk_word_size);
aoqi@0 189
aoqi@0 190 #define index_bounds_check(index) \
aoqi@0 191 assert(index == SpecializedIndex || \
aoqi@0 192 index == SmallIndex || \
aoqi@0 193 index == MediumIndex || \
aoqi@0 194 index == HumongousIndex, err_msg("Bad index: %d", (int) index))
aoqi@0 195
aoqi@0 196 size_t num_free_chunks(ChunkIndex index) const {
aoqi@0 197 index_bounds_check(index);
aoqi@0 198
aoqi@0 199 if (index == HumongousIndex) {
aoqi@0 200 return _humongous_dictionary.total_free_blocks();
aoqi@0 201 }
aoqi@0 202
aoqi@0 203 ssize_t count = _free_chunks[index].count();
aoqi@0 204 return count == -1 ? 0 : (size_t) count;
aoqi@0 205 }
aoqi@0 206
aoqi@0 207 size_t size_free_chunks_in_bytes(ChunkIndex index) const {
aoqi@0 208 index_bounds_check(index);
aoqi@0 209
aoqi@0 210 size_t word_size = 0;
aoqi@0 211 if (index == HumongousIndex) {
aoqi@0 212 word_size = _humongous_dictionary.total_size();
aoqi@0 213 } else {
aoqi@0 214 const size_t size_per_chunk_in_words = _free_chunks[index].size();
aoqi@0 215 word_size = size_per_chunk_in_words * num_free_chunks(index);
aoqi@0 216 }
aoqi@0 217
aoqi@0 218 return word_size * BytesPerWord;
aoqi@0 219 }
aoqi@0 220
aoqi@0 221 MetaspaceChunkFreeListSummary chunk_free_list_summary() const {
aoqi@0 222 return MetaspaceChunkFreeListSummary(num_free_chunks(SpecializedIndex),
aoqi@0 223 num_free_chunks(SmallIndex),
aoqi@0 224 num_free_chunks(MediumIndex),
aoqi@0 225 num_free_chunks(HumongousIndex),
aoqi@0 226 size_free_chunks_in_bytes(SpecializedIndex),
aoqi@0 227 size_free_chunks_in_bytes(SmallIndex),
aoqi@0 228 size_free_chunks_in_bytes(MediumIndex),
aoqi@0 229 size_free_chunks_in_bytes(HumongousIndex));
aoqi@0 230 }
aoqi@0 231
aoqi@0 232 // Debug support
aoqi@0 233 void verify();
aoqi@0 234 void slow_verify() {
aoqi@0 235 if (metaspace_slow_verify) {
aoqi@0 236 verify();
aoqi@0 237 }
aoqi@0 238 }
aoqi@0 239 void locked_verify();
aoqi@0 240 void slow_locked_verify() {
aoqi@0 241 if (metaspace_slow_verify) {
aoqi@0 242 locked_verify();
aoqi@0 243 }
aoqi@0 244 }
aoqi@0 245 void verify_free_chunks_total();
aoqi@0 246
aoqi@0 247 void locked_print_free_chunks(outputStream* st);
aoqi@0 248 void locked_print_sum_free_chunks(outputStream* st);
aoqi@0 249
aoqi@0 250 void print_on(outputStream* st) const;
aoqi@0 251 };
aoqi@0 252
aoqi@0 253 // Used to manage the free list of Metablocks (a block corresponds
aoqi@0 254 // to the allocation of a quantum of metadata).
aoqi@0 255 class BlockFreelist VALUE_OBJ_CLASS_SPEC {
aoqi@0 256 BlockTreeDictionary* _dictionary;
aoqi@0 257
aoqi@0 258 // Only allocate and split from freelist if the size of the allocation
aoqi@0 259 // is at least 1/4th the size of the available block.
aoqi@0 260 const static int WasteMultiplier = 4;
aoqi@0 261
aoqi@0 262 // Accessors
aoqi@0 263 BlockTreeDictionary* dictionary() const { return _dictionary; }
aoqi@0 264
aoqi@0 265 public:
aoqi@0 266 BlockFreelist();
aoqi@0 267 ~BlockFreelist();
aoqi@0 268
aoqi@0 269 // Get and return a block to the free list
aoqi@0 270 MetaWord* get_block(size_t word_size);
aoqi@0 271 void return_block(MetaWord* p, size_t word_size);
aoqi@0 272
aoqi@0 273 size_t total_size() {
aoqi@0 274 if (dictionary() == NULL) {
aoqi@0 275 return 0;
aoqi@0 276 } else {
aoqi@0 277 return dictionary()->total_size();
aoqi@0 278 }
aoqi@0 279 }
aoqi@0 280
aoqi@0 281 void print_on(outputStream* st) const;
aoqi@0 282 };
aoqi@0 283
aoqi@0 284 // A VirtualSpaceList node.
aoqi@0 285 class VirtualSpaceNode : public CHeapObj<mtClass> {
aoqi@0 286 friend class VirtualSpaceList;
aoqi@0 287
aoqi@0 288 // Link to next VirtualSpaceNode
aoqi@0 289 VirtualSpaceNode* _next;
aoqi@0 290
aoqi@0 291 // total in the VirtualSpace
aoqi@0 292 MemRegion _reserved;
aoqi@0 293 ReservedSpace _rs;
aoqi@0 294 VirtualSpace _virtual_space;
aoqi@0 295 MetaWord* _top;
aoqi@0 296 // count of chunks contained in this VirtualSpace
aoqi@0 297 uintx _container_count;
aoqi@0 298
aoqi@0 299 // Convenience functions to access the _virtual_space
aoqi@0 300 char* low() const { return virtual_space()->low(); }
aoqi@0 301 char* high() const { return virtual_space()->high(); }
aoqi@0 302
aoqi@0 303 // The first Metachunk will be allocated at the bottom of the
aoqi@0 304 // VirtualSpace
aoqi@0 305 Metachunk* first_chunk() { return (Metachunk*) bottom(); }
aoqi@0 306
aoqi@0 307 // Committed but unused space in the virtual space
aoqi@0 308 size_t free_words_in_vs() const;
aoqi@0 309 public:
aoqi@0 310
aoqi@0 311 VirtualSpaceNode(size_t byte_size);
aoqi@0 312 VirtualSpaceNode(ReservedSpace rs) : _top(NULL), _next(NULL), _rs(rs), _container_count(0) {}
aoqi@0 313 ~VirtualSpaceNode();
aoqi@0 314
aoqi@0 315 // Convenience functions for logical bottom and end
aoqi@0 316 MetaWord* bottom() const { return (MetaWord*) _virtual_space.low(); }
aoqi@0 317 MetaWord* end() const { return (MetaWord*) _virtual_space.high(); }
aoqi@0 318
aoqi@0 319 bool contains(const void* ptr) { return ptr >= low() && ptr < high(); }
aoqi@0 320
aoqi@0 321 size_t reserved_words() const { return _virtual_space.reserved_size() / BytesPerWord; }
aoqi@0 322 size_t committed_words() const { return _virtual_space.actual_committed_size() / BytesPerWord; }
aoqi@0 323
aoqi@0 324 bool is_pre_committed() const { return _virtual_space.special(); }
aoqi@0 325
aoqi@0 326 // address of next available space in _virtual_space;
aoqi@0 327 // Accessors
aoqi@0 328 VirtualSpaceNode* next() { return _next; }
aoqi@0 329 void set_next(VirtualSpaceNode* v) { _next = v; }
aoqi@0 330
aoqi@0 331 void set_reserved(MemRegion const v) { _reserved = v; }
aoqi@0 332 void set_top(MetaWord* v) { _top = v; }
aoqi@0 333
aoqi@0 334 // Accessors
aoqi@0 335 MemRegion* reserved() { return &_reserved; }
aoqi@0 336 VirtualSpace* virtual_space() const { return (VirtualSpace*) &_virtual_space; }
aoqi@0 337
aoqi@0 338 // Returns true if "word_size" is available in the VirtualSpace
aoqi@0 339 bool is_available(size_t word_size) { return word_size <= pointer_delta(end(), _top, sizeof(MetaWord)); }
aoqi@0 340
aoqi@0 341 MetaWord* top() const { return _top; }
aoqi@0 342 void inc_top(size_t word_size) { _top += word_size; }
aoqi@0 343
aoqi@0 344 uintx container_count() { return _container_count; }
aoqi@0 345 void inc_container_count();
aoqi@0 346 void dec_container_count();
aoqi@0 347 #ifdef ASSERT
aoqi@0 348 uint container_count_slow();
aoqi@0 349 void verify_container_count();
aoqi@0 350 #endif
aoqi@0 351
aoqi@0 352 // used and capacity in this single entry in the list
aoqi@0 353 size_t used_words_in_vs() const;
aoqi@0 354 size_t capacity_words_in_vs() const;
aoqi@0 355
aoqi@0 356 bool initialize();
aoqi@0 357
aoqi@0 358 // get space from the virtual space
aoqi@0 359 Metachunk* take_from_committed(size_t chunk_word_size);
aoqi@0 360
aoqi@0 361 // Allocate a chunk from the virtual space and return it.
aoqi@0 362 Metachunk* get_chunk_vs(size_t chunk_word_size);
aoqi@0 363
aoqi@0 364 // Expands/shrinks the committed space in a virtual space. Delegates
aoqi@0 365 // to Virtualspace
aoqi@0 366 bool expand_by(size_t min_words, size_t preferred_words);
aoqi@0 367
aoqi@0 368 // In preparation for deleting this node, remove all the chunks
aoqi@0 369 // in the node from any freelist.
aoqi@0 370 void purge(ChunkManager* chunk_manager);
aoqi@0 371
aoqi@0 372 // If an allocation doesn't fit in the current node a new node is created.
aoqi@0 373 // Allocate chunks out of the remaining committed space in this node
aoqi@0 374 // to avoid wasting that memory.
aoqi@0 375 // This always adds up because all the chunk sizes are multiples of
aoqi@0 376 // the smallest chunk size.
aoqi@0 377 void retire(ChunkManager* chunk_manager);
aoqi@0 378
aoqi@0 379 #ifdef ASSERT
aoqi@0 380 // Debug support
aoqi@0 381 void mangle();
aoqi@0 382 #endif
aoqi@0 383
aoqi@0 384 void print_on(outputStream* st) const;
aoqi@0 385 };
aoqi@0 386
aoqi@0 387 #define assert_is_ptr_aligned(ptr, alignment) \
aoqi@0 388 assert(is_ptr_aligned(ptr, alignment), \
aoqi@0 389 err_msg(PTR_FORMAT " is not aligned to " \
aoqi@0 390 SIZE_FORMAT, ptr, alignment))
aoqi@0 391
aoqi@0 392 #define assert_is_size_aligned(size, alignment) \
aoqi@0 393 assert(is_size_aligned(size, alignment), \
aoqi@0 394 err_msg(SIZE_FORMAT " is not aligned to " \
aoqi@0 395 SIZE_FORMAT, size, alignment))
aoqi@0 396
aoqi@0 397
aoqi@0 398 // Decide if large pages should be committed when the memory is reserved.
aoqi@0 399 static bool should_commit_large_pages_when_reserving(size_t bytes) {
aoqi@0 400 if (UseLargePages && UseLargePagesInMetaspace && !os::can_commit_large_page_memory()) {
aoqi@0 401 size_t words = bytes / BytesPerWord;
aoqi@0 402 bool is_class = false; // We never reserve large pages for the class space.
aoqi@0 403 if (MetaspaceGC::can_expand(words, is_class) &&
aoqi@0 404 MetaspaceGC::allowed_expansion() >= words) {
aoqi@0 405 return true;
aoqi@0 406 }
aoqi@0 407 }
aoqi@0 408
aoqi@0 409 return false;
aoqi@0 410 }
aoqi@0 411
aoqi@0 412 // byte_size is the size of the associated virtualspace.
aoqi@0 413 VirtualSpaceNode::VirtualSpaceNode(size_t bytes) : _top(NULL), _next(NULL), _rs(), _container_count(0) {
aoqi@0 414 assert_is_size_aligned(bytes, Metaspace::reserve_alignment());
aoqi@0 415
iklam@7089 416 #if INCLUDE_CDS
aoqi@0 417 // This allocates memory with mmap. For DumpSharedspaces, try to reserve
aoqi@0 418 // configurable address, generally at the top of the Java heap so other
aoqi@0 419 // memory addresses don't conflict.
aoqi@0 420 if (DumpSharedSpaces) {
aoqi@0 421 bool large_pages = false; // No large pages when dumping the CDS archive.
aoqi@0 422 char* shared_base = (char*)align_ptr_up((char*)SharedBaseAddress, Metaspace::reserve_alignment());
aoqi@0 423
aoqi@0 424 _rs = ReservedSpace(bytes, Metaspace::reserve_alignment(), large_pages, shared_base, 0);
aoqi@0 425 if (_rs.is_reserved()) {
aoqi@0 426 assert(shared_base == 0 || _rs.base() == shared_base, "should match");
aoqi@0 427 } else {
aoqi@0 428 // Get a mmap region anywhere if the SharedBaseAddress fails.
aoqi@0 429 _rs = ReservedSpace(bytes, Metaspace::reserve_alignment(), large_pages);
aoqi@0 430 }
aoqi@0 431 MetaspaceShared::set_shared_rs(&_rs);
iklam@7089 432 } else
iklam@7089 433 #endif
iklam@7089 434 {
aoqi@0 435 bool large_pages = should_commit_large_pages_when_reserving(bytes);
aoqi@0 436
aoqi@0 437 _rs = ReservedSpace(bytes, Metaspace::reserve_alignment(), large_pages);
aoqi@0 438 }
aoqi@0 439
aoqi@0 440 if (_rs.is_reserved()) {
aoqi@0 441 assert(_rs.base() != NULL, "Catch if we get a NULL address");
aoqi@0 442 assert(_rs.size() != 0, "Catch if we get a 0 size");
aoqi@0 443 assert_is_ptr_aligned(_rs.base(), Metaspace::reserve_alignment());
aoqi@0 444 assert_is_size_aligned(_rs.size(), Metaspace::reserve_alignment());
aoqi@0 445
aoqi@0 446 MemTracker::record_virtual_memory_type((address)_rs.base(), mtClass);
aoqi@0 447 }
aoqi@0 448 }
aoqi@0 449
aoqi@0 450 void VirtualSpaceNode::purge(ChunkManager* chunk_manager) {
aoqi@0 451 Metachunk* chunk = first_chunk();
aoqi@0 452 Metachunk* invalid_chunk = (Metachunk*) top();
aoqi@0 453 while (chunk < invalid_chunk ) {
aoqi@0 454 assert(chunk->is_tagged_free(), "Should be tagged free");
aoqi@0 455 MetaWord* next = ((MetaWord*)chunk) + chunk->word_size();
aoqi@0 456 chunk_manager->remove_chunk(chunk);
aoqi@0 457 assert(chunk->next() == NULL &&
aoqi@0 458 chunk->prev() == NULL,
aoqi@0 459 "Was not removed from its list");
aoqi@0 460 chunk = (Metachunk*) next;
aoqi@0 461 }
aoqi@0 462 }
aoqi@0 463
aoqi@0 464 #ifdef ASSERT
aoqi@0 465 uint VirtualSpaceNode::container_count_slow() {
aoqi@0 466 uint count = 0;
aoqi@0 467 Metachunk* chunk = first_chunk();
aoqi@0 468 Metachunk* invalid_chunk = (Metachunk*) top();
aoqi@0 469 while (chunk < invalid_chunk ) {
aoqi@0 470 MetaWord* next = ((MetaWord*)chunk) + chunk->word_size();
aoqi@0 471 // Don't count the chunks on the free lists. Those are
aoqi@0 472 // still part of the VirtualSpaceNode but not currently
aoqi@0 473 // counted.
aoqi@0 474 if (!chunk->is_tagged_free()) {
aoqi@0 475 count++;
aoqi@0 476 }
aoqi@0 477 chunk = (Metachunk*) next;
aoqi@0 478 }
aoqi@0 479 return count;
aoqi@0 480 }
aoqi@0 481 #endif
aoqi@0 482
aoqi@0 483 // List of VirtualSpaces for metadata allocation.
aoqi@0 484 class VirtualSpaceList : public CHeapObj<mtClass> {
aoqi@0 485 friend class VirtualSpaceNode;
aoqi@0 486
aoqi@0 487 enum VirtualSpaceSizes {
aoqi@0 488 VirtualSpaceSize = 256 * K
aoqi@0 489 };
aoqi@0 490
aoqi@0 491 // Head of the list
aoqi@0 492 VirtualSpaceNode* _virtual_space_list;
aoqi@0 493 // virtual space currently being used for allocations
aoqi@0 494 VirtualSpaceNode* _current_virtual_space;
aoqi@0 495
aoqi@0 496 // Is this VirtualSpaceList used for the compressed class space
aoqi@0 497 bool _is_class;
aoqi@0 498
aoqi@0 499 // Sum of reserved and committed memory in the virtual spaces
aoqi@0 500 size_t _reserved_words;
aoqi@0 501 size_t _committed_words;
aoqi@0 502
aoqi@0 503 // Number of virtual spaces
aoqi@0 504 size_t _virtual_space_count;
aoqi@0 505
aoqi@0 506 ~VirtualSpaceList();
aoqi@0 507
aoqi@0 508 VirtualSpaceNode* virtual_space_list() const { return _virtual_space_list; }
aoqi@0 509
aoqi@0 510 void set_virtual_space_list(VirtualSpaceNode* v) {
aoqi@0 511 _virtual_space_list = v;
aoqi@0 512 }
aoqi@0 513 void set_current_virtual_space(VirtualSpaceNode* v) {
aoqi@0 514 _current_virtual_space = v;
aoqi@0 515 }
aoqi@0 516
aoqi@0 517 void link_vs(VirtualSpaceNode* new_entry);
aoqi@0 518
aoqi@0 519 // Get another virtual space and add it to the list. This
aoqi@0 520 // is typically prompted by a failed attempt to allocate a chunk
aoqi@0 521 // and is typically followed by the allocation of a chunk.
aoqi@0 522 bool create_new_virtual_space(size_t vs_word_size);
aoqi@0 523
aoqi@0 524 // Chunk up the unused committed space in the current
aoqi@0 525 // virtual space and add the chunks to the free list.
aoqi@0 526 void retire_current_virtual_space();
aoqi@0 527
aoqi@0 528 public:
aoqi@0 529 VirtualSpaceList(size_t word_size);
aoqi@0 530 VirtualSpaceList(ReservedSpace rs);
aoqi@0 531
aoqi@0 532 size_t free_bytes();
aoqi@0 533
mchinnathamb@9058 534 Metachunk* get_new_chunk(size_t chunk_word_size,
mchinnathamb@9058 535 size_t suggested_commit_granularity);
aoqi@0 536
aoqi@0 537 bool expand_node_by(VirtualSpaceNode* node,
aoqi@0 538 size_t min_words,
aoqi@0 539 size_t preferred_words);
aoqi@0 540
aoqi@0 541 bool expand_by(size_t min_words,
aoqi@0 542 size_t preferred_words);
aoqi@0 543
aoqi@0 544 VirtualSpaceNode* current_virtual_space() {
aoqi@0 545 return _current_virtual_space;
aoqi@0 546 }
aoqi@0 547
aoqi@0 548 bool is_class() const { return _is_class; }
aoqi@0 549
aoqi@0 550 bool initialization_succeeded() { return _virtual_space_list != NULL; }
aoqi@0 551
aoqi@0 552 size_t reserved_words() { return _reserved_words; }
aoqi@0 553 size_t reserved_bytes() { return reserved_words() * BytesPerWord; }
aoqi@0 554 size_t committed_words() { return _committed_words; }
aoqi@0 555 size_t committed_bytes() { return committed_words() * BytesPerWord; }
aoqi@0 556
aoqi@0 557 void inc_reserved_words(size_t v);
aoqi@0 558 void dec_reserved_words(size_t v);
aoqi@0 559 void inc_committed_words(size_t v);
aoqi@0 560 void dec_committed_words(size_t v);
aoqi@0 561 void inc_virtual_space_count();
aoqi@0 562 void dec_virtual_space_count();
aoqi@0 563
aoqi@0 564 bool contains(const void* ptr);
aoqi@0 565
aoqi@0 566 // Unlink empty VirtualSpaceNodes and free it.
aoqi@0 567 void purge(ChunkManager* chunk_manager);
aoqi@0 568
aoqi@0 569 void print_on(outputStream* st) const;
aoqi@0 570
aoqi@0 571 class VirtualSpaceListIterator : public StackObj {
aoqi@0 572 VirtualSpaceNode* _virtual_spaces;
aoqi@0 573 public:
aoqi@0 574 VirtualSpaceListIterator(VirtualSpaceNode* virtual_spaces) :
aoqi@0 575 _virtual_spaces(virtual_spaces) {}
aoqi@0 576
aoqi@0 577 bool repeat() {
aoqi@0 578 return _virtual_spaces != NULL;
aoqi@0 579 }
aoqi@0 580
aoqi@0 581 VirtualSpaceNode* get_next() {
aoqi@0 582 VirtualSpaceNode* result = _virtual_spaces;
aoqi@0 583 if (_virtual_spaces != NULL) {
aoqi@0 584 _virtual_spaces = _virtual_spaces->next();
aoqi@0 585 }
aoqi@0 586 return result;
aoqi@0 587 }
aoqi@0 588 };
aoqi@0 589 };
aoqi@0 590
aoqi@0 591 class Metadebug : AllStatic {
aoqi@0 592 // Debugging support for Metaspaces
aoqi@0 593 static int _allocation_fail_alot_count;
aoqi@0 594
aoqi@0 595 public:
aoqi@0 596
aoqi@0 597 static void init_allocation_fail_alot_count();
aoqi@0 598 #ifdef ASSERT
aoqi@0 599 static bool test_metadata_failure();
aoqi@0 600 #endif
aoqi@0 601 };
aoqi@0 602
aoqi@0 603 int Metadebug::_allocation_fail_alot_count = 0;
aoqi@0 604
aoqi@0 605 // SpaceManager - used by Metaspace to handle allocations
aoqi@0 606 class SpaceManager : public CHeapObj<mtClass> {
aoqi@0 607 friend class Metaspace;
aoqi@0 608 friend class Metadebug;
aoqi@0 609
aoqi@0 610 private:
aoqi@0 611
aoqi@0 612 // protects allocations
aoqi@0 613 Mutex* const _lock;
aoqi@0 614
aoqi@0 615 // Type of metadata allocated.
aoqi@0 616 Metaspace::MetadataType _mdtype;
aoqi@0 617
aoqi@0 618 // List of chunks in use by this SpaceManager. Allocations
aoqi@0 619 // are done from the current chunk. The list is used for deallocating
aoqi@0 620 // chunks when the SpaceManager is freed.
aoqi@0 621 Metachunk* _chunks_in_use[NumberOfInUseLists];
aoqi@0 622 Metachunk* _current_chunk;
aoqi@0 623
aoqi@0 624 // Number of small chunks to allocate to a manager
aoqi@0 625 // If class space manager, small chunks are unlimited
aoqi@0 626 static uint const _small_chunk_limit;
aoqi@0 627
aoqi@0 628 // Sum of all space in allocated chunks
aoqi@0 629 size_t _allocated_blocks_words;
aoqi@0 630
aoqi@0 631 // Sum of all allocated chunks
aoqi@0 632 size_t _allocated_chunks_words;
aoqi@0 633 size_t _allocated_chunks_count;
aoqi@0 634
aoqi@0 635 // Free lists of blocks are per SpaceManager since they
aoqi@0 636 // are assumed to be in chunks in use by the SpaceManager
aoqi@0 637 // and all chunks in use by a SpaceManager are freed when
aoqi@0 638 // the class loader using the SpaceManager is collected.
aoqi@0 639 BlockFreelist _block_freelists;
aoqi@0 640
aoqi@0 641 // protects virtualspace and chunk expansions
aoqi@0 642 static const char* _expand_lock_name;
aoqi@0 643 static const int _expand_lock_rank;
aoqi@0 644 static Mutex* const _expand_lock;
aoqi@0 645
aoqi@0 646 private:
aoqi@0 647 // Accessors
aoqi@0 648 Metachunk* chunks_in_use(ChunkIndex index) const { return _chunks_in_use[index]; }
aoqi@0 649 void set_chunks_in_use(ChunkIndex index, Metachunk* v) {
aoqi@0 650 _chunks_in_use[index] = v;
aoqi@0 651 }
aoqi@0 652
aoqi@0 653 BlockFreelist* block_freelists() const {
aoqi@0 654 return (BlockFreelist*) &_block_freelists;
aoqi@0 655 }
aoqi@0 656
aoqi@0 657 Metaspace::MetadataType mdtype() { return _mdtype; }
aoqi@0 658
aoqi@0 659 VirtualSpaceList* vs_list() const { return Metaspace::get_space_list(_mdtype); }
aoqi@0 660 ChunkManager* chunk_manager() const { return Metaspace::get_chunk_manager(_mdtype); }
aoqi@0 661
aoqi@0 662 Metachunk* current_chunk() const { return _current_chunk; }
aoqi@0 663 void set_current_chunk(Metachunk* v) {
aoqi@0 664 _current_chunk = v;
aoqi@0 665 }
aoqi@0 666
aoqi@0 667 Metachunk* find_current_chunk(size_t word_size);
aoqi@0 668
aoqi@0 669 // Add chunk to the list of chunks in use
aoqi@0 670 void add_chunk(Metachunk* v, bool make_current);
aoqi@0 671 void retire_current_chunk();
aoqi@0 672
aoqi@0 673 Mutex* lock() const { return _lock; }
aoqi@0 674
aoqi@0 675 const char* chunk_size_name(ChunkIndex index) const;
aoqi@0 676
aoqi@0 677 protected:
aoqi@0 678 void initialize();
aoqi@0 679
aoqi@0 680 public:
aoqi@0 681 SpaceManager(Metaspace::MetadataType mdtype,
aoqi@0 682 Mutex* lock);
aoqi@0 683 ~SpaceManager();
aoqi@0 684
aoqi@0 685 enum ChunkMultiples {
aoqi@0 686 MediumChunkMultiple = 4
aoqi@0 687 };
aoqi@0 688
mchinnathamb@9058 689 static size_t specialized_chunk_size(bool is_class) { return is_class ? ClassSpecializedChunk : SpecializedChunk; }
mchinnathamb@9058 690 static size_t small_chunk_size(bool is_class) { return is_class ? ClassSmallChunk : SmallChunk; }
mchinnathamb@9058 691 static size_t medium_chunk_size(bool is_class) { return is_class ? ClassMediumChunk : MediumChunk; }
mchinnathamb@9058 692
mchinnathamb@9058 693 static size_t smallest_chunk_size(bool is_class) { return specialized_chunk_size(is_class); }
aoqi@0 694
aoqi@0 695 // Accessors
mchinnathamb@9058 696 bool is_class() const { return _mdtype == Metaspace::ClassType; }
mchinnathamb@9058 697
mchinnathamb@9058 698 size_t specialized_chunk_size() const { return specialized_chunk_size(is_class()); }
mchinnathamb@9058 699 size_t small_chunk_size() const { return small_chunk_size(is_class()); }
mchinnathamb@9058 700 size_t medium_chunk_size() const { return medium_chunk_size(is_class()); }
mchinnathamb@9058 701
mchinnathamb@9058 702 size_t smallest_chunk_size() const { return smallest_chunk_size(is_class()); }
mchinnathamb@9058 703
mchinnathamb@9058 704 size_t medium_chunk_bunch() const { return medium_chunk_size() * MediumChunkMultiple; }
aoqi@0 705
aoqi@0 706 size_t allocated_blocks_words() const { return _allocated_blocks_words; }
aoqi@0 707 size_t allocated_blocks_bytes() const { return _allocated_blocks_words * BytesPerWord; }
aoqi@0 708 size_t allocated_chunks_words() const { return _allocated_chunks_words; }
dbuck@9063 709 size_t allocated_chunks_bytes() const { return _allocated_chunks_words * BytesPerWord; }
aoqi@0 710 size_t allocated_chunks_count() const { return _allocated_chunks_count; }
aoqi@0 711
aoqi@0 712 bool is_humongous(size_t word_size) { return word_size > medium_chunk_size(); }
aoqi@0 713
aoqi@0 714 static Mutex* expand_lock() { return _expand_lock; }
aoqi@0 715
aoqi@0 716 // Increment the per Metaspace and global running sums for Metachunks
aoqi@0 717 // by the given size. This is used when a Metachunk to added to
aoqi@0 718 // the in-use list.
aoqi@0 719 void inc_size_metrics(size_t words);
aoqi@0 720 // Increment the per Metaspace and global running sums Metablocks by the given
aoqi@0 721 // size. This is used when a Metablock is allocated.
aoqi@0 722 void inc_used_metrics(size_t words);
aoqi@0 723 // Delete the portion of the running sums for this SpaceManager. That is,
aoqi@0 724 // the globals running sums for the Metachunks and Metablocks are
aoqi@0 725 // decremented for all the Metachunks in-use by this SpaceManager.
aoqi@0 726 void dec_total_from_size_metrics();
aoqi@0 727
mchinnathamb@9058 728 // Adjust the initial chunk size to match one of the fixed chunk list sizes,
mchinnathamb@9058 729 // or return the unadjusted size if the requested size is humongous.
mchinnathamb@9058 730 static size_t adjust_initial_chunk_size(size_t requested, bool is_class_space);
mchinnathamb@9058 731 size_t adjust_initial_chunk_size(size_t requested) const;
mchinnathamb@9058 732
mchinnathamb@9058 733 // Get the initial chunks size for this metaspace type.
mchinnathamb@9058 734 size_t get_initial_chunk_size(Metaspace::MetaspaceType type) const;
aoqi@0 735
aoqi@0 736 size_t sum_capacity_in_chunks_in_use() const;
aoqi@0 737 size_t sum_used_in_chunks_in_use() const;
aoqi@0 738 size_t sum_free_in_chunks_in_use() const;
aoqi@0 739 size_t sum_waste_in_chunks_in_use() const;
aoqi@0 740 size_t sum_waste_in_chunks_in_use(ChunkIndex index ) const;
aoqi@0 741
aoqi@0 742 size_t sum_count_in_chunks_in_use();
aoqi@0 743 size_t sum_count_in_chunks_in_use(ChunkIndex i);
aoqi@0 744
mchinnathamb@9058 745 Metachunk* get_new_chunk(size_t chunk_word_size);
aoqi@0 746
aoqi@0 747 // Block allocation and deallocation.
aoqi@0 748 // Allocates a block from the current chunk
aoqi@0 749 MetaWord* allocate(size_t word_size);
aoqi@0 750
aoqi@0 751 // Helper for allocations
aoqi@0 752 MetaWord* allocate_work(size_t word_size);
aoqi@0 753
aoqi@0 754 // Returns a block to the per manager freelist
aoqi@0 755 void deallocate(MetaWord* p, size_t word_size);
aoqi@0 756
aoqi@0 757 // Based on the allocation size and a minimum chunk size,
aoqi@0 758 // returned chunk size (for expanding space for chunk allocation).
aoqi@0 759 size_t calc_chunk_size(size_t allocation_word_size);
aoqi@0 760
aoqi@0 761 // Called when an allocation from the current chunk fails.
aoqi@0 762 // Gets a new chunk (may require getting a new virtual space),
aoqi@0 763 // and allocates from that chunk.
aoqi@0 764 MetaWord* grow_and_allocate(size_t word_size);
aoqi@0 765
aoqi@0 766 // Notify memory usage to MemoryService.
aoqi@0 767 void track_metaspace_memory_usage();
aoqi@0 768
aoqi@0 769 // debugging support.
aoqi@0 770
aoqi@0 771 void dump(outputStream* const out) const;
aoqi@0 772 void print_on(outputStream* st) const;
aoqi@0 773 void locked_print_chunks_in_use_on(outputStream* st) const;
aoqi@0 774
aoqi@0 775 void verify();
aoqi@0 776 void verify_chunk_size(Metachunk* chunk);
aoqi@0 777 NOT_PRODUCT(void mangle_freed_chunks();)
aoqi@0 778 #ifdef ASSERT
aoqi@0 779 void verify_allocated_blocks_words();
aoqi@0 780 #endif
aoqi@0 781
aoqi@0 782 size_t get_raw_word_size(size_t word_size) {
aoqi@0 783 size_t byte_size = word_size * BytesPerWord;
aoqi@0 784
aoqi@0 785 size_t raw_bytes_size = MAX2(byte_size, sizeof(Metablock));
aoqi@0 786 raw_bytes_size = align_size_up(raw_bytes_size, Metachunk::object_alignment());
aoqi@0 787
aoqi@0 788 size_t raw_word_size = raw_bytes_size / BytesPerWord;
aoqi@0 789 assert(raw_word_size * BytesPerWord == raw_bytes_size, "Size problem");
aoqi@0 790
aoqi@0 791 return raw_word_size;
aoqi@0 792 }
aoqi@0 793 };
aoqi@0 794
aoqi@0 795 uint const SpaceManager::_small_chunk_limit = 4;
aoqi@0 796
aoqi@0 797 const char* SpaceManager::_expand_lock_name =
aoqi@0 798 "SpaceManager chunk allocation lock";
aoqi@0 799 const int SpaceManager::_expand_lock_rank = Monitor::leaf - 1;
aoqi@0 800 Mutex* const SpaceManager::_expand_lock =
aoqi@0 801 new Mutex(SpaceManager::_expand_lock_rank,
aoqi@0 802 SpaceManager::_expand_lock_name,
aoqi@0 803 Mutex::_allow_vm_block_flag);
aoqi@0 804
aoqi@0 805 void VirtualSpaceNode::inc_container_count() {
aoqi@0 806 assert_lock_strong(SpaceManager::expand_lock());
aoqi@0 807 _container_count++;
aoqi@0 808 assert(_container_count == container_count_slow(),
aoqi@0 809 err_msg("Inconsistency in countainer_count _container_count " SIZE_FORMAT
aoqi@0 810 " container_count_slow() " SIZE_FORMAT,
aoqi@0 811 _container_count, container_count_slow()));
aoqi@0 812 }
aoqi@0 813
aoqi@0 814 void VirtualSpaceNode::dec_container_count() {
aoqi@0 815 assert_lock_strong(SpaceManager::expand_lock());
aoqi@0 816 _container_count--;
aoqi@0 817 }
aoqi@0 818
aoqi@0 819 #ifdef ASSERT
aoqi@0 820 void VirtualSpaceNode::verify_container_count() {
aoqi@0 821 assert(_container_count == container_count_slow(),
aoqi@0 822 err_msg("Inconsistency in countainer_count _container_count " SIZE_FORMAT
aoqi@0 823 " container_count_slow() " SIZE_FORMAT, _container_count, container_count_slow()));
aoqi@0 824 }
aoqi@0 825 #endif
aoqi@0 826
aoqi@0 827 // BlockFreelist methods
aoqi@0 828
aoqi@0 829 BlockFreelist::BlockFreelist() : _dictionary(NULL) {}
aoqi@0 830
aoqi@0 831 BlockFreelist::~BlockFreelist() {
aoqi@0 832 if (_dictionary != NULL) {
aoqi@0 833 if (Verbose && TraceMetadataChunkAllocation) {
aoqi@0 834 _dictionary->print_free_lists(gclog_or_tty);
aoqi@0 835 }
aoqi@0 836 delete _dictionary;
aoqi@0 837 }
aoqi@0 838 }
aoqi@0 839
aoqi@0 840 void BlockFreelist::return_block(MetaWord* p, size_t word_size) {
aoqi@0 841 Metablock* free_chunk = ::new (p) Metablock(word_size);
aoqi@0 842 if (dictionary() == NULL) {
aoqi@0 843 _dictionary = new BlockTreeDictionary();
aoqi@0 844 }
aoqi@0 845 dictionary()->return_chunk(free_chunk);
aoqi@0 846 }
aoqi@0 847
aoqi@0 848 MetaWord* BlockFreelist::get_block(size_t word_size) {
aoqi@0 849 if (dictionary() == NULL) {
aoqi@0 850 return NULL;
aoqi@0 851 }
aoqi@0 852
aoqi@0 853 if (word_size < TreeChunk<Metablock, FreeList<Metablock> >::min_size()) {
aoqi@0 854 // Dark matter. Too small for dictionary.
aoqi@0 855 return NULL;
aoqi@0 856 }
aoqi@0 857
aoqi@0 858 Metablock* free_block =
aoqi@0 859 dictionary()->get_chunk(word_size, FreeBlockDictionary<Metablock>::atLeast);
aoqi@0 860 if (free_block == NULL) {
aoqi@0 861 return NULL;
aoqi@0 862 }
aoqi@0 863
aoqi@0 864 const size_t block_size = free_block->size();
aoqi@0 865 if (block_size > WasteMultiplier * word_size) {
aoqi@0 866 return_block((MetaWord*)free_block, block_size);
aoqi@0 867 return NULL;
aoqi@0 868 }
aoqi@0 869
aoqi@0 870 MetaWord* new_block = (MetaWord*)free_block;
aoqi@0 871 assert(block_size >= word_size, "Incorrect size of block from freelist");
aoqi@0 872 const size_t unused = block_size - word_size;
aoqi@0 873 if (unused >= TreeChunk<Metablock, FreeList<Metablock> >::min_size()) {
aoqi@0 874 return_block(new_block + word_size, unused);
aoqi@0 875 }
aoqi@0 876
aoqi@0 877 return new_block;
aoqi@0 878 }
aoqi@0 879
aoqi@0 880 void BlockFreelist::print_on(outputStream* st) const {
aoqi@0 881 if (dictionary() == NULL) {
aoqi@0 882 return;
aoqi@0 883 }
aoqi@0 884 dictionary()->print_free_lists(st);
aoqi@0 885 }
aoqi@0 886
aoqi@0 887 // VirtualSpaceNode methods
aoqi@0 888
aoqi@0 889 VirtualSpaceNode::~VirtualSpaceNode() {
aoqi@0 890 _rs.release();
aoqi@0 891 #ifdef ASSERT
aoqi@0 892 size_t word_size = sizeof(*this) / BytesPerWord;
aoqi@0 893 Copy::fill_to_words((HeapWord*) this, word_size, 0xf1f1f1f1);
aoqi@0 894 #endif
aoqi@0 895 }
aoqi@0 896
aoqi@0 897 size_t VirtualSpaceNode::used_words_in_vs() const {
aoqi@0 898 return pointer_delta(top(), bottom(), sizeof(MetaWord));
aoqi@0 899 }
aoqi@0 900
aoqi@0 901 // Space committed in the VirtualSpace
aoqi@0 902 size_t VirtualSpaceNode::capacity_words_in_vs() const {
aoqi@0 903 return pointer_delta(end(), bottom(), sizeof(MetaWord));
aoqi@0 904 }
aoqi@0 905
aoqi@0 906 size_t VirtualSpaceNode::free_words_in_vs() const {
aoqi@0 907 return pointer_delta(end(), top(), sizeof(MetaWord));
aoqi@0 908 }
aoqi@0 909
aoqi@0 910 // Allocates the chunk from the virtual space only.
aoqi@0 911 // This interface is also used internally for debugging. Not all
aoqi@0 912 // chunks removed here are necessarily used for allocation.
aoqi@0 913 Metachunk* VirtualSpaceNode::take_from_committed(size_t chunk_word_size) {
aoqi@0 914 // Bottom of the new chunk
aoqi@0 915 MetaWord* chunk_limit = top();
aoqi@0 916 assert(chunk_limit != NULL, "Not safe to call this method");
aoqi@0 917
aoqi@0 918 // The virtual spaces are always expanded by the
aoqi@0 919 // commit granularity to enforce the following condition.
aoqi@0 920 // Without this the is_available check will not work correctly.
aoqi@0 921 assert(_virtual_space.committed_size() == _virtual_space.actual_committed_size(),
aoqi@0 922 "The committed memory doesn't match the expanded memory.");
aoqi@0 923
aoqi@0 924 if (!is_available(chunk_word_size)) {
aoqi@0 925 if (TraceMetadataChunkAllocation) {
aoqi@0 926 gclog_or_tty->print("VirtualSpaceNode::take_from_committed() not available %d words ", chunk_word_size);
aoqi@0 927 // Dump some information about the virtual space that is nearly full
aoqi@0 928 print_on(gclog_or_tty);
aoqi@0 929 }
aoqi@0 930 return NULL;
aoqi@0 931 }
aoqi@0 932
aoqi@0 933 // Take the space (bump top on the current virtual space).
aoqi@0 934 inc_top(chunk_word_size);
aoqi@0 935
aoqi@0 936 // Initialize the chunk
aoqi@0 937 Metachunk* result = ::new (chunk_limit) Metachunk(chunk_word_size, this);
aoqi@0 938 return result;
aoqi@0 939 }
aoqi@0 940
aoqi@0 941
aoqi@0 942 // Expand the virtual space (commit more of the reserved space)
aoqi@0 943 bool VirtualSpaceNode::expand_by(size_t min_words, size_t preferred_words) {
aoqi@0 944 size_t min_bytes = min_words * BytesPerWord;
aoqi@0 945 size_t preferred_bytes = preferred_words * BytesPerWord;
aoqi@0 946
aoqi@0 947 size_t uncommitted = virtual_space()->reserved_size() - virtual_space()->actual_committed_size();
aoqi@0 948
aoqi@0 949 if (uncommitted < min_bytes) {
aoqi@0 950 return false;
aoqi@0 951 }
aoqi@0 952
aoqi@0 953 size_t commit = MIN2(preferred_bytes, uncommitted);
aoqi@0 954 bool result = virtual_space()->expand_by(commit, false);
aoqi@0 955
aoqi@0 956 assert(result, "Failed to commit memory");
aoqi@0 957
aoqi@0 958 return result;
aoqi@0 959 }
aoqi@0 960
aoqi@0 961 Metachunk* VirtualSpaceNode::get_chunk_vs(size_t chunk_word_size) {
aoqi@0 962 assert_lock_strong(SpaceManager::expand_lock());
aoqi@0 963 Metachunk* result = take_from_committed(chunk_word_size);
aoqi@0 964 if (result != NULL) {
aoqi@0 965 inc_container_count();
aoqi@0 966 }
aoqi@0 967 return result;
aoqi@0 968 }
aoqi@0 969
aoqi@0 970 bool VirtualSpaceNode::initialize() {
aoqi@0 971
aoqi@0 972 if (!_rs.is_reserved()) {
aoqi@0 973 return false;
aoqi@0 974 }
aoqi@0 975
aoqi@0 976 // These are necessary restriction to make sure that the virtual space always
aoqi@0 977 // grows in steps of Metaspace::commit_alignment(). If both base and size are
aoqi@0 978 // aligned only the middle alignment of the VirtualSpace is used.
aoqi@0 979 assert_is_ptr_aligned(_rs.base(), Metaspace::commit_alignment());
aoqi@0 980 assert_is_size_aligned(_rs.size(), Metaspace::commit_alignment());
aoqi@0 981
aoqi@0 982 // ReservedSpaces marked as special will have the entire memory
aoqi@0 983 // pre-committed. Setting a committed size will make sure that
aoqi@0 984 // committed_size and actual_committed_size agrees.
aoqi@0 985 size_t pre_committed_size = _rs.special() ? _rs.size() : 0;
aoqi@0 986
aoqi@0 987 bool result = virtual_space()->initialize_with_granularity(_rs, pre_committed_size,
aoqi@0 988 Metaspace::commit_alignment());
aoqi@0 989 if (result) {
aoqi@0 990 assert(virtual_space()->committed_size() == virtual_space()->actual_committed_size(),
aoqi@0 991 "Checking that the pre-committed memory was registered by the VirtualSpace");
aoqi@0 992
aoqi@0 993 set_top((MetaWord*)virtual_space()->low());
aoqi@0 994 set_reserved(MemRegion((HeapWord*)_rs.base(),
aoqi@0 995 (HeapWord*)(_rs.base() + _rs.size())));
aoqi@0 996
aoqi@0 997 assert(reserved()->start() == (HeapWord*) _rs.base(),
aoqi@0 998 err_msg("Reserved start was not set properly " PTR_FORMAT
aoqi@0 999 " != " PTR_FORMAT, reserved()->start(), _rs.base()));
aoqi@0 1000 assert(reserved()->word_size() == _rs.size() / BytesPerWord,
aoqi@0 1001 err_msg("Reserved size was not set properly " SIZE_FORMAT
aoqi@0 1002 " != " SIZE_FORMAT, reserved()->word_size(),
aoqi@0 1003 _rs.size() / BytesPerWord));
aoqi@0 1004 }
aoqi@0 1005
aoqi@0 1006 return result;
aoqi@0 1007 }
aoqi@0 1008
aoqi@0 1009 void VirtualSpaceNode::print_on(outputStream* st) const {
aoqi@0 1010 size_t used = used_words_in_vs();
aoqi@0 1011 size_t capacity = capacity_words_in_vs();
aoqi@0 1012 VirtualSpace* vs = virtual_space();
aoqi@0 1013 st->print_cr(" space @ " PTR_FORMAT " " SIZE_FORMAT "K, %3d%% used "
aoqi@0 1014 "[" PTR_FORMAT ", " PTR_FORMAT ", "
aoqi@0 1015 PTR_FORMAT ", " PTR_FORMAT ")",
aoqi@0 1016 vs, capacity / K,
aoqi@0 1017 capacity == 0 ? 0 : used * 100 / capacity,
aoqi@0 1018 bottom(), top(), end(),
aoqi@0 1019 vs->high_boundary());
aoqi@0 1020 }
aoqi@0 1021
aoqi@0 1022 #ifdef ASSERT
aoqi@0 1023 void VirtualSpaceNode::mangle() {
aoqi@0 1024 size_t word_size = capacity_words_in_vs();
aoqi@0 1025 Copy::fill_to_words((HeapWord*) low(), word_size, 0xf1f1f1f1);
aoqi@0 1026 }
aoqi@0 1027 #endif // ASSERT
aoqi@0 1028
aoqi@0 1029 // VirtualSpaceList methods
aoqi@0 1030 // Space allocated from the VirtualSpace
aoqi@0 1031
aoqi@0 1032 VirtualSpaceList::~VirtualSpaceList() {
aoqi@0 1033 VirtualSpaceListIterator iter(virtual_space_list());
aoqi@0 1034 while (iter.repeat()) {
aoqi@0 1035 VirtualSpaceNode* vsl = iter.get_next();
aoqi@0 1036 delete vsl;
aoqi@0 1037 }
aoqi@0 1038 }
aoqi@0 1039
aoqi@0 1040 void VirtualSpaceList::inc_reserved_words(size_t v) {
aoqi@0 1041 assert_lock_strong(SpaceManager::expand_lock());
aoqi@0 1042 _reserved_words = _reserved_words + v;
aoqi@0 1043 }
aoqi@0 1044 void VirtualSpaceList::dec_reserved_words(size_t v) {
aoqi@0 1045 assert_lock_strong(SpaceManager::expand_lock());
aoqi@0 1046 _reserved_words = _reserved_words - v;
aoqi@0 1047 }
aoqi@0 1048
aoqi@0 1049 #define assert_committed_below_limit() \
aoqi@0 1050 assert(MetaspaceAux::committed_bytes() <= MaxMetaspaceSize, \
aoqi@0 1051 err_msg("Too much committed memory. Committed: " SIZE_FORMAT \
aoqi@0 1052 " limit (MaxMetaspaceSize): " SIZE_FORMAT, \
aoqi@0 1053 MetaspaceAux::committed_bytes(), MaxMetaspaceSize));
aoqi@0 1054
aoqi@0 1055 void VirtualSpaceList::inc_committed_words(size_t v) {
aoqi@0 1056 assert_lock_strong(SpaceManager::expand_lock());
aoqi@0 1057 _committed_words = _committed_words + v;
aoqi@0 1058
aoqi@0 1059 assert_committed_below_limit();
aoqi@0 1060 }
aoqi@0 1061 void VirtualSpaceList::dec_committed_words(size_t v) {
aoqi@0 1062 assert_lock_strong(SpaceManager::expand_lock());
aoqi@0 1063 _committed_words = _committed_words - v;
aoqi@0 1064
aoqi@0 1065 assert_committed_below_limit();
aoqi@0 1066 }
aoqi@0 1067
aoqi@0 1068 void VirtualSpaceList::inc_virtual_space_count() {
aoqi@0 1069 assert_lock_strong(SpaceManager::expand_lock());
aoqi@0 1070 _virtual_space_count++;
aoqi@0 1071 }
aoqi@0 1072 void VirtualSpaceList::dec_virtual_space_count() {
aoqi@0 1073 assert_lock_strong(SpaceManager::expand_lock());
aoqi@0 1074 _virtual_space_count--;
aoqi@0 1075 }
aoqi@0 1076
aoqi@0 1077 void ChunkManager::remove_chunk(Metachunk* chunk) {
aoqi@0 1078 size_t word_size = chunk->word_size();
aoqi@0 1079 ChunkIndex index = list_index(word_size);
aoqi@0 1080 if (index != HumongousIndex) {
aoqi@0 1081 free_chunks(index)->remove_chunk(chunk);
aoqi@0 1082 } else {
aoqi@0 1083 humongous_dictionary()->remove_chunk(chunk);
aoqi@0 1084 }
aoqi@0 1085
aoqi@0 1086 // Chunk is being removed from the chunks free list.
aoqi@0 1087 dec_free_chunks_total(chunk->word_size());
aoqi@0 1088 }
aoqi@0 1089
aoqi@0 1090 // Walk the list of VirtualSpaceNodes and delete
aoqi@0 1091 // nodes with a 0 container_count. Remove Metachunks in
aoqi@0 1092 // the node from their respective freelists.
aoqi@0 1093 void VirtualSpaceList::purge(ChunkManager* chunk_manager) {
aoqi@0 1094 assert(SafepointSynchronize::is_at_safepoint(), "must be called at safepoint for contains to work");
aoqi@0 1095 assert_lock_strong(SpaceManager::expand_lock());
aoqi@0 1096 // Don't use a VirtualSpaceListIterator because this
aoqi@0 1097 // list is being changed and a straightforward use of an iterator is not safe.
aoqi@0 1098 VirtualSpaceNode* purged_vsl = NULL;
aoqi@0 1099 VirtualSpaceNode* prev_vsl = virtual_space_list();
aoqi@0 1100 VirtualSpaceNode* next_vsl = prev_vsl;
aoqi@0 1101 while (next_vsl != NULL) {
aoqi@0 1102 VirtualSpaceNode* vsl = next_vsl;
aoqi@0 1103 next_vsl = vsl->next();
aoqi@0 1104 // Don't free the current virtual space since it will likely
aoqi@0 1105 // be needed soon.
aoqi@0 1106 if (vsl->container_count() == 0 && vsl != current_virtual_space()) {
aoqi@0 1107 // Unlink it from the list
aoqi@0 1108 if (prev_vsl == vsl) {
aoqi@0 1109 // This is the case of the current node being the first node.
aoqi@0 1110 assert(vsl == virtual_space_list(), "Expected to be the first node");
aoqi@0 1111 set_virtual_space_list(vsl->next());
aoqi@0 1112 } else {
aoqi@0 1113 prev_vsl->set_next(vsl->next());
aoqi@0 1114 }
aoqi@0 1115
aoqi@0 1116 vsl->purge(chunk_manager);
aoqi@0 1117 dec_reserved_words(vsl->reserved_words());
aoqi@0 1118 dec_committed_words(vsl->committed_words());
aoqi@0 1119 dec_virtual_space_count();
aoqi@0 1120 purged_vsl = vsl;
aoqi@0 1121 delete vsl;
aoqi@0 1122 } else {
aoqi@0 1123 prev_vsl = vsl;
aoqi@0 1124 }
aoqi@0 1125 }
aoqi@0 1126 #ifdef ASSERT
aoqi@0 1127 if (purged_vsl != NULL) {
aoqi@0 1128 // List should be stable enough to use an iterator here.
aoqi@0 1129 VirtualSpaceListIterator iter(virtual_space_list());
aoqi@0 1130 while (iter.repeat()) {
aoqi@0 1131 VirtualSpaceNode* vsl = iter.get_next();
aoqi@0 1132 assert(vsl != purged_vsl, "Purge of vsl failed");
aoqi@0 1133 }
aoqi@0 1134 }
aoqi@0 1135 #endif
aoqi@0 1136 }
aoqi@0 1137
aoqi@0 1138
aoqi@0 1139 // This function looks at the mmap regions in the metaspace without locking.
aoqi@0 1140 // The chunks are added with store ordering and not deleted except for at
aoqi@0 1141 // unloading time during a safepoint.
aoqi@0 1142 bool VirtualSpaceList::contains(const void* ptr) {
aoqi@0 1143 // List should be stable enough to use an iterator here because removing virtual
aoqi@0 1144 // space nodes is only allowed at a safepoint.
aoqi@0 1145 VirtualSpaceListIterator iter(virtual_space_list());
aoqi@0 1146 while (iter.repeat()) {
aoqi@0 1147 VirtualSpaceNode* vsn = iter.get_next();
aoqi@0 1148 if (vsn->contains(ptr)) {
aoqi@0 1149 return true;
aoqi@0 1150 }
aoqi@0 1151 }
aoqi@0 1152 return false;
aoqi@0 1153 }
aoqi@0 1154
aoqi@0 1155 void VirtualSpaceList::retire_current_virtual_space() {
aoqi@0 1156 assert_lock_strong(SpaceManager::expand_lock());
aoqi@0 1157
aoqi@0 1158 VirtualSpaceNode* vsn = current_virtual_space();
aoqi@0 1159
aoqi@0 1160 ChunkManager* cm = is_class() ? Metaspace::chunk_manager_class() :
aoqi@0 1161 Metaspace::chunk_manager_metadata();
aoqi@0 1162
aoqi@0 1163 vsn->retire(cm);
aoqi@0 1164 }
aoqi@0 1165
aoqi@0 1166 void VirtualSpaceNode::retire(ChunkManager* chunk_manager) {
aoqi@0 1167 for (int i = (int)MediumIndex; i >= (int)ZeroIndex; --i) {
aoqi@0 1168 ChunkIndex index = (ChunkIndex)i;
aoqi@0 1169 size_t chunk_size = chunk_manager->free_chunks(index)->size();
aoqi@0 1170
aoqi@0 1171 while (free_words_in_vs() >= chunk_size) {
aoqi@0 1172 DEBUG_ONLY(verify_container_count();)
aoqi@0 1173 Metachunk* chunk = get_chunk_vs(chunk_size);
aoqi@0 1174 assert(chunk != NULL, "allocation should have been successful");
aoqi@0 1175
aoqi@0 1176 chunk_manager->return_chunks(index, chunk);
aoqi@0 1177 chunk_manager->inc_free_chunks_total(chunk_size);
aoqi@0 1178 DEBUG_ONLY(verify_container_count();)
aoqi@0 1179 }
aoqi@0 1180 }
aoqi@0 1181 assert(free_words_in_vs() == 0, "should be empty now");
aoqi@0 1182 }
aoqi@0 1183
aoqi@0 1184 VirtualSpaceList::VirtualSpaceList(size_t word_size) :
aoqi@0 1185 _is_class(false),
aoqi@0 1186 _virtual_space_list(NULL),
aoqi@0 1187 _current_virtual_space(NULL),
aoqi@0 1188 _reserved_words(0),
aoqi@0 1189 _committed_words(0),
aoqi@0 1190 _virtual_space_count(0) {
aoqi@0 1191 MutexLockerEx cl(SpaceManager::expand_lock(),
aoqi@0 1192 Mutex::_no_safepoint_check_flag);
aoqi@0 1193 create_new_virtual_space(word_size);
aoqi@0 1194 }
aoqi@0 1195
aoqi@0 1196 VirtualSpaceList::VirtualSpaceList(ReservedSpace rs) :
aoqi@0 1197 _is_class(true),
aoqi@0 1198 _virtual_space_list(NULL),
aoqi@0 1199 _current_virtual_space(NULL),
aoqi@0 1200 _reserved_words(0),
aoqi@0 1201 _committed_words(0),
aoqi@0 1202 _virtual_space_count(0) {
aoqi@0 1203 MutexLockerEx cl(SpaceManager::expand_lock(),
aoqi@0 1204 Mutex::_no_safepoint_check_flag);
aoqi@0 1205 VirtualSpaceNode* class_entry = new VirtualSpaceNode(rs);
aoqi@0 1206 bool succeeded = class_entry->initialize();
aoqi@0 1207 if (succeeded) {
aoqi@0 1208 link_vs(class_entry);
aoqi@0 1209 }
aoqi@0 1210 }
aoqi@0 1211
aoqi@0 1212 size_t VirtualSpaceList::free_bytes() {
zgu@9057 1213 return current_virtual_space()->free_words_in_vs() * BytesPerWord;
aoqi@0 1214 }
aoqi@0 1215
aoqi@0 1216 // Allocate another meta virtual space and add it to the list.
aoqi@0 1217 bool VirtualSpaceList::create_new_virtual_space(size_t vs_word_size) {
aoqi@0 1218 assert_lock_strong(SpaceManager::expand_lock());
aoqi@0 1219
aoqi@0 1220 if (is_class()) {
aoqi@0 1221 assert(false, "We currently don't support more than one VirtualSpace for"
aoqi@0 1222 " the compressed class space. The initialization of the"
aoqi@0 1223 " CCS uses another code path and should not hit this path.");
aoqi@0 1224 return false;
aoqi@0 1225 }
aoqi@0 1226
aoqi@0 1227 if (vs_word_size == 0) {
aoqi@0 1228 assert(false, "vs_word_size should always be at least _reserve_alignment large.");
aoqi@0 1229 return false;
aoqi@0 1230 }
aoqi@0 1231
aoqi@0 1232 // Reserve the space
aoqi@0 1233 size_t vs_byte_size = vs_word_size * BytesPerWord;
aoqi@0 1234 assert_is_size_aligned(vs_byte_size, Metaspace::reserve_alignment());
aoqi@0 1235
aoqi@0 1236 // Allocate the meta virtual space and initialize it.
aoqi@0 1237 VirtualSpaceNode* new_entry = new VirtualSpaceNode(vs_byte_size);
aoqi@0 1238 if (!new_entry->initialize()) {
aoqi@0 1239 delete new_entry;
aoqi@0 1240 return false;
aoqi@0 1241 } else {
aoqi@0 1242 assert(new_entry->reserved_words() == vs_word_size,
aoqi@0 1243 "Reserved memory size differs from requested memory size");
aoqi@0 1244 // ensure lock-free iteration sees fully initialized node
aoqi@0 1245 OrderAccess::storestore();
aoqi@0 1246 link_vs(new_entry);
aoqi@0 1247 return true;
aoqi@0 1248 }
aoqi@0 1249 }
aoqi@0 1250
aoqi@0 1251 void VirtualSpaceList::link_vs(VirtualSpaceNode* new_entry) {
aoqi@0 1252 if (virtual_space_list() == NULL) {
aoqi@0 1253 set_virtual_space_list(new_entry);
aoqi@0 1254 } else {
aoqi@0 1255 current_virtual_space()->set_next(new_entry);
aoqi@0 1256 }
aoqi@0 1257 set_current_virtual_space(new_entry);
aoqi@0 1258 inc_reserved_words(new_entry->reserved_words());
aoqi@0 1259 inc_committed_words(new_entry->committed_words());
aoqi@0 1260 inc_virtual_space_count();
aoqi@0 1261 #ifdef ASSERT
aoqi@0 1262 new_entry->mangle();
aoqi@0 1263 #endif
aoqi@0 1264 if (TraceMetavirtualspaceAllocation && Verbose) {
aoqi@0 1265 VirtualSpaceNode* vsl = current_virtual_space();
aoqi@0 1266 vsl->print_on(gclog_or_tty);
aoqi@0 1267 }
aoqi@0 1268 }
aoqi@0 1269
aoqi@0 1270 bool VirtualSpaceList::expand_node_by(VirtualSpaceNode* node,
aoqi@0 1271 size_t min_words,
aoqi@0 1272 size_t preferred_words) {
aoqi@0 1273 size_t before = node->committed_words();
aoqi@0 1274
aoqi@0 1275 bool result = node->expand_by(min_words, preferred_words);
aoqi@0 1276
aoqi@0 1277 size_t after = node->committed_words();
aoqi@0 1278
aoqi@0 1279 // after and before can be the same if the memory was pre-committed.
aoqi@0 1280 assert(after >= before, "Inconsistency");
aoqi@0 1281 inc_committed_words(after - before);
aoqi@0 1282
aoqi@0 1283 return result;
aoqi@0 1284 }
aoqi@0 1285
aoqi@0 1286 bool VirtualSpaceList::expand_by(size_t min_words, size_t preferred_words) {
aoqi@0 1287 assert_is_size_aligned(min_words, Metaspace::commit_alignment_words());
aoqi@0 1288 assert_is_size_aligned(preferred_words, Metaspace::commit_alignment_words());
aoqi@0 1289 assert(min_words <= preferred_words, "Invalid arguments");
aoqi@0 1290
aoqi@0 1291 if (!MetaspaceGC::can_expand(min_words, this->is_class())) {
aoqi@0 1292 return false;
aoqi@0 1293 }
aoqi@0 1294
aoqi@0 1295 size_t allowed_expansion_words = MetaspaceGC::allowed_expansion();
aoqi@0 1296 if (allowed_expansion_words < min_words) {
aoqi@0 1297 return false;
aoqi@0 1298 }
aoqi@0 1299
aoqi@0 1300 size_t max_expansion_words = MIN2(preferred_words, allowed_expansion_words);
aoqi@0 1301
aoqi@0 1302 // Commit more memory from the the current virtual space.
aoqi@0 1303 bool vs_expanded = expand_node_by(current_virtual_space(),
aoqi@0 1304 min_words,
aoqi@0 1305 max_expansion_words);
aoqi@0 1306 if (vs_expanded) {
aoqi@0 1307 return true;
aoqi@0 1308 }
aoqi@0 1309 retire_current_virtual_space();
aoqi@0 1310
aoqi@0 1311 // Get another virtual space.
aoqi@0 1312 size_t grow_vs_words = MAX2((size_t)VirtualSpaceSize, preferred_words);
aoqi@0 1313 grow_vs_words = align_size_up(grow_vs_words, Metaspace::reserve_alignment_words());
aoqi@0 1314
aoqi@0 1315 if (create_new_virtual_space(grow_vs_words)) {
aoqi@0 1316 if (current_virtual_space()->is_pre_committed()) {
aoqi@0 1317 // The memory was pre-committed, so we are done here.
aoqi@0 1318 assert(min_words <= current_virtual_space()->committed_words(),
aoqi@0 1319 "The new VirtualSpace was pre-committed, so it"
aoqi@0 1320 "should be large enough to fit the alloc request.");
aoqi@0 1321 return true;
aoqi@0 1322 }
aoqi@0 1323
aoqi@0 1324 return expand_node_by(current_virtual_space(),
aoqi@0 1325 min_words,
aoqi@0 1326 max_expansion_words);
aoqi@0 1327 }
aoqi@0 1328
aoqi@0 1329 return false;
aoqi@0 1330 }
aoqi@0 1331
mchinnathamb@9058 1332 Metachunk* VirtualSpaceList::get_new_chunk(size_t chunk_word_size, size_t suggested_commit_granularity) {
aoqi@0 1333
aoqi@0 1334 // Allocate a chunk out of the current virtual space.
mchinnathamb@9058 1335 Metachunk* next = current_virtual_space()->get_chunk_vs(chunk_word_size);
aoqi@0 1336
aoqi@0 1337 if (next != NULL) {
aoqi@0 1338 return next;
aoqi@0 1339 }
aoqi@0 1340
aoqi@0 1341 // The expand amount is currently only determined by the requested sizes
aoqi@0 1342 // and not how much committed memory is left in the current virtual space.
aoqi@0 1343
mchinnathamb@9058 1344 size_t min_word_size = align_size_up(chunk_word_size, Metaspace::commit_alignment_words());
mchinnathamb@9058 1345 size_t preferred_word_size = align_size_up(suggested_commit_granularity, Metaspace::commit_alignment_words());
aoqi@0 1346 if (min_word_size >= preferred_word_size) {
aoqi@0 1347 // Can happen when humongous chunks are allocated.
aoqi@0 1348 preferred_word_size = min_word_size;
aoqi@0 1349 }
aoqi@0 1350
aoqi@0 1351 bool expanded = expand_by(min_word_size, preferred_word_size);
aoqi@0 1352 if (expanded) {
mchinnathamb@9058 1353 next = current_virtual_space()->get_chunk_vs(chunk_word_size);
aoqi@0 1354 assert(next != NULL, "The allocation was expected to succeed after the expansion");
aoqi@0 1355 }
aoqi@0 1356
aoqi@0 1357 return next;
aoqi@0 1358 }
aoqi@0 1359
aoqi@0 1360 void VirtualSpaceList::print_on(outputStream* st) const {
aoqi@0 1361 if (TraceMetadataChunkAllocation && Verbose) {
aoqi@0 1362 VirtualSpaceListIterator iter(virtual_space_list());
aoqi@0 1363 while (iter.repeat()) {
aoqi@0 1364 VirtualSpaceNode* node = iter.get_next();
aoqi@0 1365 node->print_on(st);
aoqi@0 1366 }
aoqi@0 1367 }
aoqi@0 1368 }
aoqi@0 1369
aoqi@0 1370 // MetaspaceGC methods
aoqi@0 1371
aoqi@0 1372 // VM_CollectForMetadataAllocation is the vm operation used to GC.
aoqi@0 1373 // Within the VM operation after the GC the attempt to allocate the metadata
aoqi@0 1374 // should succeed. If the GC did not free enough space for the metaspace
aoqi@0 1375 // allocation, the HWM is increased so that another virtualspace will be
aoqi@0 1376 // allocated for the metadata. With perm gen the increase in the perm
aoqi@0 1377 // gen had bounds, MinMetaspaceExpansion and MaxMetaspaceExpansion. The
aoqi@0 1378 // metaspace policy uses those as the small and large steps for the HWM.
aoqi@0 1379 //
aoqi@0 1380 // After the GC the compute_new_size() for MetaspaceGC is called to
aoqi@0 1381 // resize the capacity of the metaspaces. The current implementation
aoqi@0 1382 // is based on the flags MinMetaspaceFreeRatio and MaxMetaspaceFreeRatio used
aoqi@0 1383 // to resize the Java heap by some GC's. New flags can be implemented
aoqi@0 1384 // if really needed. MinMetaspaceFreeRatio is used to calculate how much
aoqi@0 1385 // free space is desirable in the metaspace capacity to decide how much
aoqi@0 1386 // to increase the HWM. MaxMetaspaceFreeRatio is used to decide how much
aoqi@0 1387 // free space is desirable in the metaspace capacity before decreasing
aoqi@0 1388 // the HWM.
aoqi@0 1389
aoqi@0 1390 // Calculate the amount to increase the high water mark (HWM).
aoqi@0 1391 // Increase by a minimum amount (MinMetaspaceExpansion) so that
aoqi@0 1392 // another expansion is not requested too soon. If that is not
aoqi@0 1393 // enough to satisfy the allocation, increase by MaxMetaspaceExpansion.
aoqi@0 1394 // If that is still not enough, expand by the size of the allocation
aoqi@0 1395 // plus some.
aoqi@0 1396 size_t MetaspaceGC::delta_capacity_until_GC(size_t bytes) {
aoqi@0 1397 size_t min_delta = MinMetaspaceExpansion;
aoqi@0 1398 size_t max_delta = MaxMetaspaceExpansion;
aoqi@0 1399 size_t delta = align_size_up(bytes, Metaspace::commit_alignment());
aoqi@0 1400
aoqi@0 1401 if (delta <= min_delta) {
aoqi@0 1402 delta = min_delta;
aoqi@0 1403 } else if (delta <= max_delta) {
aoqi@0 1404 // Don't want to hit the high water mark on the next
aoqi@0 1405 // allocation so make the delta greater than just enough
aoqi@0 1406 // for this allocation.
aoqi@0 1407 delta = max_delta;
aoqi@0 1408 } else {
aoqi@0 1409 // This allocation is large but the next ones are probably not
aoqi@0 1410 // so increase by the minimum.
aoqi@0 1411 delta = delta + min_delta;
aoqi@0 1412 }
aoqi@0 1413
aoqi@0 1414 assert_is_size_aligned(delta, Metaspace::commit_alignment());
aoqi@0 1415
aoqi@0 1416 return delta;
aoqi@0 1417 }
aoqi@0 1418
aoqi@0 1419 size_t MetaspaceGC::capacity_until_GC() {
aoqi@0 1420 size_t value = (size_t)OrderAccess::load_ptr_acquire(&_capacity_until_GC);
aoqi@0 1421 assert(value >= MetaspaceSize, "Not initialied properly?");
aoqi@0 1422 return value;
aoqi@0 1423 }
aoqi@0 1424
ehelin@7254 1425 bool MetaspaceGC::inc_capacity_until_GC(size_t v, size_t* new_cap_until_GC, size_t* old_cap_until_GC) {
aoqi@0 1426 assert_is_size_aligned(v, Metaspace::commit_alignment());
aoqi@0 1427
ehelin@7254 1428 size_t capacity_until_GC = (size_t) _capacity_until_GC;
ehelin@7254 1429 size_t new_value = capacity_until_GC + v;
ehelin@7254 1430
ehelin@7254 1431 if (new_value < capacity_until_GC) {
ehelin@7254 1432 // The addition wrapped around, set new_value to aligned max value.
ehelin@7254 1433 new_value = align_size_down(max_uintx, Metaspace::commit_alignment());
ehelin@7254 1434 }
ehelin@7254 1435
ehelin@7254 1436 intptr_t expected = (intptr_t) capacity_until_GC;
ehelin@7254 1437 intptr_t actual = Atomic::cmpxchg_ptr((intptr_t) new_value, &_capacity_until_GC, expected);
ehelin@7254 1438
ehelin@7254 1439 if (expected != actual) {
ehelin@7254 1440 return false;
ehelin@7254 1441 }
ehelin@7254 1442
ehelin@7254 1443 if (new_cap_until_GC != NULL) {
ehelin@7254 1444 *new_cap_until_GC = new_value;
ehelin@7254 1445 }
ehelin@7254 1446 if (old_cap_until_GC != NULL) {
ehelin@7254 1447 *old_cap_until_GC = capacity_until_GC;
ehelin@7254 1448 }
ehelin@7254 1449 return true;
aoqi@0 1450 }
aoqi@0 1451
aoqi@0 1452 size_t MetaspaceGC::dec_capacity_until_GC(size_t v) {
aoqi@0 1453 assert_is_size_aligned(v, Metaspace::commit_alignment());
aoqi@0 1454
aoqi@0 1455 return (size_t)Atomic::add_ptr(-(intptr_t)v, &_capacity_until_GC);
aoqi@0 1456 }
aoqi@0 1457
aoqi@0 1458 void MetaspaceGC::initialize() {
aoqi@0 1459 // Set the high-water mark to MaxMetapaceSize during VM initializaton since
aoqi@0 1460 // we can't do a GC during initialization.
aoqi@0 1461 _capacity_until_GC = MaxMetaspaceSize;
aoqi@0 1462 }
aoqi@0 1463
aoqi@0 1464 void MetaspaceGC::post_initialize() {
aoqi@0 1465 // Reset the high-water mark once the VM initialization is done.
aoqi@0 1466 _capacity_until_GC = MAX2(MetaspaceAux::committed_bytes(), MetaspaceSize);
aoqi@0 1467 }
aoqi@0 1468
aoqi@0 1469 bool MetaspaceGC::can_expand(size_t word_size, bool is_class) {
aoqi@0 1470 // Check if the compressed class space is full.
aoqi@0 1471 if (is_class && Metaspace::using_class_space()) {
aoqi@0 1472 size_t class_committed = MetaspaceAux::committed_bytes(Metaspace::ClassType);
aoqi@0 1473 if (class_committed + word_size * BytesPerWord > CompressedClassSpaceSize) {
aoqi@0 1474 return false;
aoqi@0 1475 }
aoqi@0 1476 }
aoqi@0 1477
aoqi@0 1478 // Check if the user has imposed a limit on the metaspace memory.
aoqi@0 1479 size_t committed_bytes = MetaspaceAux::committed_bytes();
aoqi@0 1480 if (committed_bytes + word_size * BytesPerWord > MaxMetaspaceSize) {
aoqi@0 1481 return false;
aoqi@0 1482 }
aoqi@0 1483
aoqi@0 1484 return true;
aoqi@0 1485 }
aoqi@0 1486
aoqi@0 1487 size_t MetaspaceGC::allowed_expansion() {
aoqi@0 1488 size_t committed_bytes = MetaspaceAux::committed_bytes();
aoqi@0 1489 size_t capacity_until_gc = capacity_until_GC();
aoqi@0 1490
aoqi@0 1491 assert(capacity_until_gc >= committed_bytes,
aoqi@0 1492 err_msg("capacity_until_gc: " SIZE_FORMAT " < committed_bytes: " SIZE_FORMAT,
aoqi@0 1493 capacity_until_gc, committed_bytes));
aoqi@0 1494
aoqi@0 1495 size_t left_until_max = MaxMetaspaceSize - committed_bytes;
aoqi@0 1496 size_t left_until_GC = capacity_until_gc - committed_bytes;
aoqi@0 1497 size_t left_to_commit = MIN2(left_until_GC, left_until_max);
aoqi@0 1498
aoqi@0 1499 return left_to_commit / BytesPerWord;
aoqi@0 1500 }
aoqi@0 1501
aoqi@0 1502 void MetaspaceGC::compute_new_size() {
aoqi@0 1503 assert(_shrink_factor <= 100, "invalid shrink factor");
aoqi@0 1504 uint current_shrink_factor = _shrink_factor;
aoqi@0 1505 _shrink_factor = 0;
aoqi@0 1506
aoqi@0 1507 // Using committed_bytes() for used_after_gc is an overestimation, since the
aoqi@0 1508 // chunk free lists are included in committed_bytes() and the memory in an
aoqi@0 1509 // un-fragmented chunk free list is available for future allocations.
aoqi@0 1510 // However, if the chunk free lists becomes fragmented, then the memory may
aoqi@0 1511 // not be available for future allocations and the memory is therefore "in use".
aoqi@0 1512 // Including the chunk free lists in the definition of "in use" is therefore
aoqi@0 1513 // necessary. Not including the chunk free lists can cause capacity_until_GC to
aoqi@0 1514 // shrink below committed_bytes() and this has caused serious bugs in the past.
aoqi@0 1515 const size_t used_after_gc = MetaspaceAux::committed_bytes();
aoqi@0 1516 const size_t capacity_until_GC = MetaspaceGC::capacity_until_GC();
aoqi@0 1517
aoqi@0 1518 const double minimum_free_percentage = MinMetaspaceFreeRatio / 100.0;
aoqi@0 1519 const double maximum_used_percentage = 1.0 - minimum_free_percentage;
aoqi@0 1520
aoqi@0 1521 const double min_tmp = used_after_gc / maximum_used_percentage;
aoqi@0 1522 size_t minimum_desired_capacity =
aoqi@0 1523 (size_t)MIN2(min_tmp, double(max_uintx));
aoqi@0 1524 // Don't shrink less than the initial generation size
aoqi@0 1525 minimum_desired_capacity = MAX2(minimum_desired_capacity,
aoqi@0 1526 MetaspaceSize);
aoqi@0 1527
aoqi@0 1528 if (PrintGCDetails && Verbose) {
aoqi@0 1529 gclog_or_tty->print_cr("\nMetaspaceGC::compute_new_size: ");
aoqi@0 1530 gclog_or_tty->print_cr(" "
aoqi@0 1531 " minimum_free_percentage: %6.2f"
aoqi@0 1532 " maximum_used_percentage: %6.2f",
aoqi@0 1533 minimum_free_percentage,
aoqi@0 1534 maximum_used_percentage);
aoqi@0 1535 gclog_or_tty->print_cr(" "
aoqi@0 1536 " used_after_gc : %6.1fKB",
aoqi@0 1537 used_after_gc / (double) K);
aoqi@0 1538 }
aoqi@0 1539
aoqi@0 1540
aoqi@0 1541 size_t shrink_bytes = 0;
aoqi@0 1542 if (capacity_until_GC < minimum_desired_capacity) {
aoqi@0 1543 // If we have less capacity below the metaspace HWM, then
aoqi@0 1544 // increment the HWM.
aoqi@0 1545 size_t expand_bytes = minimum_desired_capacity - capacity_until_GC;
aoqi@0 1546 expand_bytes = align_size_up(expand_bytes, Metaspace::commit_alignment());
aoqi@0 1547 // Don't expand unless it's significant
aoqi@0 1548 if (expand_bytes >= MinMetaspaceExpansion) {
ehelin@7254 1549 size_t new_capacity_until_GC = 0;
ehelin@7254 1550 bool succeeded = MetaspaceGC::inc_capacity_until_GC(expand_bytes, &new_capacity_until_GC);
ehelin@7254 1551 assert(succeeded, "Should always succesfully increment HWM when at safepoint");
ehelin@7254 1552
aoqi@0 1553 Metaspace::tracer()->report_gc_threshold(capacity_until_GC,
aoqi@0 1554 new_capacity_until_GC,
aoqi@0 1555 MetaspaceGCThresholdUpdater::ComputeNewSize);
aoqi@0 1556 if (PrintGCDetails && Verbose) {
aoqi@0 1557 gclog_or_tty->print_cr(" expanding:"
aoqi@0 1558 " minimum_desired_capacity: %6.1fKB"
aoqi@0 1559 " expand_bytes: %6.1fKB"
aoqi@0 1560 " MinMetaspaceExpansion: %6.1fKB"
aoqi@0 1561 " new metaspace HWM: %6.1fKB",
aoqi@0 1562 minimum_desired_capacity / (double) K,
aoqi@0 1563 expand_bytes / (double) K,
aoqi@0 1564 MinMetaspaceExpansion / (double) K,
aoqi@0 1565 new_capacity_until_GC / (double) K);
aoqi@0 1566 }
aoqi@0 1567 }
aoqi@0 1568 return;
aoqi@0 1569 }
aoqi@0 1570
aoqi@0 1571 // No expansion, now see if we want to shrink
aoqi@0 1572 // We would never want to shrink more than this
aoqi@0 1573 size_t max_shrink_bytes = capacity_until_GC - minimum_desired_capacity;
aoqi@0 1574 assert(max_shrink_bytes >= 0, err_msg("max_shrink_bytes " SIZE_FORMAT,
aoqi@0 1575 max_shrink_bytes));
aoqi@0 1576
aoqi@0 1577 // Should shrinking be considered?
aoqi@0 1578 if (MaxMetaspaceFreeRatio < 100) {
aoqi@0 1579 const double maximum_free_percentage = MaxMetaspaceFreeRatio / 100.0;
aoqi@0 1580 const double minimum_used_percentage = 1.0 - maximum_free_percentage;
aoqi@0 1581 const double max_tmp = used_after_gc / minimum_used_percentage;
aoqi@0 1582 size_t maximum_desired_capacity = (size_t)MIN2(max_tmp, double(max_uintx));
aoqi@0 1583 maximum_desired_capacity = MAX2(maximum_desired_capacity,
aoqi@0 1584 MetaspaceSize);
aoqi@0 1585 if (PrintGCDetails && Verbose) {
aoqi@0 1586 gclog_or_tty->print_cr(" "
aoqi@0 1587 " maximum_free_percentage: %6.2f"
aoqi@0 1588 " minimum_used_percentage: %6.2f",
aoqi@0 1589 maximum_free_percentage,
aoqi@0 1590 minimum_used_percentage);
aoqi@0 1591 gclog_or_tty->print_cr(" "
aoqi@0 1592 " minimum_desired_capacity: %6.1fKB"
aoqi@0 1593 " maximum_desired_capacity: %6.1fKB",
aoqi@0 1594 minimum_desired_capacity / (double) K,
aoqi@0 1595 maximum_desired_capacity / (double) K);
aoqi@0 1596 }
aoqi@0 1597
aoqi@0 1598 assert(minimum_desired_capacity <= maximum_desired_capacity,
aoqi@0 1599 "sanity check");
aoqi@0 1600
aoqi@0 1601 if (capacity_until_GC > maximum_desired_capacity) {
aoqi@0 1602 // Capacity too large, compute shrinking size
aoqi@0 1603 shrink_bytes = capacity_until_GC - maximum_desired_capacity;
aoqi@0 1604 // We don't want shrink all the way back to initSize if people call
aoqi@0 1605 // System.gc(), because some programs do that between "phases" and then
aoqi@0 1606 // we'd just have to grow the heap up again for the next phase. So we
aoqi@0 1607 // damp the shrinking: 0% on the first call, 10% on the second call, 40%
aoqi@0 1608 // on the third call, and 100% by the fourth call. But if we recompute
aoqi@0 1609 // size without shrinking, it goes back to 0%.
aoqi@0 1610 shrink_bytes = shrink_bytes / 100 * current_shrink_factor;
aoqi@0 1611
aoqi@0 1612 shrink_bytes = align_size_down(shrink_bytes, Metaspace::commit_alignment());
aoqi@0 1613
aoqi@0 1614 assert(shrink_bytes <= max_shrink_bytes,
aoqi@0 1615 err_msg("invalid shrink size " SIZE_FORMAT " not <= " SIZE_FORMAT,
aoqi@0 1616 shrink_bytes, max_shrink_bytes));
aoqi@0 1617 if (current_shrink_factor == 0) {
aoqi@0 1618 _shrink_factor = 10;
aoqi@0 1619 } else {
aoqi@0 1620 _shrink_factor = MIN2(current_shrink_factor * 4, (uint) 100);
aoqi@0 1621 }
aoqi@0 1622 if (PrintGCDetails && Verbose) {
aoqi@0 1623 gclog_or_tty->print_cr(" "
aoqi@0 1624 " shrinking:"
aoqi@0 1625 " initSize: %.1fK"
aoqi@0 1626 " maximum_desired_capacity: %.1fK",
aoqi@0 1627 MetaspaceSize / (double) K,
aoqi@0 1628 maximum_desired_capacity / (double) K);
aoqi@0 1629 gclog_or_tty->print_cr(" "
aoqi@0 1630 " shrink_bytes: %.1fK"
aoqi@0 1631 " current_shrink_factor: %d"
aoqi@0 1632 " new shrink factor: %d"
aoqi@0 1633 " MinMetaspaceExpansion: %.1fK",
aoqi@0 1634 shrink_bytes / (double) K,
aoqi@0 1635 current_shrink_factor,
aoqi@0 1636 _shrink_factor,
aoqi@0 1637 MinMetaspaceExpansion / (double) K);
aoqi@0 1638 }
aoqi@0 1639 }
aoqi@0 1640 }
aoqi@0 1641
aoqi@0 1642 // Don't shrink unless it's significant
aoqi@0 1643 if (shrink_bytes >= MinMetaspaceExpansion &&
aoqi@0 1644 ((capacity_until_GC - shrink_bytes) >= MetaspaceSize)) {
aoqi@0 1645 size_t new_capacity_until_GC = MetaspaceGC::dec_capacity_until_GC(shrink_bytes);
aoqi@0 1646 Metaspace::tracer()->report_gc_threshold(capacity_until_GC,
aoqi@0 1647 new_capacity_until_GC,
aoqi@0 1648 MetaspaceGCThresholdUpdater::ComputeNewSize);
aoqi@0 1649 }
aoqi@0 1650 }
aoqi@0 1651
aoqi@0 1652 // Metadebug methods
aoqi@0 1653
aoqi@0 1654 void Metadebug::init_allocation_fail_alot_count() {
aoqi@0 1655 if (MetadataAllocationFailALot) {
aoqi@0 1656 _allocation_fail_alot_count =
aoqi@0 1657 1+(long)((double)MetadataAllocationFailALotInterval*os::random()/(max_jint+1.0));
aoqi@0 1658 }
aoqi@0 1659 }
aoqi@0 1660
aoqi@0 1661 #ifdef ASSERT
aoqi@0 1662 bool Metadebug::test_metadata_failure() {
aoqi@0 1663 if (MetadataAllocationFailALot &&
aoqi@0 1664 Threads::is_vm_complete()) {
aoqi@0 1665 if (_allocation_fail_alot_count > 0) {
aoqi@0 1666 _allocation_fail_alot_count--;
aoqi@0 1667 } else {
aoqi@0 1668 if (TraceMetadataChunkAllocation && Verbose) {
aoqi@0 1669 gclog_or_tty->print_cr("Metadata allocation failing for "
aoqi@0 1670 "MetadataAllocationFailALot");
aoqi@0 1671 }
aoqi@0 1672 init_allocation_fail_alot_count();
aoqi@0 1673 return true;
aoqi@0 1674 }
aoqi@0 1675 }
aoqi@0 1676 return false;
aoqi@0 1677 }
aoqi@0 1678 #endif
aoqi@0 1679
aoqi@0 1680 // ChunkManager methods
aoqi@0 1681
aoqi@0 1682 size_t ChunkManager::free_chunks_total_words() {
aoqi@0 1683 return _free_chunks_total;
aoqi@0 1684 }
aoqi@0 1685
aoqi@0 1686 size_t ChunkManager::free_chunks_total_bytes() {
aoqi@0 1687 return free_chunks_total_words() * BytesPerWord;
aoqi@0 1688 }
aoqi@0 1689
aoqi@0 1690 size_t ChunkManager::free_chunks_count() {
aoqi@0 1691 #ifdef ASSERT
aoqi@0 1692 if (!UseConcMarkSweepGC && !SpaceManager::expand_lock()->is_locked()) {
aoqi@0 1693 MutexLockerEx cl(SpaceManager::expand_lock(),
aoqi@0 1694 Mutex::_no_safepoint_check_flag);
aoqi@0 1695 // This lock is only needed in debug because the verification
aoqi@0 1696 // of the _free_chunks_totals walks the list of free chunks
aoqi@0 1697 slow_locked_verify_free_chunks_count();
aoqi@0 1698 }
aoqi@0 1699 #endif
aoqi@0 1700 return _free_chunks_count;
aoqi@0 1701 }
aoqi@0 1702
aoqi@0 1703 void ChunkManager::locked_verify_free_chunks_total() {
aoqi@0 1704 assert_lock_strong(SpaceManager::expand_lock());
aoqi@0 1705 assert(sum_free_chunks() == _free_chunks_total,
aoqi@0 1706 err_msg("_free_chunks_total " SIZE_FORMAT " is not the"
aoqi@0 1707 " same as sum " SIZE_FORMAT, _free_chunks_total,
aoqi@0 1708 sum_free_chunks()));
aoqi@0 1709 }
aoqi@0 1710
aoqi@0 1711 void ChunkManager::verify_free_chunks_total() {
aoqi@0 1712 MutexLockerEx cl(SpaceManager::expand_lock(),
aoqi@0 1713 Mutex::_no_safepoint_check_flag);
aoqi@0 1714 locked_verify_free_chunks_total();
aoqi@0 1715 }
aoqi@0 1716
aoqi@0 1717 void ChunkManager::locked_verify_free_chunks_count() {
aoqi@0 1718 assert_lock_strong(SpaceManager::expand_lock());
aoqi@0 1719 assert(sum_free_chunks_count() == _free_chunks_count,
aoqi@0 1720 err_msg("_free_chunks_count " SIZE_FORMAT " is not the"
aoqi@0 1721 " same as sum " SIZE_FORMAT, _free_chunks_count,
aoqi@0 1722 sum_free_chunks_count()));
aoqi@0 1723 }
aoqi@0 1724
aoqi@0 1725 void ChunkManager::verify_free_chunks_count() {
aoqi@0 1726 #ifdef ASSERT
aoqi@0 1727 MutexLockerEx cl(SpaceManager::expand_lock(),
aoqi@0 1728 Mutex::_no_safepoint_check_flag);
aoqi@0 1729 locked_verify_free_chunks_count();
aoqi@0 1730 #endif
aoqi@0 1731 }
aoqi@0 1732
aoqi@0 1733 void ChunkManager::verify() {
aoqi@0 1734 MutexLockerEx cl(SpaceManager::expand_lock(),
aoqi@0 1735 Mutex::_no_safepoint_check_flag);
aoqi@0 1736 locked_verify();
aoqi@0 1737 }
aoqi@0 1738
aoqi@0 1739 void ChunkManager::locked_verify() {
aoqi@0 1740 locked_verify_free_chunks_count();
aoqi@0 1741 locked_verify_free_chunks_total();
aoqi@0 1742 }
aoqi@0 1743
aoqi@0 1744 void ChunkManager::locked_print_free_chunks(outputStream* st) {
aoqi@0 1745 assert_lock_strong(SpaceManager::expand_lock());
aoqi@0 1746 st->print_cr("Free chunk total " SIZE_FORMAT " count " SIZE_FORMAT,
aoqi@0 1747 _free_chunks_total, _free_chunks_count);
aoqi@0 1748 }
aoqi@0 1749
aoqi@0 1750 void ChunkManager::locked_print_sum_free_chunks(outputStream* st) {
aoqi@0 1751 assert_lock_strong(SpaceManager::expand_lock());
aoqi@0 1752 st->print_cr("Sum free chunk total " SIZE_FORMAT " count " SIZE_FORMAT,
aoqi@0 1753 sum_free_chunks(), sum_free_chunks_count());
aoqi@0 1754 }
mchinnathamb@9064 1755
aoqi@0 1756 ChunkList* ChunkManager::free_chunks(ChunkIndex index) {
mchinnathamb@9064 1757 assert(index == SpecializedIndex || index == SmallIndex || index == MediumIndex,
mchinnathamb@9064 1758 err_msg("Bad index: %d", (int)index));
mchinnathamb@9064 1759
aoqi@0 1760 return &_free_chunks[index];
aoqi@0 1761 }
aoqi@0 1762
aoqi@0 1763 // These methods that sum the free chunk lists are used in printing
aoqi@0 1764 // methods that are used in product builds.
aoqi@0 1765 size_t ChunkManager::sum_free_chunks() {
aoqi@0 1766 assert_lock_strong(SpaceManager::expand_lock());
aoqi@0 1767 size_t result = 0;
aoqi@0 1768 for (ChunkIndex i = ZeroIndex; i < NumberOfFreeLists; i = next_chunk_index(i)) {
aoqi@0 1769 ChunkList* list = free_chunks(i);
aoqi@0 1770
aoqi@0 1771 if (list == NULL) {
aoqi@0 1772 continue;
aoqi@0 1773 }
aoqi@0 1774
aoqi@0 1775 result = result + list->count() * list->size();
aoqi@0 1776 }
aoqi@0 1777 result = result + humongous_dictionary()->total_size();
aoqi@0 1778 return result;
aoqi@0 1779 }
aoqi@0 1780
aoqi@0 1781 size_t ChunkManager::sum_free_chunks_count() {
aoqi@0 1782 assert_lock_strong(SpaceManager::expand_lock());
aoqi@0 1783 size_t count = 0;
aoqi@0 1784 for (ChunkIndex i = ZeroIndex; i < NumberOfFreeLists; i = next_chunk_index(i)) {
aoqi@0 1785 ChunkList* list = free_chunks(i);
aoqi@0 1786 if (list == NULL) {
aoqi@0 1787 continue;
aoqi@0 1788 }
aoqi@0 1789 count = count + list->count();
aoqi@0 1790 }
aoqi@0 1791 count = count + humongous_dictionary()->total_free_blocks();
aoqi@0 1792 return count;
aoqi@0 1793 }
aoqi@0 1794
aoqi@0 1795 ChunkList* ChunkManager::find_free_chunks_list(size_t word_size) {
aoqi@0 1796 ChunkIndex index = list_index(word_size);
aoqi@0 1797 assert(index < HumongousIndex, "No humongous list");
aoqi@0 1798 return free_chunks(index);
aoqi@0 1799 }
aoqi@0 1800
aoqi@0 1801 Metachunk* ChunkManager::free_chunks_get(size_t word_size) {
aoqi@0 1802 assert_lock_strong(SpaceManager::expand_lock());
aoqi@0 1803
aoqi@0 1804 slow_locked_verify();
aoqi@0 1805
aoqi@0 1806 Metachunk* chunk = NULL;
aoqi@0 1807 if (list_index(word_size) != HumongousIndex) {
aoqi@0 1808 ChunkList* free_list = find_free_chunks_list(word_size);
aoqi@0 1809 assert(free_list != NULL, "Sanity check");
aoqi@0 1810
aoqi@0 1811 chunk = free_list->head();
aoqi@0 1812
aoqi@0 1813 if (chunk == NULL) {
aoqi@0 1814 return NULL;
aoqi@0 1815 }
aoqi@0 1816
aoqi@0 1817 // Remove the chunk as the head of the list.
aoqi@0 1818 free_list->remove_chunk(chunk);
aoqi@0 1819
aoqi@0 1820 if (TraceMetadataChunkAllocation && Verbose) {
aoqi@0 1821 gclog_or_tty->print_cr("ChunkManager::free_chunks_get: free_list "
aoqi@0 1822 PTR_FORMAT " head " PTR_FORMAT " size " SIZE_FORMAT,
aoqi@0 1823 free_list, chunk, chunk->word_size());
aoqi@0 1824 }
aoqi@0 1825 } else {
aoqi@0 1826 chunk = humongous_dictionary()->get_chunk(
aoqi@0 1827 word_size,
aoqi@0 1828 FreeBlockDictionary<Metachunk>::atLeast);
aoqi@0 1829
aoqi@0 1830 if (chunk == NULL) {
aoqi@0 1831 return NULL;
aoqi@0 1832 }
aoqi@0 1833
aoqi@0 1834 if (TraceMetadataHumongousAllocation) {
aoqi@0 1835 size_t waste = chunk->word_size() - word_size;
aoqi@0 1836 gclog_or_tty->print_cr("Free list allocate humongous chunk size "
aoqi@0 1837 SIZE_FORMAT " for requested size " SIZE_FORMAT
aoqi@0 1838 " waste " SIZE_FORMAT,
aoqi@0 1839 chunk->word_size(), word_size, waste);
aoqi@0 1840 }
aoqi@0 1841 }
aoqi@0 1842
aoqi@0 1843 // Chunk is being removed from the chunks free list.
aoqi@0 1844 dec_free_chunks_total(chunk->word_size());
aoqi@0 1845
aoqi@0 1846 // Remove it from the links to this freelist
aoqi@0 1847 chunk->set_next(NULL);
aoqi@0 1848 chunk->set_prev(NULL);
aoqi@0 1849 #ifdef ASSERT
aoqi@0 1850 // Chunk is no longer on any freelist. Setting to false make container_count_slow()
aoqi@0 1851 // work.
aoqi@0 1852 chunk->set_is_tagged_free(false);
aoqi@0 1853 #endif
aoqi@0 1854 chunk->container()->inc_container_count();
aoqi@0 1855
aoqi@0 1856 slow_locked_verify();
aoqi@0 1857 return chunk;
aoqi@0 1858 }
aoqi@0 1859
aoqi@0 1860 Metachunk* ChunkManager::chunk_freelist_allocate(size_t word_size) {
aoqi@0 1861 assert_lock_strong(SpaceManager::expand_lock());
aoqi@0 1862 slow_locked_verify();
aoqi@0 1863
aoqi@0 1864 // Take from the beginning of the list
aoqi@0 1865 Metachunk* chunk = free_chunks_get(word_size);
aoqi@0 1866 if (chunk == NULL) {
aoqi@0 1867 return NULL;
aoqi@0 1868 }
aoqi@0 1869
aoqi@0 1870 assert((word_size <= chunk->word_size()) ||
mchinnathamb@9064 1871 (list_index(chunk->word_size()) == HumongousIndex),
aoqi@0 1872 "Non-humongous variable sized chunk");
aoqi@0 1873 if (TraceMetadataChunkAllocation) {
aoqi@0 1874 size_t list_count;
aoqi@0 1875 if (list_index(word_size) < HumongousIndex) {
aoqi@0 1876 ChunkList* list = find_free_chunks_list(word_size);
aoqi@0 1877 list_count = list->count();
aoqi@0 1878 } else {
aoqi@0 1879 list_count = humongous_dictionary()->total_count();
aoqi@0 1880 }
aoqi@0 1881 gclog_or_tty->print("ChunkManager::chunk_freelist_allocate: " PTR_FORMAT " chunk "
aoqi@0 1882 PTR_FORMAT " size " SIZE_FORMAT " count " SIZE_FORMAT " ",
aoqi@0 1883 this, chunk, chunk->word_size(), list_count);
aoqi@0 1884 locked_print_free_chunks(gclog_or_tty);
aoqi@0 1885 }
aoqi@0 1886
aoqi@0 1887 return chunk;
aoqi@0 1888 }
aoqi@0 1889
aoqi@0 1890 void ChunkManager::print_on(outputStream* out) const {
aoqi@0 1891 if (PrintFLSStatistics != 0) {
aoqi@0 1892 const_cast<ChunkManager *>(this)->humongous_dictionary()->report_statistics();
aoqi@0 1893 }
aoqi@0 1894 }
aoqi@0 1895
aoqi@0 1896 // SpaceManager methods
aoqi@0 1897
mchinnathamb@9058 1898 size_t SpaceManager::adjust_initial_chunk_size(size_t requested, bool is_class_space) {
mchinnathamb@9058 1899 size_t chunk_sizes[] = {
mchinnathamb@9058 1900 specialized_chunk_size(is_class_space),
mchinnathamb@9058 1901 small_chunk_size(is_class_space),
mchinnathamb@9058 1902 medium_chunk_size(is_class_space)
mchinnathamb@9058 1903 };
mchinnathamb@9058 1904
mchinnathamb@9058 1905 // Adjust up to one of the fixed chunk sizes ...
mchinnathamb@9058 1906 for (size_t i = 0; i < ARRAY_SIZE(chunk_sizes); i++) {
mchinnathamb@9058 1907 if (requested <= chunk_sizes[i]) {
mchinnathamb@9058 1908 return chunk_sizes[i];
mchinnathamb@9058 1909 }
aoqi@0 1910 }
mchinnathamb@9058 1911
mchinnathamb@9058 1912 // ... or return the size as a humongous chunk.
mchinnathamb@9058 1913 return requested;
mchinnathamb@9058 1914 }
mchinnathamb@9058 1915
mchinnathamb@9058 1916 size_t SpaceManager::adjust_initial_chunk_size(size_t requested) const {
mchinnathamb@9058 1917 return adjust_initial_chunk_size(requested, is_class());
mchinnathamb@9058 1918 }
mchinnathamb@9058 1919
mchinnathamb@9058 1920 size_t SpaceManager::get_initial_chunk_size(Metaspace::MetaspaceType type) const {
mchinnathamb@9058 1921 size_t requested;
mchinnathamb@9058 1922
mchinnathamb@9058 1923 if (is_class()) {
mchinnathamb@9058 1924 switch (type) {
mchinnathamb@9058 1925 case Metaspace::BootMetaspaceType: requested = Metaspace::first_class_chunk_word_size(); break;
mchinnathamb@9058 1926 case Metaspace::ROMetaspaceType: requested = ClassSpecializedChunk; break;
mchinnathamb@9058 1927 case Metaspace::ReadWriteMetaspaceType: requested = ClassSpecializedChunk; break;
mchinnathamb@9058 1928 case Metaspace::AnonymousMetaspaceType: requested = ClassSpecializedChunk; break;
mchinnathamb@9058 1929 case Metaspace::ReflectionMetaspaceType: requested = ClassSpecializedChunk; break;
mchinnathamb@9058 1930 default: requested = ClassSmallChunk; break;
mchinnathamb@9058 1931 }
mchinnathamb@9058 1932 } else {
mchinnathamb@9058 1933 switch (type) {
mchinnathamb@9058 1934 case Metaspace::BootMetaspaceType: requested = Metaspace::first_chunk_word_size(); break;
mchinnathamb@9058 1935 case Metaspace::ROMetaspaceType: requested = SharedReadOnlySize / wordSize; break;
mchinnathamb@9058 1936 case Metaspace::ReadWriteMetaspaceType: requested = SharedReadWriteSize / wordSize; break;
mchinnathamb@9058 1937 case Metaspace::AnonymousMetaspaceType: requested = SpecializedChunk; break;
mchinnathamb@9058 1938 case Metaspace::ReflectionMetaspaceType: requested = SpecializedChunk; break;
mchinnathamb@9058 1939 default: requested = SmallChunk; break;
mchinnathamb@9058 1940 }
mchinnathamb@9058 1941 }
mchinnathamb@9058 1942
mchinnathamb@9058 1943 // Adjust to one of the fixed chunk sizes (unless humongous)
mchinnathamb@9058 1944 const size_t adjusted = adjust_initial_chunk_size(requested);
mchinnathamb@9058 1945
mchinnathamb@9058 1946 assert(adjusted != 0, err_msg("Incorrect initial chunk size. Requested: "
mchinnathamb@9058 1947 SIZE_FORMAT " adjusted: " SIZE_FORMAT, requested, adjusted));
mchinnathamb@9058 1948
mchinnathamb@9058 1949 return adjusted;
aoqi@0 1950 }
aoqi@0 1951
aoqi@0 1952 size_t SpaceManager::sum_free_in_chunks_in_use() const {
aoqi@0 1953 MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
aoqi@0 1954 size_t free = 0;
aoqi@0 1955 for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
aoqi@0 1956 Metachunk* chunk = chunks_in_use(i);
aoqi@0 1957 while (chunk != NULL) {
aoqi@0 1958 free += chunk->free_word_size();
aoqi@0 1959 chunk = chunk->next();
aoqi@0 1960 }
aoqi@0 1961 }
aoqi@0 1962 return free;
aoqi@0 1963 }
aoqi@0 1964
aoqi@0 1965 size_t SpaceManager::sum_waste_in_chunks_in_use() const {
aoqi@0 1966 MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
aoqi@0 1967 size_t result = 0;
aoqi@0 1968 for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
aoqi@0 1969 result += sum_waste_in_chunks_in_use(i);
aoqi@0 1970 }
aoqi@0 1971
aoqi@0 1972 return result;
aoqi@0 1973 }
aoqi@0 1974
aoqi@0 1975 size_t SpaceManager::sum_waste_in_chunks_in_use(ChunkIndex index) const {
aoqi@0 1976 size_t result = 0;
aoqi@0 1977 Metachunk* chunk = chunks_in_use(index);
aoqi@0 1978 // Count the free space in all the chunk but not the
aoqi@0 1979 // current chunk from which allocations are still being done.
aoqi@0 1980 while (chunk != NULL) {
aoqi@0 1981 if (chunk != current_chunk()) {
aoqi@0 1982 result += chunk->free_word_size();
aoqi@0 1983 }
aoqi@0 1984 chunk = chunk->next();
aoqi@0 1985 }
aoqi@0 1986 return result;
aoqi@0 1987 }
aoqi@0 1988
aoqi@0 1989 size_t SpaceManager::sum_capacity_in_chunks_in_use() const {
aoqi@0 1990 // For CMS use "allocated_chunks_words()" which does not need the
aoqi@0 1991 // Metaspace lock. For the other collectors sum over the
aoqi@0 1992 // lists. Use both methods as a check that "allocated_chunks_words()"
aoqi@0 1993 // is correct. That is, sum_capacity_in_chunks() is too expensive
aoqi@0 1994 // to use in the product and allocated_chunks_words() should be used
aoqi@0 1995 // but allow for checking that allocated_chunks_words() returns the same
aoqi@0 1996 // value as sum_capacity_in_chunks_in_use() which is the definitive
aoqi@0 1997 // answer.
aoqi@0 1998 if (UseConcMarkSweepGC) {
aoqi@0 1999 return allocated_chunks_words();
aoqi@0 2000 } else {
aoqi@0 2001 MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
aoqi@0 2002 size_t sum = 0;
aoqi@0 2003 for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
aoqi@0 2004 Metachunk* chunk = chunks_in_use(i);
aoqi@0 2005 while (chunk != NULL) {
aoqi@0 2006 sum += chunk->word_size();
aoqi@0 2007 chunk = chunk->next();
aoqi@0 2008 }
aoqi@0 2009 }
aoqi@0 2010 return sum;
aoqi@0 2011 }
aoqi@0 2012 }
aoqi@0 2013
aoqi@0 2014 size_t SpaceManager::sum_count_in_chunks_in_use() {
aoqi@0 2015 size_t count = 0;
aoqi@0 2016 for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
aoqi@0 2017 count = count + sum_count_in_chunks_in_use(i);
aoqi@0 2018 }
aoqi@0 2019
aoqi@0 2020 return count;
aoqi@0 2021 }
aoqi@0 2022
aoqi@0 2023 size_t SpaceManager::sum_count_in_chunks_in_use(ChunkIndex i) {
aoqi@0 2024 size_t count = 0;
aoqi@0 2025 Metachunk* chunk = chunks_in_use(i);
aoqi@0 2026 while (chunk != NULL) {
aoqi@0 2027 count++;
aoqi@0 2028 chunk = chunk->next();
aoqi@0 2029 }
aoqi@0 2030 return count;
aoqi@0 2031 }
aoqi@0 2032
aoqi@0 2033
aoqi@0 2034 size_t SpaceManager::sum_used_in_chunks_in_use() const {
aoqi@0 2035 MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
aoqi@0 2036 size_t used = 0;
aoqi@0 2037 for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
aoqi@0 2038 Metachunk* chunk = chunks_in_use(i);
aoqi@0 2039 while (chunk != NULL) {
aoqi@0 2040 used += chunk->used_word_size();
aoqi@0 2041 chunk = chunk->next();
aoqi@0 2042 }
aoqi@0 2043 }
aoqi@0 2044 return used;
aoqi@0 2045 }
aoqi@0 2046
aoqi@0 2047 void SpaceManager::locked_print_chunks_in_use_on(outputStream* st) const {
aoqi@0 2048
aoqi@0 2049 for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
aoqi@0 2050 Metachunk* chunk = chunks_in_use(i);
aoqi@0 2051 st->print("SpaceManager: %s " PTR_FORMAT,
aoqi@0 2052 chunk_size_name(i), chunk);
aoqi@0 2053 if (chunk != NULL) {
aoqi@0 2054 st->print_cr(" free " SIZE_FORMAT,
aoqi@0 2055 chunk->free_word_size());
aoqi@0 2056 } else {
aoqi@0 2057 st->cr();
aoqi@0 2058 }
aoqi@0 2059 }
aoqi@0 2060
aoqi@0 2061 chunk_manager()->locked_print_free_chunks(st);
aoqi@0 2062 chunk_manager()->locked_print_sum_free_chunks(st);
aoqi@0 2063 }
aoqi@0 2064
aoqi@0 2065 size_t SpaceManager::calc_chunk_size(size_t word_size) {
aoqi@0 2066
aoqi@0 2067 // Decide between a small chunk and a medium chunk. Up to
aoqi@0 2068 // _small_chunk_limit small chunks can be allocated but
aoqi@0 2069 // once a medium chunk has been allocated, no more small
aoqi@0 2070 // chunks will be allocated.
aoqi@0 2071 size_t chunk_word_size;
aoqi@0 2072 if (chunks_in_use(MediumIndex) == NULL &&
aoqi@0 2073 sum_count_in_chunks_in_use(SmallIndex) < _small_chunk_limit) {
aoqi@0 2074 chunk_word_size = (size_t) small_chunk_size();
aoqi@0 2075 if (word_size + Metachunk::overhead() > small_chunk_size()) {
aoqi@0 2076 chunk_word_size = medium_chunk_size();
aoqi@0 2077 }
aoqi@0 2078 } else {
aoqi@0 2079 chunk_word_size = medium_chunk_size();
aoqi@0 2080 }
aoqi@0 2081
aoqi@0 2082 // Might still need a humongous chunk. Enforce
aoqi@0 2083 // humongous allocations sizes to be aligned up to
aoqi@0 2084 // the smallest chunk size.
aoqi@0 2085 size_t if_humongous_sized_chunk =
aoqi@0 2086 align_size_up(word_size + Metachunk::overhead(),
aoqi@0 2087 smallest_chunk_size());
aoqi@0 2088 chunk_word_size =
aoqi@0 2089 MAX2((size_t) chunk_word_size, if_humongous_sized_chunk);
aoqi@0 2090
aoqi@0 2091 assert(!SpaceManager::is_humongous(word_size) ||
aoqi@0 2092 chunk_word_size == if_humongous_sized_chunk,
aoqi@0 2093 err_msg("Size calculation is wrong, word_size " SIZE_FORMAT
aoqi@0 2094 " chunk_word_size " SIZE_FORMAT,
aoqi@0 2095 word_size, chunk_word_size));
aoqi@0 2096 if (TraceMetadataHumongousAllocation &&
aoqi@0 2097 SpaceManager::is_humongous(word_size)) {
aoqi@0 2098 gclog_or_tty->print_cr("Metadata humongous allocation:");
aoqi@0 2099 gclog_or_tty->print_cr(" word_size " PTR_FORMAT, word_size);
aoqi@0 2100 gclog_or_tty->print_cr(" chunk_word_size " PTR_FORMAT,
aoqi@0 2101 chunk_word_size);
aoqi@0 2102 gclog_or_tty->print_cr(" chunk overhead " PTR_FORMAT,
aoqi@0 2103 Metachunk::overhead());
aoqi@0 2104 }
aoqi@0 2105 return chunk_word_size;
aoqi@0 2106 }
aoqi@0 2107
aoqi@0 2108 void SpaceManager::track_metaspace_memory_usage() {
aoqi@0 2109 if (is_init_completed()) {
aoqi@0 2110 if (is_class()) {
aoqi@0 2111 MemoryService::track_compressed_class_memory_usage();
aoqi@0 2112 }
aoqi@0 2113 MemoryService::track_metaspace_memory_usage();
aoqi@0 2114 }
aoqi@0 2115 }
aoqi@0 2116
aoqi@0 2117 MetaWord* SpaceManager::grow_and_allocate(size_t word_size) {
aoqi@0 2118 assert(vs_list()->current_virtual_space() != NULL,
aoqi@0 2119 "Should have been set");
aoqi@0 2120 assert(current_chunk() == NULL ||
aoqi@0 2121 current_chunk()->allocate(word_size) == NULL,
aoqi@0 2122 "Don't need to expand");
aoqi@0 2123 MutexLockerEx cl(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag);
aoqi@0 2124
aoqi@0 2125 if (TraceMetadataChunkAllocation && Verbose) {
aoqi@0 2126 size_t words_left = 0;
aoqi@0 2127 size_t words_used = 0;
aoqi@0 2128 if (current_chunk() != NULL) {
aoqi@0 2129 words_left = current_chunk()->free_word_size();
aoqi@0 2130 words_used = current_chunk()->used_word_size();
aoqi@0 2131 }
aoqi@0 2132 gclog_or_tty->print_cr("SpaceManager::grow_and_allocate for " SIZE_FORMAT
aoqi@0 2133 " words " SIZE_FORMAT " words used " SIZE_FORMAT
aoqi@0 2134 " words left",
aoqi@0 2135 word_size, words_used, words_left);
aoqi@0 2136 }
aoqi@0 2137
aoqi@0 2138 // Get another chunk out of the virtual space
mchinnathamb@9058 2139 size_t chunk_word_size = calc_chunk_size(word_size);
mchinnathamb@9058 2140 Metachunk* next = get_new_chunk(chunk_word_size);
aoqi@0 2141
aoqi@0 2142 MetaWord* mem = NULL;
aoqi@0 2143
aoqi@0 2144 // If a chunk was available, add it to the in-use chunk list
aoqi@0 2145 // and do an allocation from it.
aoqi@0 2146 if (next != NULL) {
aoqi@0 2147 // Add to this manager's list of chunks in use.
aoqi@0 2148 add_chunk(next, false);
aoqi@0 2149 mem = next->allocate(word_size);
aoqi@0 2150 }
aoqi@0 2151
aoqi@0 2152 // Track metaspace memory usage statistic.
aoqi@0 2153 track_metaspace_memory_usage();
aoqi@0 2154
aoqi@0 2155 return mem;
aoqi@0 2156 }
aoqi@0 2157
aoqi@0 2158 void SpaceManager::print_on(outputStream* st) const {
aoqi@0 2159
aoqi@0 2160 for (ChunkIndex i = ZeroIndex;
aoqi@0 2161 i < NumberOfInUseLists ;
aoqi@0 2162 i = next_chunk_index(i) ) {
aoqi@0 2163 st->print_cr(" chunks_in_use " PTR_FORMAT " chunk size " PTR_FORMAT,
aoqi@0 2164 chunks_in_use(i),
aoqi@0 2165 chunks_in_use(i) == NULL ? 0 : chunks_in_use(i)->word_size());
aoqi@0 2166 }
aoqi@0 2167 st->print_cr(" waste: Small " SIZE_FORMAT " Medium " SIZE_FORMAT
aoqi@0 2168 " Humongous " SIZE_FORMAT,
aoqi@0 2169 sum_waste_in_chunks_in_use(SmallIndex),
aoqi@0 2170 sum_waste_in_chunks_in_use(MediumIndex),
aoqi@0 2171 sum_waste_in_chunks_in_use(HumongousIndex));
aoqi@0 2172 // block free lists
aoqi@0 2173 if (block_freelists() != NULL) {
aoqi@0 2174 st->print_cr("total in block free lists " SIZE_FORMAT,
aoqi@0 2175 block_freelists()->total_size());
aoqi@0 2176 }
aoqi@0 2177 }
aoqi@0 2178
aoqi@0 2179 SpaceManager::SpaceManager(Metaspace::MetadataType mdtype,
aoqi@0 2180 Mutex* lock) :
aoqi@0 2181 _mdtype(mdtype),
aoqi@0 2182 _allocated_blocks_words(0),
aoqi@0 2183 _allocated_chunks_words(0),
aoqi@0 2184 _allocated_chunks_count(0),
aoqi@0 2185 _lock(lock)
aoqi@0 2186 {
aoqi@0 2187 initialize();
aoqi@0 2188 }
aoqi@0 2189
aoqi@0 2190 void SpaceManager::inc_size_metrics(size_t words) {
aoqi@0 2191 assert_lock_strong(SpaceManager::expand_lock());
aoqi@0 2192 // Total of allocated Metachunks and allocated Metachunks count
aoqi@0 2193 // for each SpaceManager
aoqi@0 2194 _allocated_chunks_words = _allocated_chunks_words + words;
aoqi@0 2195 _allocated_chunks_count++;
aoqi@0 2196 // Global total of capacity in allocated Metachunks
aoqi@0 2197 MetaspaceAux::inc_capacity(mdtype(), words);
aoqi@0 2198 // Global total of allocated Metablocks.
aoqi@0 2199 // used_words_slow() includes the overhead in each
aoqi@0 2200 // Metachunk so include it in the used when the
aoqi@0 2201 // Metachunk is first added (so only added once per
aoqi@0 2202 // Metachunk).
aoqi@0 2203 MetaspaceAux::inc_used(mdtype(), Metachunk::overhead());
aoqi@0 2204 }
aoqi@0 2205
aoqi@0 2206 void SpaceManager::inc_used_metrics(size_t words) {
aoqi@0 2207 // Add to the per SpaceManager total
aoqi@0 2208 Atomic::add_ptr(words, &_allocated_blocks_words);
aoqi@0 2209 // Add to the global total
aoqi@0 2210 MetaspaceAux::inc_used(mdtype(), words);
aoqi@0 2211 }
aoqi@0 2212
aoqi@0 2213 void SpaceManager::dec_total_from_size_metrics() {
aoqi@0 2214 MetaspaceAux::dec_capacity(mdtype(), allocated_chunks_words());
aoqi@0 2215 MetaspaceAux::dec_used(mdtype(), allocated_blocks_words());
aoqi@0 2216 // Also deduct the overhead per Metachunk
aoqi@0 2217 MetaspaceAux::dec_used(mdtype(), allocated_chunks_count() * Metachunk::overhead());
aoqi@0 2218 }
aoqi@0 2219
aoqi@0 2220 void SpaceManager::initialize() {
aoqi@0 2221 Metadebug::init_allocation_fail_alot_count();
aoqi@0 2222 for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
aoqi@0 2223 _chunks_in_use[i] = NULL;
aoqi@0 2224 }
aoqi@0 2225 _current_chunk = NULL;
aoqi@0 2226 if (TraceMetadataChunkAllocation && Verbose) {
aoqi@0 2227 gclog_or_tty->print_cr("SpaceManager(): " PTR_FORMAT, this);
aoqi@0 2228 }
aoqi@0 2229 }
aoqi@0 2230
aoqi@0 2231 void ChunkManager::return_chunks(ChunkIndex index, Metachunk* chunks) {
aoqi@0 2232 if (chunks == NULL) {
aoqi@0 2233 return;
aoqi@0 2234 }
aoqi@0 2235 ChunkList* list = free_chunks(index);
aoqi@0 2236 assert(list->size() == chunks->word_size(), "Mismatch in chunk sizes");
aoqi@0 2237 assert_lock_strong(SpaceManager::expand_lock());
aoqi@0 2238 Metachunk* cur = chunks;
aoqi@0 2239
aoqi@0 2240 // This returns chunks one at a time. If a new
aoqi@0 2241 // class List can be created that is a base class
aoqi@0 2242 // of FreeList then something like FreeList::prepend()
aoqi@0 2243 // can be used in place of this loop
aoqi@0 2244 while (cur != NULL) {
aoqi@0 2245 assert(cur->container() != NULL, "Container should have been set");
aoqi@0 2246 cur->container()->dec_container_count();
aoqi@0 2247 // Capture the next link before it is changed
aoqi@0 2248 // by the call to return_chunk_at_head();
aoqi@0 2249 Metachunk* next = cur->next();
aoqi@0 2250 DEBUG_ONLY(cur->set_is_tagged_free(true);)
aoqi@0 2251 list->return_chunk_at_head(cur);
aoqi@0 2252 cur = next;
aoqi@0 2253 }
aoqi@0 2254 }
aoqi@0 2255
aoqi@0 2256 SpaceManager::~SpaceManager() {
aoqi@0 2257 // This call this->_lock which can't be done while holding expand_lock()
aoqi@0 2258 assert(sum_capacity_in_chunks_in_use() == allocated_chunks_words(),
aoqi@0 2259 err_msg("sum_capacity_in_chunks_in_use() " SIZE_FORMAT
aoqi@0 2260 " allocated_chunks_words() " SIZE_FORMAT,
aoqi@0 2261 sum_capacity_in_chunks_in_use(), allocated_chunks_words()));
aoqi@0 2262
aoqi@0 2263 MutexLockerEx fcl(SpaceManager::expand_lock(),
aoqi@0 2264 Mutex::_no_safepoint_check_flag);
aoqi@0 2265
aoqi@0 2266 chunk_manager()->slow_locked_verify();
aoqi@0 2267
aoqi@0 2268 dec_total_from_size_metrics();
aoqi@0 2269
aoqi@0 2270 if (TraceMetadataChunkAllocation && Verbose) {
aoqi@0 2271 gclog_or_tty->print_cr("~SpaceManager(): " PTR_FORMAT, this);
aoqi@0 2272 locked_print_chunks_in_use_on(gclog_or_tty);
aoqi@0 2273 }
aoqi@0 2274
aoqi@0 2275 // Do not mangle freed Metachunks. The chunk size inside Metachunks
aoqi@0 2276 // is during the freeing of a VirtualSpaceNodes.
aoqi@0 2277
aoqi@0 2278 // Have to update before the chunks_in_use lists are emptied
aoqi@0 2279 // below.
aoqi@0 2280 chunk_manager()->inc_free_chunks_total(allocated_chunks_words(),
aoqi@0 2281 sum_count_in_chunks_in_use());
aoqi@0 2282
aoqi@0 2283 // Add all the chunks in use by this space manager
aoqi@0 2284 // to the global list of free chunks.
aoqi@0 2285
aoqi@0 2286 // Follow each list of chunks-in-use and add them to the
aoqi@0 2287 // free lists. Each list is NULL terminated.
aoqi@0 2288
aoqi@0 2289 for (ChunkIndex i = ZeroIndex; i < HumongousIndex; i = next_chunk_index(i)) {
aoqi@0 2290 if (TraceMetadataChunkAllocation && Verbose) {
aoqi@0 2291 gclog_or_tty->print_cr("returned %d %s chunks to freelist",
aoqi@0 2292 sum_count_in_chunks_in_use(i),
aoqi@0 2293 chunk_size_name(i));
aoqi@0 2294 }
aoqi@0 2295 Metachunk* chunks = chunks_in_use(i);
aoqi@0 2296 chunk_manager()->return_chunks(i, chunks);
aoqi@0 2297 set_chunks_in_use(i, NULL);
aoqi@0 2298 if (TraceMetadataChunkAllocation && Verbose) {
aoqi@0 2299 gclog_or_tty->print_cr("updated freelist count %d %s",
aoqi@0 2300 chunk_manager()->free_chunks(i)->count(),
aoqi@0 2301 chunk_size_name(i));
aoqi@0 2302 }
aoqi@0 2303 assert(i != HumongousIndex, "Humongous chunks are handled explicitly later");
aoqi@0 2304 }
aoqi@0 2305
aoqi@0 2306 // The medium chunk case may be optimized by passing the head and
aoqi@0 2307 // tail of the medium chunk list to add_at_head(). The tail is often
aoqi@0 2308 // the current chunk but there are probably exceptions.
aoqi@0 2309
aoqi@0 2310 // Humongous chunks
aoqi@0 2311 if (TraceMetadataChunkAllocation && Verbose) {
aoqi@0 2312 gclog_or_tty->print_cr("returned %d %s humongous chunks to dictionary",
aoqi@0 2313 sum_count_in_chunks_in_use(HumongousIndex),
aoqi@0 2314 chunk_size_name(HumongousIndex));
aoqi@0 2315 gclog_or_tty->print("Humongous chunk dictionary: ");
aoqi@0 2316 }
aoqi@0 2317 // Humongous chunks are never the current chunk.
aoqi@0 2318 Metachunk* humongous_chunks = chunks_in_use(HumongousIndex);
aoqi@0 2319
aoqi@0 2320 while (humongous_chunks != NULL) {
aoqi@0 2321 #ifdef ASSERT
aoqi@0 2322 humongous_chunks->set_is_tagged_free(true);
aoqi@0 2323 #endif
aoqi@0 2324 if (TraceMetadataChunkAllocation && Verbose) {
aoqi@0 2325 gclog_or_tty->print(PTR_FORMAT " (" SIZE_FORMAT ") ",
aoqi@0 2326 humongous_chunks,
aoqi@0 2327 humongous_chunks->word_size());
aoqi@0 2328 }
aoqi@0 2329 assert(humongous_chunks->word_size() == (size_t)
aoqi@0 2330 align_size_up(humongous_chunks->word_size(),
aoqi@0 2331 smallest_chunk_size()),
aoqi@0 2332 err_msg("Humongous chunk size is wrong: word size " SIZE_FORMAT
aoqi@0 2333 " granularity %d",
aoqi@0 2334 humongous_chunks->word_size(), smallest_chunk_size()));
aoqi@0 2335 Metachunk* next_humongous_chunks = humongous_chunks->next();
aoqi@0 2336 humongous_chunks->container()->dec_container_count();
aoqi@0 2337 chunk_manager()->humongous_dictionary()->return_chunk(humongous_chunks);
aoqi@0 2338 humongous_chunks = next_humongous_chunks;
aoqi@0 2339 }
aoqi@0 2340 if (TraceMetadataChunkAllocation && Verbose) {
aoqi@0 2341 gclog_or_tty->cr();
aoqi@0 2342 gclog_or_tty->print_cr("updated dictionary count %d %s",
aoqi@0 2343 chunk_manager()->humongous_dictionary()->total_count(),
aoqi@0 2344 chunk_size_name(HumongousIndex));
aoqi@0 2345 }
aoqi@0 2346 chunk_manager()->slow_locked_verify();
aoqi@0 2347 }
aoqi@0 2348
aoqi@0 2349 const char* SpaceManager::chunk_size_name(ChunkIndex index) const {
aoqi@0 2350 switch (index) {
aoqi@0 2351 case SpecializedIndex:
aoqi@0 2352 return "Specialized";
aoqi@0 2353 case SmallIndex:
aoqi@0 2354 return "Small";
aoqi@0 2355 case MediumIndex:
aoqi@0 2356 return "Medium";
aoqi@0 2357 case HumongousIndex:
aoqi@0 2358 return "Humongous";
aoqi@0 2359 default:
aoqi@0 2360 return NULL;
aoqi@0 2361 }
aoqi@0 2362 }
aoqi@0 2363
aoqi@0 2364 ChunkIndex ChunkManager::list_index(size_t size) {
mchinnathamb@9064 2365 if (free_chunks(SpecializedIndex)->size() == size) {
mchinnathamb@9064 2366 return SpecializedIndex;
aoqi@0 2367 }
mchinnathamb@9064 2368 if (free_chunks(SmallIndex)->size() == size) {
mchinnathamb@9064 2369 return SmallIndex;
mchinnathamb@9064 2370 }
mchinnathamb@9064 2371 if (free_chunks(MediumIndex)->size() == size) {
mchinnathamb@9064 2372 return MediumIndex;
mchinnathamb@9064 2373 }
mchinnathamb@9064 2374
mchinnathamb@9064 2375 assert(size > free_chunks(MediumIndex)->size(), "Not a humongous chunk");
mchinnathamb@9064 2376 return HumongousIndex;
aoqi@0 2377 }
aoqi@0 2378
aoqi@0 2379 void SpaceManager::deallocate(MetaWord* p, size_t word_size) {
aoqi@0 2380 assert_lock_strong(_lock);
aoqi@0 2381 size_t raw_word_size = get_raw_word_size(word_size);
aoqi@0 2382 size_t min_size = TreeChunk<Metablock, FreeList<Metablock> >::min_size();
aoqi@0 2383 assert(raw_word_size >= min_size,
aoqi@0 2384 err_msg("Should not deallocate dark matter " SIZE_FORMAT "<" SIZE_FORMAT, word_size, min_size));
aoqi@0 2385 block_freelists()->return_block(p, raw_word_size);
aoqi@0 2386 }
aoqi@0 2387
aoqi@0 2388 // Adds a chunk to the list of chunks in use.
aoqi@0 2389 void SpaceManager::add_chunk(Metachunk* new_chunk, bool make_current) {
aoqi@0 2390
aoqi@0 2391 assert(new_chunk != NULL, "Should not be NULL");
aoqi@0 2392 assert(new_chunk->next() == NULL, "Should not be on a list");
aoqi@0 2393
aoqi@0 2394 new_chunk->reset_empty();
aoqi@0 2395
aoqi@0 2396 // Find the correct list and and set the current
aoqi@0 2397 // chunk for that list.
mchinnathamb@9064 2398 ChunkIndex index = chunk_manager()->list_index(new_chunk->word_size());
aoqi@0 2399
aoqi@0 2400 if (index != HumongousIndex) {
aoqi@0 2401 retire_current_chunk();
aoqi@0 2402 set_current_chunk(new_chunk);
aoqi@0 2403 new_chunk->set_next(chunks_in_use(index));
aoqi@0 2404 set_chunks_in_use(index, new_chunk);
aoqi@0 2405 } else {
aoqi@0 2406 // For null class loader data and DumpSharedSpaces, the first chunk isn't
aoqi@0 2407 // small, so small will be null. Link this first chunk as the current
aoqi@0 2408 // chunk.
aoqi@0 2409 if (make_current) {
aoqi@0 2410 // Set as the current chunk but otherwise treat as a humongous chunk.
aoqi@0 2411 set_current_chunk(new_chunk);
aoqi@0 2412 }
aoqi@0 2413 // Link at head. The _current_chunk only points to a humongous chunk for
aoqi@0 2414 // the null class loader metaspace (class and data virtual space managers)
aoqi@0 2415 // any humongous chunks so will not point to the tail
aoqi@0 2416 // of the humongous chunks list.
aoqi@0 2417 new_chunk->set_next(chunks_in_use(HumongousIndex));
aoqi@0 2418 set_chunks_in_use(HumongousIndex, new_chunk);
aoqi@0 2419
aoqi@0 2420 assert(new_chunk->word_size() > medium_chunk_size(), "List inconsistency");
aoqi@0 2421 }
aoqi@0 2422
aoqi@0 2423 // Add to the running sum of capacity
aoqi@0 2424 inc_size_metrics(new_chunk->word_size());
aoqi@0 2425
aoqi@0 2426 assert(new_chunk->is_empty(), "Not ready for reuse");
aoqi@0 2427 if (TraceMetadataChunkAllocation && Verbose) {
aoqi@0 2428 gclog_or_tty->print("SpaceManager::add_chunk: %d) ",
aoqi@0 2429 sum_count_in_chunks_in_use());
aoqi@0 2430 new_chunk->print_on(gclog_or_tty);
aoqi@0 2431 chunk_manager()->locked_print_free_chunks(gclog_or_tty);
aoqi@0 2432 }
aoqi@0 2433 }
aoqi@0 2434
aoqi@0 2435 void SpaceManager::retire_current_chunk() {
aoqi@0 2436 if (current_chunk() != NULL) {
aoqi@0 2437 size_t remaining_words = current_chunk()->free_word_size();
aoqi@0 2438 if (remaining_words >= TreeChunk<Metablock, FreeList<Metablock> >::min_size()) {
aoqi@0 2439 block_freelists()->return_block(current_chunk()->allocate(remaining_words), remaining_words);
aoqi@0 2440 inc_used_metrics(remaining_words);
aoqi@0 2441 }
aoqi@0 2442 }
aoqi@0 2443 }
aoqi@0 2444
mchinnathamb@9058 2445 Metachunk* SpaceManager::get_new_chunk(size_t chunk_word_size) {
aoqi@0 2446 // Get a chunk from the chunk freelist
mchinnathamb@9058 2447 Metachunk* next = chunk_manager()->chunk_freelist_allocate(chunk_word_size);
aoqi@0 2448
aoqi@0 2449 if (next == NULL) {
mchinnathamb@9058 2450 next = vs_list()->get_new_chunk(chunk_word_size,
aoqi@0 2451 medium_chunk_bunch());
aoqi@0 2452 }
aoqi@0 2453
aoqi@0 2454 if (TraceMetadataHumongousAllocation && next != NULL &&
aoqi@0 2455 SpaceManager::is_humongous(next->word_size())) {
aoqi@0 2456 gclog_or_tty->print_cr(" new humongous chunk word size "
aoqi@0 2457 PTR_FORMAT, next->word_size());
aoqi@0 2458 }
aoqi@0 2459
aoqi@0 2460 return next;
aoqi@0 2461 }
aoqi@0 2462
aoqi@0 2463 MetaWord* SpaceManager::allocate(size_t word_size) {
aoqi@0 2464 MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
aoqi@0 2465
aoqi@0 2466 size_t raw_word_size = get_raw_word_size(word_size);
aoqi@0 2467 BlockFreelist* fl = block_freelists();
aoqi@0 2468 MetaWord* p = NULL;
aoqi@0 2469 // Allocation from the dictionary is expensive in the sense that
aoqi@0 2470 // the dictionary has to be searched for a size. Don't allocate
aoqi@0 2471 // from the dictionary until it starts to get fat. Is this
aoqi@0 2472 // a reasonable policy? Maybe an skinny dictionary is fast enough
aoqi@0 2473 // for allocations. Do some profiling. JJJ
aoqi@0 2474 if (fl->total_size() > allocation_from_dictionary_limit) {
aoqi@0 2475 p = fl->get_block(raw_word_size);
aoqi@0 2476 }
aoqi@0 2477 if (p == NULL) {
aoqi@0 2478 p = allocate_work(raw_word_size);
aoqi@0 2479 }
aoqi@0 2480
aoqi@0 2481 return p;
aoqi@0 2482 }
aoqi@0 2483
aoqi@0 2484 // Returns the address of spaced allocated for "word_size".
aoqi@0 2485 // This methods does not know about blocks (Metablocks)
aoqi@0 2486 MetaWord* SpaceManager::allocate_work(size_t word_size) {
aoqi@0 2487 assert_lock_strong(_lock);
aoqi@0 2488 #ifdef ASSERT
aoqi@0 2489 if (Metadebug::test_metadata_failure()) {
aoqi@0 2490 return NULL;
aoqi@0 2491 }
aoqi@0 2492 #endif
aoqi@0 2493 // Is there space in the current chunk?
aoqi@0 2494 MetaWord* result = NULL;
aoqi@0 2495
aoqi@0 2496 // For DumpSharedSpaces, only allocate out of the current chunk which is
aoqi@0 2497 // never null because we gave it the size we wanted. Caller reports out
aoqi@0 2498 // of memory if this returns null.
aoqi@0 2499 if (DumpSharedSpaces) {
aoqi@0 2500 assert(current_chunk() != NULL, "should never happen");
aoqi@0 2501 inc_used_metrics(word_size);
aoqi@0 2502 return current_chunk()->allocate(word_size); // caller handles null result
aoqi@0 2503 }
aoqi@0 2504
aoqi@0 2505 if (current_chunk() != NULL) {
aoqi@0 2506 result = current_chunk()->allocate(word_size);
aoqi@0 2507 }
aoqi@0 2508
aoqi@0 2509 if (result == NULL) {
aoqi@0 2510 result = grow_and_allocate(word_size);
aoqi@0 2511 }
aoqi@0 2512
aoqi@0 2513 if (result != NULL) {
aoqi@0 2514 inc_used_metrics(word_size);
aoqi@0 2515 assert(result != (MetaWord*) chunks_in_use(MediumIndex),
aoqi@0 2516 "Head of the list is being allocated");
aoqi@0 2517 }
aoqi@0 2518
aoqi@0 2519 return result;
aoqi@0 2520 }
aoqi@0 2521
aoqi@0 2522 void SpaceManager::verify() {
aoqi@0 2523 // If there are blocks in the dictionary, then
aoqi@0 2524 // verfication of chunks does not work since
aoqi@0 2525 // being in the dictionary alters a chunk.
aoqi@0 2526 if (block_freelists()->total_size() == 0) {
aoqi@0 2527 for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
aoqi@0 2528 Metachunk* curr = chunks_in_use(i);
aoqi@0 2529 while (curr != NULL) {
aoqi@0 2530 curr->verify();
aoqi@0 2531 verify_chunk_size(curr);
aoqi@0 2532 curr = curr->next();
aoqi@0 2533 }
aoqi@0 2534 }
aoqi@0 2535 }
aoqi@0 2536 }
aoqi@0 2537
aoqi@0 2538 void SpaceManager::verify_chunk_size(Metachunk* chunk) {
aoqi@0 2539 assert(is_humongous(chunk->word_size()) ||
aoqi@0 2540 chunk->word_size() == medium_chunk_size() ||
aoqi@0 2541 chunk->word_size() == small_chunk_size() ||
aoqi@0 2542 chunk->word_size() == specialized_chunk_size(),
aoqi@0 2543 "Chunk size is wrong");
aoqi@0 2544 return;
aoqi@0 2545 }
aoqi@0 2546
aoqi@0 2547 #ifdef ASSERT
aoqi@0 2548 void SpaceManager::verify_allocated_blocks_words() {
aoqi@0 2549 // Verification is only guaranteed at a safepoint.
aoqi@0 2550 assert(SafepointSynchronize::is_at_safepoint() || !Universe::is_fully_initialized(),
aoqi@0 2551 "Verification can fail if the applications is running");
aoqi@0 2552 assert(allocated_blocks_words() == sum_used_in_chunks_in_use(),
aoqi@0 2553 err_msg("allocation total is not consistent " SIZE_FORMAT
aoqi@0 2554 " vs " SIZE_FORMAT,
aoqi@0 2555 allocated_blocks_words(), sum_used_in_chunks_in_use()));
aoqi@0 2556 }
aoqi@0 2557
aoqi@0 2558 #endif
aoqi@0 2559
aoqi@0 2560 void SpaceManager::dump(outputStream* const out) const {
aoqi@0 2561 size_t curr_total = 0;
aoqi@0 2562 size_t waste = 0;
aoqi@0 2563 uint i = 0;
aoqi@0 2564 size_t used = 0;
aoqi@0 2565 size_t capacity = 0;
aoqi@0 2566
aoqi@0 2567 // Add up statistics for all chunks in this SpaceManager.
aoqi@0 2568 for (ChunkIndex index = ZeroIndex;
aoqi@0 2569 index < NumberOfInUseLists;
aoqi@0 2570 index = next_chunk_index(index)) {
aoqi@0 2571 for (Metachunk* curr = chunks_in_use(index);
aoqi@0 2572 curr != NULL;
aoqi@0 2573 curr = curr->next()) {
aoqi@0 2574 out->print("%d) ", i++);
aoqi@0 2575 curr->print_on(out);
aoqi@0 2576 curr_total += curr->word_size();
aoqi@0 2577 used += curr->used_word_size();
aoqi@0 2578 capacity += curr->word_size();
aoqi@0 2579 waste += curr->free_word_size() + curr->overhead();;
aoqi@0 2580 }
aoqi@0 2581 }
aoqi@0 2582
aoqi@0 2583 if (TraceMetadataChunkAllocation && Verbose) {
aoqi@0 2584 block_freelists()->print_on(out);
aoqi@0 2585 }
aoqi@0 2586
aoqi@0 2587 size_t free = current_chunk() == NULL ? 0 : current_chunk()->free_word_size();
aoqi@0 2588 // Free space isn't wasted.
aoqi@0 2589 waste -= free;
aoqi@0 2590
aoqi@0 2591 out->print_cr("total of all chunks " SIZE_FORMAT " used " SIZE_FORMAT
aoqi@0 2592 " free " SIZE_FORMAT " capacity " SIZE_FORMAT
aoqi@0 2593 " waste " SIZE_FORMAT, curr_total, used, free, capacity, waste);
aoqi@0 2594 }
aoqi@0 2595
aoqi@0 2596 #ifndef PRODUCT
aoqi@0 2597 void SpaceManager::mangle_freed_chunks() {
aoqi@0 2598 for (ChunkIndex index = ZeroIndex;
aoqi@0 2599 index < NumberOfInUseLists;
aoqi@0 2600 index = next_chunk_index(index)) {
aoqi@0 2601 for (Metachunk* curr = chunks_in_use(index);
aoqi@0 2602 curr != NULL;
aoqi@0 2603 curr = curr->next()) {
aoqi@0 2604 curr->mangle();
aoqi@0 2605 }
aoqi@0 2606 }
aoqi@0 2607 }
aoqi@0 2608 #endif // PRODUCT
aoqi@0 2609
aoqi@0 2610 // MetaspaceAux
aoqi@0 2611
aoqi@0 2612
aoqi@0 2613 size_t MetaspaceAux::_capacity_words[] = {0, 0};
aoqi@0 2614 size_t MetaspaceAux::_used_words[] = {0, 0};
aoqi@0 2615
aoqi@0 2616 size_t MetaspaceAux::free_bytes(Metaspace::MetadataType mdtype) {
aoqi@0 2617 VirtualSpaceList* list = Metaspace::get_space_list(mdtype);
aoqi@0 2618 return list == NULL ? 0 : list->free_bytes();
aoqi@0 2619 }
aoqi@0 2620
aoqi@0 2621 size_t MetaspaceAux::free_bytes() {
aoqi@0 2622 return free_bytes(Metaspace::ClassType) + free_bytes(Metaspace::NonClassType);
aoqi@0 2623 }
aoqi@0 2624
aoqi@0 2625 void MetaspaceAux::dec_capacity(Metaspace::MetadataType mdtype, size_t words) {
aoqi@0 2626 assert_lock_strong(SpaceManager::expand_lock());
aoqi@0 2627 assert(words <= capacity_words(mdtype),
aoqi@0 2628 err_msg("About to decrement below 0: words " SIZE_FORMAT
aoqi@0 2629 " is greater than _capacity_words[%u] " SIZE_FORMAT,
aoqi@0 2630 words, mdtype, capacity_words(mdtype)));
aoqi@0 2631 _capacity_words[mdtype] -= words;
aoqi@0 2632 }
aoqi@0 2633
aoqi@0 2634 void MetaspaceAux::inc_capacity(Metaspace::MetadataType mdtype, size_t words) {
aoqi@0 2635 assert_lock_strong(SpaceManager::expand_lock());
aoqi@0 2636 // Needs to be atomic
aoqi@0 2637 _capacity_words[mdtype] += words;
aoqi@0 2638 }
aoqi@0 2639
aoqi@0 2640 void MetaspaceAux::dec_used(Metaspace::MetadataType mdtype, size_t words) {
aoqi@0 2641 assert(words <= used_words(mdtype),
aoqi@0 2642 err_msg("About to decrement below 0: words " SIZE_FORMAT
aoqi@0 2643 " is greater than _used_words[%u] " SIZE_FORMAT,
aoqi@0 2644 words, mdtype, used_words(mdtype)));
aoqi@0 2645 // For CMS deallocation of the Metaspaces occurs during the
aoqi@0 2646 // sweep which is a concurrent phase. Protection by the expand_lock()
aoqi@0 2647 // is not enough since allocation is on a per Metaspace basis
aoqi@0 2648 // and protected by the Metaspace lock.
aoqi@0 2649 jlong minus_words = (jlong) - (jlong) words;
aoqi@0 2650 Atomic::add_ptr(minus_words, &_used_words[mdtype]);
aoqi@0 2651 }
aoqi@0 2652
aoqi@0 2653 void MetaspaceAux::inc_used(Metaspace::MetadataType mdtype, size_t words) {
aoqi@0 2654 // _used_words tracks allocations for
aoqi@0 2655 // each piece of metadata. Those allocations are
aoqi@0 2656 // generally done concurrently by different application
aoqi@0 2657 // threads so must be done atomically.
aoqi@0 2658 Atomic::add_ptr(words, &_used_words[mdtype]);
aoqi@0 2659 }
aoqi@0 2660
aoqi@0 2661 size_t MetaspaceAux::used_bytes_slow(Metaspace::MetadataType mdtype) {
aoqi@0 2662 size_t used = 0;
aoqi@0 2663 ClassLoaderDataGraphMetaspaceIterator iter;
aoqi@0 2664 while (iter.repeat()) {
aoqi@0 2665 Metaspace* msp = iter.get_next();
aoqi@0 2666 // Sum allocated_blocks_words for each metaspace
aoqi@0 2667 if (msp != NULL) {
aoqi@0 2668 used += msp->used_words_slow(mdtype);
aoqi@0 2669 }
aoqi@0 2670 }
aoqi@0 2671 return used * BytesPerWord;
aoqi@0 2672 }
aoqi@0 2673
aoqi@0 2674 size_t MetaspaceAux::free_bytes_slow(Metaspace::MetadataType mdtype) {
aoqi@0 2675 size_t free = 0;
aoqi@0 2676 ClassLoaderDataGraphMetaspaceIterator iter;
aoqi@0 2677 while (iter.repeat()) {
aoqi@0 2678 Metaspace* msp = iter.get_next();
aoqi@0 2679 if (msp != NULL) {
aoqi@0 2680 free += msp->free_words_slow(mdtype);
aoqi@0 2681 }
aoqi@0 2682 }
aoqi@0 2683 return free * BytesPerWord;
aoqi@0 2684 }
aoqi@0 2685
aoqi@0 2686 size_t MetaspaceAux::capacity_bytes_slow(Metaspace::MetadataType mdtype) {
aoqi@0 2687 if ((mdtype == Metaspace::ClassType) && !Metaspace::using_class_space()) {
aoqi@0 2688 return 0;
aoqi@0 2689 }
aoqi@0 2690 // Don't count the space in the freelists. That space will be
aoqi@0 2691 // added to the capacity calculation as needed.
aoqi@0 2692 size_t capacity = 0;
aoqi@0 2693 ClassLoaderDataGraphMetaspaceIterator iter;
aoqi@0 2694 while (iter.repeat()) {
aoqi@0 2695 Metaspace* msp = iter.get_next();
aoqi@0 2696 if (msp != NULL) {
aoqi@0 2697 capacity += msp->capacity_words_slow(mdtype);
aoqi@0 2698 }
aoqi@0 2699 }
aoqi@0 2700 return capacity * BytesPerWord;
aoqi@0 2701 }
aoqi@0 2702
aoqi@0 2703 size_t MetaspaceAux::capacity_bytes_slow() {
aoqi@0 2704 #ifdef PRODUCT
aoqi@0 2705 // Use capacity_bytes() in PRODUCT instead of this function.
aoqi@0 2706 guarantee(false, "Should not call capacity_bytes_slow() in the PRODUCT");
aoqi@0 2707 #endif
aoqi@0 2708 size_t class_capacity = capacity_bytes_slow(Metaspace::ClassType);
aoqi@0 2709 size_t non_class_capacity = capacity_bytes_slow(Metaspace::NonClassType);
aoqi@0 2710 assert(capacity_bytes() == class_capacity + non_class_capacity,
aoqi@0 2711 err_msg("bad accounting: capacity_bytes() " SIZE_FORMAT
aoqi@0 2712 " class_capacity + non_class_capacity " SIZE_FORMAT
aoqi@0 2713 " class_capacity " SIZE_FORMAT " non_class_capacity " SIZE_FORMAT,
aoqi@0 2714 capacity_bytes(), class_capacity + non_class_capacity,
aoqi@0 2715 class_capacity, non_class_capacity));
aoqi@0 2716
aoqi@0 2717 return class_capacity + non_class_capacity;
aoqi@0 2718 }
aoqi@0 2719
aoqi@0 2720 size_t MetaspaceAux::reserved_bytes(Metaspace::MetadataType mdtype) {
aoqi@0 2721 VirtualSpaceList* list = Metaspace::get_space_list(mdtype);
aoqi@0 2722 return list == NULL ? 0 : list->reserved_bytes();
aoqi@0 2723 }
aoqi@0 2724
aoqi@0 2725 size_t MetaspaceAux::committed_bytes(Metaspace::MetadataType mdtype) {
aoqi@0 2726 VirtualSpaceList* list = Metaspace::get_space_list(mdtype);
aoqi@0 2727 return list == NULL ? 0 : list->committed_bytes();
aoqi@0 2728 }
aoqi@0 2729
aoqi@0 2730 size_t MetaspaceAux::min_chunk_size_words() { return Metaspace::first_chunk_word_size(); }
aoqi@0 2731
aoqi@0 2732 size_t MetaspaceAux::free_chunks_total_words(Metaspace::MetadataType mdtype) {
aoqi@0 2733 ChunkManager* chunk_manager = Metaspace::get_chunk_manager(mdtype);
aoqi@0 2734 if (chunk_manager == NULL) {
aoqi@0 2735 return 0;
aoqi@0 2736 }
aoqi@0 2737 chunk_manager->slow_verify();
aoqi@0 2738 return chunk_manager->free_chunks_total_words();
aoqi@0 2739 }
aoqi@0 2740
aoqi@0 2741 size_t MetaspaceAux::free_chunks_total_bytes(Metaspace::MetadataType mdtype) {
aoqi@0 2742 return free_chunks_total_words(mdtype) * BytesPerWord;
aoqi@0 2743 }
aoqi@0 2744
aoqi@0 2745 size_t MetaspaceAux::free_chunks_total_words() {
aoqi@0 2746 return free_chunks_total_words(Metaspace::ClassType) +
aoqi@0 2747 free_chunks_total_words(Metaspace::NonClassType);
aoqi@0 2748 }
aoqi@0 2749
aoqi@0 2750 size_t MetaspaceAux::free_chunks_total_bytes() {
aoqi@0 2751 return free_chunks_total_words() * BytesPerWord;
aoqi@0 2752 }
aoqi@0 2753
aoqi@0 2754 bool MetaspaceAux::has_chunk_free_list(Metaspace::MetadataType mdtype) {
aoqi@0 2755 return Metaspace::get_chunk_manager(mdtype) != NULL;
aoqi@0 2756 }
aoqi@0 2757
aoqi@0 2758 MetaspaceChunkFreeListSummary MetaspaceAux::chunk_free_list_summary(Metaspace::MetadataType mdtype) {
aoqi@0 2759 if (!has_chunk_free_list(mdtype)) {
aoqi@0 2760 return MetaspaceChunkFreeListSummary();
aoqi@0 2761 }
aoqi@0 2762
aoqi@0 2763 const ChunkManager* cm = Metaspace::get_chunk_manager(mdtype);
aoqi@0 2764 return cm->chunk_free_list_summary();
aoqi@0 2765 }
aoqi@0 2766
aoqi@0 2767 void MetaspaceAux::print_metaspace_change(size_t prev_metadata_used) {
aoqi@0 2768 gclog_or_tty->print(", [Metaspace:");
aoqi@0 2769 if (PrintGCDetails && Verbose) {
aoqi@0 2770 gclog_or_tty->print(" " SIZE_FORMAT
aoqi@0 2771 "->" SIZE_FORMAT
aoqi@0 2772 "(" SIZE_FORMAT ")",
aoqi@0 2773 prev_metadata_used,
aoqi@0 2774 used_bytes(),
aoqi@0 2775 reserved_bytes());
aoqi@0 2776 } else {
aoqi@0 2777 gclog_or_tty->print(" " SIZE_FORMAT "K"
aoqi@0 2778 "->" SIZE_FORMAT "K"
aoqi@0 2779 "(" SIZE_FORMAT "K)",
aoqi@0 2780 prev_metadata_used/K,
aoqi@0 2781 used_bytes()/K,
aoqi@0 2782 reserved_bytes()/K);
aoqi@0 2783 }
aoqi@0 2784
aoqi@0 2785 gclog_or_tty->print("]");
aoqi@0 2786 }
aoqi@0 2787
aoqi@0 2788 // This is printed when PrintGCDetails
aoqi@0 2789 void MetaspaceAux::print_on(outputStream* out) {
aoqi@0 2790 Metaspace::MetadataType nct = Metaspace::NonClassType;
aoqi@0 2791
aoqi@0 2792 out->print_cr(" Metaspace "
aoqi@0 2793 "used " SIZE_FORMAT "K, "
aoqi@0 2794 "capacity " SIZE_FORMAT "K, "
aoqi@0 2795 "committed " SIZE_FORMAT "K, "
aoqi@0 2796 "reserved " SIZE_FORMAT "K",
aoqi@0 2797 used_bytes()/K,
aoqi@0 2798 capacity_bytes()/K,
aoqi@0 2799 committed_bytes()/K,
aoqi@0 2800 reserved_bytes()/K);
aoqi@0 2801
aoqi@0 2802 if (Metaspace::using_class_space()) {
aoqi@0 2803 Metaspace::MetadataType ct = Metaspace::ClassType;
aoqi@0 2804 out->print_cr(" class space "
aoqi@0 2805 "used " SIZE_FORMAT "K, "
aoqi@0 2806 "capacity " SIZE_FORMAT "K, "
aoqi@0 2807 "committed " SIZE_FORMAT "K, "
aoqi@0 2808 "reserved " SIZE_FORMAT "K",
aoqi@0 2809 used_bytes(ct)/K,
aoqi@0 2810 capacity_bytes(ct)/K,
aoqi@0 2811 committed_bytes(ct)/K,
aoqi@0 2812 reserved_bytes(ct)/K);
aoqi@0 2813 }
aoqi@0 2814 }
aoqi@0 2815
aoqi@0 2816 // Print information for class space and data space separately.
aoqi@0 2817 // This is almost the same as above.
aoqi@0 2818 void MetaspaceAux::print_on(outputStream* out, Metaspace::MetadataType mdtype) {
aoqi@0 2819 size_t free_chunks_capacity_bytes = free_chunks_total_bytes(mdtype);
aoqi@0 2820 size_t capacity_bytes = capacity_bytes_slow(mdtype);
aoqi@0 2821 size_t used_bytes = used_bytes_slow(mdtype);
aoqi@0 2822 size_t free_bytes = free_bytes_slow(mdtype);
aoqi@0 2823 size_t used_and_free = used_bytes + free_bytes +
aoqi@0 2824 free_chunks_capacity_bytes;
aoqi@0 2825 out->print_cr(" Chunk accounting: used in chunks " SIZE_FORMAT
aoqi@0 2826 "K + unused in chunks " SIZE_FORMAT "K + "
aoqi@0 2827 " capacity in free chunks " SIZE_FORMAT "K = " SIZE_FORMAT
aoqi@0 2828 "K capacity in allocated chunks " SIZE_FORMAT "K",
aoqi@0 2829 used_bytes / K,
aoqi@0 2830 free_bytes / K,
aoqi@0 2831 free_chunks_capacity_bytes / K,
aoqi@0 2832 used_and_free / K,
aoqi@0 2833 capacity_bytes / K);
aoqi@0 2834 // Accounting can only be correct if we got the values during a safepoint
aoqi@0 2835 assert(!SafepointSynchronize::is_at_safepoint() || used_and_free == capacity_bytes, "Accounting is wrong");
aoqi@0 2836 }
aoqi@0 2837
aoqi@0 2838 // Print total fragmentation for class metaspaces
aoqi@0 2839 void MetaspaceAux::print_class_waste(outputStream* out) {
aoqi@0 2840 assert(Metaspace::using_class_space(), "class metaspace not used");
aoqi@0 2841 size_t cls_specialized_waste = 0, cls_small_waste = 0, cls_medium_waste = 0;
aoqi@0 2842 size_t cls_specialized_count = 0, cls_small_count = 0, cls_medium_count = 0, cls_humongous_count = 0;
aoqi@0 2843 ClassLoaderDataGraphMetaspaceIterator iter;
aoqi@0 2844 while (iter.repeat()) {
aoqi@0 2845 Metaspace* msp = iter.get_next();
aoqi@0 2846 if (msp != NULL) {
aoqi@0 2847 cls_specialized_waste += msp->class_vsm()->sum_waste_in_chunks_in_use(SpecializedIndex);
aoqi@0 2848 cls_specialized_count += msp->class_vsm()->sum_count_in_chunks_in_use(SpecializedIndex);
aoqi@0 2849 cls_small_waste += msp->class_vsm()->sum_waste_in_chunks_in_use(SmallIndex);
aoqi@0 2850 cls_small_count += msp->class_vsm()->sum_count_in_chunks_in_use(SmallIndex);
aoqi@0 2851 cls_medium_waste += msp->class_vsm()->sum_waste_in_chunks_in_use(MediumIndex);
aoqi@0 2852 cls_medium_count += msp->class_vsm()->sum_count_in_chunks_in_use(MediumIndex);
aoqi@0 2853 cls_humongous_count += msp->class_vsm()->sum_count_in_chunks_in_use(HumongousIndex);
aoqi@0 2854 }
aoqi@0 2855 }
aoqi@0 2856 out->print_cr(" class: " SIZE_FORMAT " specialized(s) " SIZE_FORMAT ", "
aoqi@0 2857 SIZE_FORMAT " small(s) " SIZE_FORMAT ", "
aoqi@0 2858 SIZE_FORMAT " medium(s) " SIZE_FORMAT ", "
aoqi@0 2859 "large count " SIZE_FORMAT,
aoqi@0 2860 cls_specialized_count, cls_specialized_waste,
aoqi@0 2861 cls_small_count, cls_small_waste,
aoqi@0 2862 cls_medium_count, cls_medium_waste, cls_humongous_count);
aoqi@0 2863 }
aoqi@0 2864
aoqi@0 2865 // Print total fragmentation for data and class metaspaces separately
aoqi@0 2866 void MetaspaceAux::print_waste(outputStream* out) {
aoqi@0 2867 size_t specialized_waste = 0, small_waste = 0, medium_waste = 0;
aoqi@0 2868 size_t specialized_count = 0, small_count = 0, medium_count = 0, humongous_count = 0;
aoqi@0 2869
aoqi@0 2870 ClassLoaderDataGraphMetaspaceIterator iter;
aoqi@0 2871 while (iter.repeat()) {
aoqi@0 2872 Metaspace* msp = iter.get_next();
aoqi@0 2873 if (msp != NULL) {
aoqi@0 2874 specialized_waste += msp->vsm()->sum_waste_in_chunks_in_use(SpecializedIndex);
aoqi@0 2875 specialized_count += msp->vsm()->sum_count_in_chunks_in_use(SpecializedIndex);
aoqi@0 2876 small_waste += msp->vsm()->sum_waste_in_chunks_in_use(SmallIndex);
aoqi@0 2877 small_count += msp->vsm()->sum_count_in_chunks_in_use(SmallIndex);
aoqi@0 2878 medium_waste += msp->vsm()->sum_waste_in_chunks_in_use(MediumIndex);
aoqi@0 2879 medium_count += msp->vsm()->sum_count_in_chunks_in_use(MediumIndex);
aoqi@0 2880 humongous_count += msp->vsm()->sum_count_in_chunks_in_use(HumongousIndex);
aoqi@0 2881 }
aoqi@0 2882 }
aoqi@0 2883 out->print_cr("Total fragmentation waste (words) doesn't count free space");
aoqi@0 2884 out->print_cr(" data: " SIZE_FORMAT " specialized(s) " SIZE_FORMAT ", "
aoqi@0 2885 SIZE_FORMAT " small(s) " SIZE_FORMAT ", "
aoqi@0 2886 SIZE_FORMAT " medium(s) " SIZE_FORMAT ", "
aoqi@0 2887 "large count " SIZE_FORMAT,
aoqi@0 2888 specialized_count, specialized_waste, small_count,
aoqi@0 2889 small_waste, medium_count, medium_waste, humongous_count);
aoqi@0 2890 if (Metaspace::using_class_space()) {
aoqi@0 2891 print_class_waste(out);
aoqi@0 2892 }
aoqi@0 2893 }
aoqi@0 2894
aoqi@0 2895 // Dump global metaspace things from the end of ClassLoaderDataGraph
aoqi@0 2896 void MetaspaceAux::dump(outputStream* out) {
aoqi@0 2897 out->print_cr("All Metaspace:");
aoqi@0 2898 out->print("data space: "); print_on(out, Metaspace::NonClassType);
aoqi@0 2899 out->print("class space: "); print_on(out, Metaspace::ClassType);
aoqi@0 2900 print_waste(out);
aoqi@0 2901 }
aoqi@0 2902
aoqi@0 2903 void MetaspaceAux::verify_free_chunks() {
aoqi@0 2904 Metaspace::chunk_manager_metadata()->verify();
aoqi@0 2905 if (Metaspace::using_class_space()) {
aoqi@0 2906 Metaspace::chunk_manager_class()->verify();
aoqi@0 2907 }
aoqi@0 2908 }
aoqi@0 2909
aoqi@0 2910 void MetaspaceAux::verify_capacity() {
aoqi@0 2911 #ifdef ASSERT
aoqi@0 2912 size_t running_sum_capacity_bytes = capacity_bytes();
aoqi@0 2913 // For purposes of the running sum of capacity, verify against capacity
aoqi@0 2914 size_t capacity_in_use_bytes = capacity_bytes_slow();
aoqi@0 2915 assert(running_sum_capacity_bytes == capacity_in_use_bytes,
aoqi@0 2916 err_msg("capacity_words() * BytesPerWord " SIZE_FORMAT
aoqi@0 2917 " capacity_bytes_slow()" SIZE_FORMAT,
aoqi@0 2918 running_sum_capacity_bytes, capacity_in_use_bytes));
aoqi@0 2919 for (Metaspace::MetadataType i = Metaspace::ClassType;
aoqi@0 2920 i < Metaspace:: MetadataTypeCount;
aoqi@0 2921 i = (Metaspace::MetadataType)(i + 1)) {
aoqi@0 2922 size_t capacity_in_use_bytes = capacity_bytes_slow(i);
aoqi@0 2923 assert(capacity_bytes(i) == capacity_in_use_bytes,
aoqi@0 2924 err_msg("capacity_bytes(%u) " SIZE_FORMAT
aoqi@0 2925 " capacity_bytes_slow(%u)" SIZE_FORMAT,
aoqi@0 2926 i, capacity_bytes(i), i, capacity_in_use_bytes));
aoqi@0 2927 }
aoqi@0 2928 #endif
aoqi@0 2929 }
aoqi@0 2930
aoqi@0 2931 void MetaspaceAux::verify_used() {
aoqi@0 2932 #ifdef ASSERT
aoqi@0 2933 size_t running_sum_used_bytes = used_bytes();
aoqi@0 2934 // For purposes of the running sum of used, verify against used
aoqi@0 2935 size_t used_in_use_bytes = used_bytes_slow();
aoqi@0 2936 assert(used_bytes() == used_in_use_bytes,
aoqi@0 2937 err_msg("used_bytes() " SIZE_FORMAT
aoqi@0 2938 " used_bytes_slow()" SIZE_FORMAT,
aoqi@0 2939 used_bytes(), used_in_use_bytes));
aoqi@0 2940 for (Metaspace::MetadataType i = Metaspace::ClassType;
aoqi@0 2941 i < Metaspace:: MetadataTypeCount;
aoqi@0 2942 i = (Metaspace::MetadataType)(i + 1)) {
aoqi@0 2943 size_t used_in_use_bytes = used_bytes_slow(i);
aoqi@0 2944 assert(used_bytes(i) == used_in_use_bytes,
aoqi@0 2945 err_msg("used_bytes(%u) " SIZE_FORMAT
aoqi@0 2946 " used_bytes_slow(%u)" SIZE_FORMAT,
aoqi@0 2947 i, used_bytes(i), i, used_in_use_bytes));
aoqi@0 2948 }
aoqi@0 2949 #endif
aoqi@0 2950 }
aoqi@0 2951
aoqi@0 2952 void MetaspaceAux::verify_metrics() {
aoqi@0 2953 verify_capacity();
aoqi@0 2954 verify_used();
aoqi@0 2955 }
aoqi@0 2956
aoqi@0 2957
aoqi@0 2958 // Metaspace methods
aoqi@0 2959
aoqi@0 2960 size_t Metaspace::_first_chunk_word_size = 0;
aoqi@0 2961 size_t Metaspace::_first_class_chunk_word_size = 0;
aoqi@0 2962
aoqi@0 2963 size_t Metaspace::_commit_alignment = 0;
aoqi@0 2964 size_t Metaspace::_reserve_alignment = 0;
aoqi@0 2965
aoqi@0 2966 Metaspace::Metaspace(Mutex* lock, MetaspaceType type) {
aoqi@0 2967 initialize(lock, type);
aoqi@0 2968 }
aoqi@0 2969
aoqi@0 2970 Metaspace::~Metaspace() {
aoqi@0 2971 delete _vsm;
aoqi@0 2972 if (using_class_space()) {
aoqi@0 2973 delete _class_vsm;
aoqi@0 2974 }
aoqi@0 2975 }
aoqi@0 2976
aoqi@0 2977 VirtualSpaceList* Metaspace::_space_list = NULL;
aoqi@0 2978 VirtualSpaceList* Metaspace::_class_space_list = NULL;
aoqi@0 2979
aoqi@0 2980 ChunkManager* Metaspace::_chunk_manager_metadata = NULL;
aoqi@0 2981 ChunkManager* Metaspace::_chunk_manager_class = NULL;
aoqi@0 2982
aoqi@0 2983 #define VIRTUALSPACEMULTIPLIER 2
aoqi@0 2984
aoqi@0 2985 #ifdef _LP64
aoqi@0 2986 static const uint64_t UnscaledClassSpaceMax = (uint64_t(max_juint) + 1);
aoqi@0 2987
aoqi@0 2988 void Metaspace::set_narrow_klass_base_and_shift(address metaspace_base, address cds_base) {
aoqi@0 2989 // Figure out the narrow_klass_base and the narrow_klass_shift. The
aoqi@0 2990 // narrow_klass_base is the lower of the metaspace base and the cds base
aoqi@0 2991 // (if cds is enabled). The narrow_klass_shift depends on the distance
aoqi@0 2992 // between the lower base and higher address.
aoqi@0 2993 address lower_base;
aoqi@0 2994 address higher_address;
iklam@7089 2995 #if INCLUDE_CDS
aoqi@0 2996 if (UseSharedSpaces) {
aoqi@0 2997 higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()),
aoqi@0 2998 (address)(metaspace_base + compressed_class_space_size()));
aoqi@0 2999 lower_base = MIN2(metaspace_base, cds_base);
iklam@7089 3000 } else
iklam@7089 3001 #endif
iklam@7089 3002 {
aoqi@0 3003 higher_address = metaspace_base + compressed_class_space_size();
aoqi@0 3004 lower_base = metaspace_base;
aoqi@0 3005
aoqi@0 3006 uint64_t klass_encoding_max = UnscaledClassSpaceMax << LogKlassAlignmentInBytes;
aoqi@0 3007 // If compressed class space fits in lower 32G, we don't need a base.
aoqi@0 3008 if (higher_address <= (address)klass_encoding_max) {
aoqi@0 3009 lower_base = 0; // effectively lower base is zero.
aoqi@0 3010 }
aoqi@0 3011 }
aoqi@0 3012
aoqi@0 3013 Universe::set_narrow_klass_base(lower_base);
aoqi@0 3014
aoqi@0 3015 if ((uint64_t)(higher_address - lower_base) <= UnscaledClassSpaceMax) {
aoqi@0 3016 Universe::set_narrow_klass_shift(0);
aoqi@0 3017 } else {
aoqi@0 3018 assert(!UseSharedSpaces, "Cannot shift with UseSharedSpaces");
aoqi@0 3019 Universe::set_narrow_klass_shift(LogKlassAlignmentInBytes);
aoqi@0 3020 }
aoqi@0 3021 }
aoqi@0 3022
iklam@7089 3023 #if INCLUDE_CDS
aoqi@0 3024 // Return TRUE if the specified metaspace_base and cds_base are close enough
aoqi@0 3025 // to work with compressed klass pointers.
aoqi@0 3026 bool Metaspace::can_use_cds_with_metaspace_addr(char* metaspace_base, address cds_base) {
aoqi@0 3027 assert(cds_base != 0 && UseSharedSpaces, "Only use with CDS");
aoqi@0 3028 assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs");
aoqi@0 3029 address lower_base = MIN2((address)metaspace_base, cds_base);
aoqi@0 3030 address higher_address = MAX2((address)(cds_base + FileMapInfo::shared_spaces_size()),
aoqi@0 3031 (address)(metaspace_base + compressed_class_space_size()));
aoqi@0 3032 return ((uint64_t)(higher_address - lower_base) <= UnscaledClassSpaceMax);
aoqi@0 3033 }
iklam@7089 3034 #endif
aoqi@0 3035
aoqi@0 3036 // Try to allocate the metaspace at the requested addr.
aoqi@0 3037 void Metaspace::allocate_metaspace_compressed_klass_ptrs(char* requested_addr, address cds_base) {
aoqi@0 3038 assert(using_class_space(), "called improperly");
aoqi@0 3039 assert(UseCompressedClassPointers, "Only use with CompressedKlassPtrs");
aoqi@0 3040 assert(compressed_class_space_size() < KlassEncodingMetaspaceMax,
aoqi@0 3041 "Metaspace size is too big");
aoqi@0 3042 assert_is_ptr_aligned(requested_addr, _reserve_alignment);
aoqi@0 3043 assert_is_ptr_aligned(cds_base, _reserve_alignment);
aoqi@0 3044 assert_is_size_aligned(compressed_class_space_size(), _reserve_alignment);
aoqi@0 3045
aoqi@0 3046 // Don't use large pages for the class space.
aoqi@0 3047 bool large_pages = false;
aoqi@0 3048
wanghaomin@9268 3049 #ifndef MIPS64
aoqi@0 3050 ReservedSpace metaspace_rs = ReservedSpace(compressed_class_space_size(),
aoqi@0 3051 _reserve_alignment,
aoqi@0 3052 large_pages,
aoqi@0 3053 requested_addr, 0);
wanghaomin@9268 3054 #else // MIPS64
wanghaomin@9268 3055 ReservedSpace metaspace_rs;
wanghaomin@9268 3056
wanghaomin@9268 3057 // Our compressed klass pointers may fit nicely into the lower 32
wanghaomin@9268 3058 // bits.
wanghaomin@9268 3059 if ((uint64_t)requested_addr + compressed_class_space_size() < 4*G) {
wanghaomin@9268 3060 metaspace_rs = ReservedSpace(compressed_class_space_size(),
wanghaomin@9268 3061 _reserve_alignment,
wanghaomin@9268 3062 large_pages,
wanghaomin@9268 3063 requested_addr);
wanghaomin@9268 3064 }
wanghaomin@9268 3065
wanghaomin@9268 3066 if (! metaspace_rs.is_reserved()) {
wanghaomin@9268 3067 size_t increment = 4*G;
wanghaomin@9268 3068 for (char *a = (char *)align_ptr_up(requested_addr, increment);
wanghaomin@9268 3069 a < (char*)(1024*G);
wanghaomin@9268 3070 a += increment) {
wanghaomin@9268 3071
wanghaomin@9268 3072 #if INCLUDE_CDS
wanghaomin@9268 3073 if (UseSharedSpaces
wanghaomin@9268 3074 && ! can_use_cds_with_metaspace_addr(a, cds_base)) {
wanghaomin@9268 3075 // We failed to find an aligned base that will reach. Fall
wanghaomin@9268 3076 // back to using our requested addr.
wanghaomin@9268 3077 metaspace_rs = ReservedSpace(compressed_class_space_size(),
wanghaomin@9268 3078 _reserve_alignment,
wanghaomin@9268 3079 large_pages,
wanghaomin@9268 3080 requested_addr);
wanghaomin@9268 3081 break;
wanghaomin@9268 3082 }
wanghaomin@9268 3083 #endif
wanghaomin@9268 3084
wanghaomin@9268 3085 metaspace_rs = ReservedSpace(compressed_class_space_size(),
wanghaomin@9268 3086 _reserve_alignment,
wanghaomin@9268 3087 large_pages,
wanghaomin@9268 3088 a);
wanghaomin@9268 3089 if (metaspace_rs.is_reserved())
wanghaomin@9268 3090 break;
wanghaomin@9268 3091 }
wanghaomin@9268 3092 }
wanghaomin@9268 3093
wanghaomin@9268 3094 #endif // MIPS64
wanghaomin@9268 3095
aoqi@0 3096 if (!metaspace_rs.is_reserved()) {
iklam@7089 3097 #if INCLUDE_CDS
aoqi@0 3098 if (UseSharedSpaces) {
aoqi@0 3099 size_t increment = align_size_up(1*G, _reserve_alignment);
aoqi@0 3100
aoqi@0 3101 // Keep trying to allocate the metaspace, increasing the requested_addr
aoqi@0 3102 // by 1GB each time, until we reach an address that will no longer allow
aoqi@0 3103 // use of CDS with compressed klass pointers.
aoqi@0 3104 char *addr = requested_addr;
aoqi@0 3105 while (!metaspace_rs.is_reserved() && (addr + increment > addr) &&
aoqi@0 3106 can_use_cds_with_metaspace_addr(addr + increment, cds_base)) {
aoqi@0 3107 addr = addr + increment;
aoqi@0 3108 metaspace_rs = ReservedSpace(compressed_class_space_size(),
aoqi@0 3109 _reserve_alignment, large_pages, addr, 0);
aoqi@0 3110 }
aoqi@0 3111 }
iklam@7089 3112 #endif
aoqi@0 3113 // If no successful allocation then try to allocate the space anywhere. If
aoqi@0 3114 // that fails then OOM doom. At this point we cannot try allocating the
aoqi@0 3115 // metaspace as if UseCompressedClassPointers is off because too much
aoqi@0 3116 // initialization has happened that depends on UseCompressedClassPointers.
aoqi@0 3117 // So, UseCompressedClassPointers cannot be turned off at this point.
aoqi@0 3118 if (!metaspace_rs.is_reserved()) {
aoqi@0 3119 metaspace_rs = ReservedSpace(compressed_class_space_size(),
aoqi@0 3120 _reserve_alignment, large_pages);
aoqi@0 3121 if (!metaspace_rs.is_reserved()) {
aoqi@0 3122 vm_exit_during_initialization(err_msg("Could not allocate metaspace: %d bytes",
aoqi@0 3123 compressed_class_space_size()));
aoqi@0 3124 }
aoqi@0 3125 }
aoqi@0 3126 }
aoqi@0 3127
aoqi@0 3128 // If we got here then the metaspace got allocated.
aoqi@0 3129 MemTracker::record_virtual_memory_type((address)metaspace_rs.base(), mtClass);
aoqi@0 3130
iklam@7089 3131 #if INCLUDE_CDS
aoqi@0 3132 // Verify that we can use shared spaces. Otherwise, turn off CDS.
aoqi@0 3133 if (UseSharedSpaces && !can_use_cds_with_metaspace_addr(metaspace_rs.base(), cds_base)) {
aoqi@0 3134 FileMapInfo::stop_sharing_and_unmap(
aoqi@0 3135 "Could not allocate metaspace at a compatible address");
aoqi@0 3136 }
iklam@7089 3137 #endif
aoqi@0 3138 set_narrow_klass_base_and_shift((address)metaspace_rs.base(),
aoqi@0 3139 UseSharedSpaces ? (address)cds_base : 0);
aoqi@0 3140
aoqi@0 3141 initialize_class_space(metaspace_rs);
aoqi@0 3142
aoqi@0 3143 if (PrintCompressedOopsMode || (PrintMiscellaneous && Verbose)) {
aoqi@0 3144 gclog_or_tty->print_cr("Narrow klass base: " PTR_FORMAT ", Narrow klass shift: " SIZE_FORMAT,
aoqi@0 3145 Universe::narrow_klass_base(), Universe::narrow_klass_shift());
aoqi@0 3146 gclog_or_tty->print_cr("Compressed class space size: " SIZE_FORMAT " Address: " PTR_FORMAT " Req Addr: " PTR_FORMAT,
aoqi@0 3147 compressed_class_space_size(), metaspace_rs.base(), requested_addr);
aoqi@0 3148 }
aoqi@0 3149 }
aoqi@0 3150
aoqi@0 3151 // For UseCompressedClassPointers the class space is reserved above the top of
aoqi@0 3152 // the Java heap. The argument passed in is at the base of the compressed space.
aoqi@0 3153 void Metaspace::initialize_class_space(ReservedSpace rs) {
aoqi@0 3154 // The reserved space size may be bigger because of alignment, esp with UseLargePages
aoqi@0 3155 assert(rs.size() >= CompressedClassSpaceSize,
aoqi@0 3156 err_msg(SIZE_FORMAT " != " UINTX_FORMAT, rs.size(), CompressedClassSpaceSize));
aoqi@0 3157 assert(using_class_space(), "Must be using class space");
aoqi@0 3158 _class_space_list = new VirtualSpaceList(rs);
mchinnathamb@9058 3159 _chunk_manager_class = new ChunkManager(ClassSpecializedChunk, ClassSmallChunk, ClassMediumChunk);
aoqi@0 3160
aoqi@0 3161 if (!_class_space_list->initialization_succeeded()) {
aoqi@0 3162 vm_exit_during_initialization("Failed to setup compressed class space virtual space list.");
aoqi@0 3163 }
aoqi@0 3164 }
aoqi@0 3165
aoqi@0 3166 #endif
aoqi@0 3167
aoqi@0 3168 void Metaspace::ergo_initialize() {
aoqi@0 3169 if (DumpSharedSpaces) {
aoqi@0 3170 // Using large pages when dumping the shared archive is currently not implemented.
aoqi@0 3171 FLAG_SET_ERGO(bool, UseLargePagesInMetaspace, false);
aoqi@0 3172 }
aoqi@0 3173
aoqi@0 3174 size_t page_size = os::vm_page_size();
aoqi@0 3175 if (UseLargePages && UseLargePagesInMetaspace) {
aoqi@0 3176 page_size = os::large_page_size();
aoqi@0 3177 }
aoqi@0 3178
aoqi@0 3179 _commit_alignment = page_size;
aoqi@0 3180 _reserve_alignment = MAX2(page_size, (size_t)os::vm_allocation_granularity());
aoqi@0 3181
aoqi@0 3182 // Do not use FLAG_SET_ERGO to update MaxMetaspaceSize, since this will
aoqi@0 3183 // override if MaxMetaspaceSize was set on the command line or not.
aoqi@0 3184 // This information is needed later to conform to the specification of the
aoqi@0 3185 // java.lang.management.MemoryUsage API.
aoqi@0 3186 //
aoqi@0 3187 // Ideally, we would be able to set the default value of MaxMetaspaceSize in
aoqi@0 3188 // globals.hpp to the aligned value, but this is not possible, since the
aoqi@0 3189 // alignment depends on other flags being parsed.
aoqi@0 3190 MaxMetaspaceSize = align_size_down_bounded(MaxMetaspaceSize, _reserve_alignment);
aoqi@0 3191
aoqi@0 3192 if (MetaspaceSize > MaxMetaspaceSize) {
aoqi@0 3193 MetaspaceSize = MaxMetaspaceSize;
aoqi@0 3194 }
aoqi@0 3195
aoqi@0 3196 MetaspaceSize = align_size_down_bounded(MetaspaceSize, _commit_alignment);
aoqi@0 3197
aoqi@0 3198 assert(MetaspaceSize <= MaxMetaspaceSize, "MetaspaceSize should be limited by MaxMetaspaceSize");
aoqi@0 3199
aoqi@0 3200 if (MetaspaceSize < 256*K) {
aoqi@0 3201 vm_exit_during_initialization("Too small initial Metaspace size");
aoqi@0 3202 }
aoqi@0 3203
aoqi@0 3204 MinMetaspaceExpansion = align_size_down_bounded(MinMetaspaceExpansion, _commit_alignment);
aoqi@0 3205 MaxMetaspaceExpansion = align_size_down_bounded(MaxMetaspaceExpansion, _commit_alignment);
aoqi@0 3206
aoqi@0 3207 CompressedClassSpaceSize = align_size_down_bounded(CompressedClassSpaceSize, _reserve_alignment);
aoqi@0 3208 set_compressed_class_space_size(CompressedClassSpaceSize);
ysuenaga@9021 3209
ysuenaga@9021 3210 // Initial virtual space size will be calculated at global_initialize()
ysuenaga@9021 3211 uintx min_metaspace_sz =
ysuenaga@9021 3212 VIRTUALSPACEMULTIPLIER * InitialBootClassLoaderMetaspaceSize;
ysuenaga@9021 3213 if (UseCompressedClassPointers) {
ysuenaga@9021 3214 if ((min_metaspace_sz + CompressedClassSpaceSize) > MaxMetaspaceSize) {
ysuenaga@9021 3215 if (min_metaspace_sz >= MaxMetaspaceSize) {
ysuenaga@9021 3216 vm_exit_during_initialization("MaxMetaspaceSize is too small.");
ysuenaga@9021 3217 } else {
ysuenaga@9021 3218 FLAG_SET_ERGO(uintx, CompressedClassSpaceSize,
ysuenaga@9021 3219 MaxMetaspaceSize - min_metaspace_sz);
ysuenaga@9021 3220 }
ysuenaga@9021 3221 }
ysuenaga@9021 3222 } else if (min_metaspace_sz >= MaxMetaspaceSize) {
ysuenaga@9021 3223 FLAG_SET_ERGO(uintx, InitialBootClassLoaderMetaspaceSize,
ysuenaga@9021 3224 min_metaspace_sz);
ysuenaga@9021 3225 }
ysuenaga@9021 3226
aoqi@0 3227 }
aoqi@0 3228
aoqi@0 3229 void Metaspace::global_initialize() {
aoqi@0 3230 MetaspaceGC::initialize();
aoqi@0 3231
aoqi@0 3232 // Initialize the alignment for shared spaces.
minqi@7297 3233 int max_alignment = os::vm_allocation_granularity();
aoqi@0 3234 size_t cds_total = 0;
aoqi@0 3235
aoqi@0 3236 MetaspaceShared::set_max_alignment(max_alignment);
aoqi@0 3237
aoqi@0 3238 if (DumpSharedSpaces) {
iklam@7089 3239 #if INCLUDE_CDS
ccheung@7103 3240 MetaspaceShared::estimate_regions_size();
ccheung@7103 3241
aoqi@0 3242 SharedReadOnlySize = align_size_up(SharedReadOnlySize, max_alignment);
aoqi@0 3243 SharedReadWriteSize = align_size_up(SharedReadWriteSize, max_alignment);
aoqi@0 3244 SharedMiscDataSize = align_size_up(SharedMiscDataSize, max_alignment);
aoqi@0 3245 SharedMiscCodeSize = align_size_up(SharedMiscCodeSize, max_alignment);
aoqi@0 3246
ccheung@7300 3247 // the min_misc_code_size estimate is based on MetaspaceShared::generate_vtable_methods()
ccheung@7300 3248 uintx min_misc_code_size = align_size_up(
ccheung@7300 3249 (MetaspaceShared::num_virtuals * MetaspaceShared::vtbl_list_size) *
ccheung@7300 3250 (sizeof(void*) + MetaspaceShared::vtbl_method_size) + MetaspaceShared::vtbl_common_code_size,
ccheung@7300 3251 max_alignment);
ccheung@7300 3252
ccheung@7300 3253 if (SharedMiscCodeSize < min_misc_code_size) {
ccheung@7300 3254 report_out_of_shared_space(SharedMiscCode);
ccheung@7300 3255 }
ccheung@7300 3256
aoqi@0 3257 // Initialize with the sum of the shared space sizes. The read-only
aoqi@0 3258 // and read write metaspace chunks will be allocated out of this and the
aoqi@0 3259 // remainder is the misc code and data chunks.
aoqi@0 3260 cds_total = FileMapInfo::shared_spaces_size();
aoqi@0 3261 cds_total = align_size_up(cds_total, _reserve_alignment);
aoqi@0 3262 _space_list = new VirtualSpaceList(cds_total/wordSize);
aoqi@0 3263 _chunk_manager_metadata = new ChunkManager(SpecializedChunk, SmallChunk, MediumChunk);
aoqi@0 3264
aoqi@0 3265 if (!_space_list->initialization_succeeded()) {
aoqi@0 3266 vm_exit_during_initialization("Unable to dump shared archive.", NULL);
aoqi@0 3267 }
aoqi@0 3268
aoqi@0 3269 #ifdef _LP64
aoqi@0 3270 if (cds_total + compressed_class_space_size() > UnscaledClassSpaceMax) {
aoqi@0 3271 vm_exit_during_initialization("Unable to dump shared archive.",
aoqi@0 3272 err_msg("Size of archive (" SIZE_FORMAT ") + compressed class space ("
aoqi@0 3273 SIZE_FORMAT ") == total (" SIZE_FORMAT ") is larger than compressed "
aoqi@0 3274 "klass limit: " SIZE_FORMAT, cds_total, compressed_class_space_size(),
aoqi@0 3275 cds_total + compressed_class_space_size(), UnscaledClassSpaceMax));
aoqi@0 3276 }
aoqi@0 3277
aoqi@0 3278 // Set the compressed klass pointer base so that decoding of these pointers works
aoqi@0 3279 // properly when creating the shared archive.
aoqi@0 3280 assert(UseCompressedOops && UseCompressedClassPointers,
aoqi@0 3281 "UseCompressedOops and UseCompressedClassPointers must be set");
aoqi@0 3282 Universe::set_narrow_klass_base((address)_space_list->current_virtual_space()->bottom());
aoqi@0 3283 if (TraceMetavirtualspaceAllocation && Verbose) {
aoqi@0 3284 gclog_or_tty->print_cr("Setting_narrow_klass_base to Address: " PTR_FORMAT,
aoqi@0 3285 _space_list->current_virtual_space()->bottom());
aoqi@0 3286 }
aoqi@0 3287
aoqi@0 3288 Universe::set_narrow_klass_shift(0);
iklam@7089 3289 #endif // _LP64
iklam@7089 3290 #endif // INCLUDE_CDS
aoqi@0 3291 } else {
iklam@7089 3292 #if INCLUDE_CDS
aoqi@0 3293 // If using shared space, open the file that contains the shared space
aoqi@0 3294 // and map in the memory before initializing the rest of metaspace (so
aoqi@0 3295 // the addresses don't conflict)
aoqi@0 3296 address cds_address = NULL;
aoqi@0 3297 if (UseSharedSpaces) {
aoqi@0 3298 FileMapInfo* mapinfo = new FileMapInfo();
aoqi@0 3299
aoqi@0 3300 // Open the shared archive file, read and validate the header. If
aoqi@0 3301 // initialization fails, shared spaces [UseSharedSpaces] are
aoqi@0 3302 // disabled and the file is closed.
aoqi@0 3303 // Map in spaces now also
aoqi@0 3304 if (mapinfo->initialize() && MetaspaceShared::map_shared_spaces(mapinfo)) {
aoqi@0 3305 cds_total = FileMapInfo::shared_spaces_size();
aoqi@0 3306 cds_address = (address)mapinfo->region_base(0);
aoqi@0 3307 } else {
aoqi@0 3308 assert(!mapinfo->is_open() && !UseSharedSpaces,
aoqi@0 3309 "archive file not closed or shared spaces not disabled.");
aoqi@0 3310 }
aoqi@0 3311 }
iklam@7089 3312 #endif // INCLUDE_CDS
aoqi@0 3313 #ifdef _LP64
aoqi@0 3314 // If UseCompressedClassPointers is set then allocate the metaspace area
aoqi@0 3315 // above the heap and above the CDS area (if it exists).
aoqi@0 3316 if (using_class_space()) {
aoqi@0 3317 if (UseSharedSpaces) {
iklam@7089 3318 #if INCLUDE_CDS
aoqi@0 3319 char* cds_end = (char*)(cds_address + cds_total);
aoqi@0 3320 cds_end = (char *)align_ptr_up(cds_end, _reserve_alignment);
aoqi@0 3321 allocate_metaspace_compressed_klass_ptrs(cds_end, cds_address);
iklam@7089 3322 #endif
aoqi@0 3323 } else {
aoqi@0 3324 char* base = (char*)align_ptr_up(Universe::heap()->reserved_region().end(), _reserve_alignment);
aoqi@0 3325 allocate_metaspace_compressed_klass_ptrs(base, 0);
aoqi@0 3326 }
aoqi@0 3327 }
iklam@7089 3328 #endif // _LP64
aoqi@0 3329
aoqi@0 3330 // Initialize these before initializing the VirtualSpaceList
aoqi@0 3331 _first_chunk_word_size = InitialBootClassLoaderMetaspaceSize / BytesPerWord;
aoqi@0 3332 _first_chunk_word_size = align_word_size_up(_first_chunk_word_size);
aoqi@0 3333 // Make the first class chunk bigger than a medium chunk so it's not put
aoqi@0 3334 // on the medium chunk list. The next chunk will be small and progress
aoqi@0 3335 // from there. This size calculated by -version.
aoqi@0 3336 _first_class_chunk_word_size = MIN2((size_t)MediumChunk*6,
aoqi@0 3337 (CompressedClassSpaceSize/BytesPerWord)*2);
aoqi@0 3338 _first_class_chunk_word_size = align_word_size_up(_first_class_chunk_word_size);
aoqi@0 3339 // Arbitrarily set the initial virtual space to a multiple
aoqi@0 3340 // of the boot class loader size.
aoqi@0 3341 size_t word_size = VIRTUALSPACEMULTIPLIER * _first_chunk_word_size;
aoqi@0 3342 word_size = align_size_up(word_size, Metaspace::reserve_alignment_words());
aoqi@0 3343
aoqi@0 3344 // Initialize the list of virtual spaces.
aoqi@0 3345 _space_list = new VirtualSpaceList(word_size);
aoqi@0 3346 _chunk_manager_metadata = new ChunkManager(SpecializedChunk, SmallChunk, MediumChunk);
aoqi@0 3347
aoqi@0 3348 if (!_space_list->initialization_succeeded()) {
aoqi@0 3349 vm_exit_during_initialization("Unable to setup metadata virtual space list.", NULL);
aoqi@0 3350 }
aoqi@0 3351 }
aoqi@0 3352
aoqi@0 3353 _tracer = new MetaspaceTracer();
aoqi@0 3354 }
aoqi@0 3355
aoqi@0 3356 void Metaspace::post_initialize() {
aoqi@0 3357 MetaspaceGC::post_initialize();
aoqi@0 3358 }
aoqi@0 3359
mchinnathamb@9058 3360 void Metaspace::initialize_first_chunk(MetaspaceType type, MetadataType mdtype) {
mchinnathamb@9058 3361 Metachunk* chunk = get_initialization_chunk(type, mdtype);
mchinnathamb@9058 3362 if (chunk != NULL) {
mchinnathamb@9058 3363 // Add to this manager's list of chunks in use and current_chunk().
mchinnathamb@9058 3364 get_space_manager(mdtype)->add_chunk(chunk, true);
mchinnathamb@9058 3365 }
mchinnathamb@9058 3366 }
mchinnathamb@9058 3367
mchinnathamb@9058 3368 Metachunk* Metaspace::get_initialization_chunk(MetaspaceType type, MetadataType mdtype) {
mchinnathamb@9058 3369 size_t chunk_word_size = get_space_manager(mdtype)->get_initial_chunk_size(type);
mchinnathamb@9058 3370
aoqi@0 3371 // Get a chunk from the chunk freelist
aoqi@0 3372 Metachunk* chunk = get_chunk_manager(mdtype)->chunk_freelist_allocate(chunk_word_size);
mchinnathamb@9058 3373
mchinnathamb@9058 3374 if (chunk == NULL) {
mchinnathamb@9058 3375 chunk = get_space_list(mdtype)->get_new_chunk(chunk_word_size,
mchinnathamb@9058 3376 get_space_manager(mdtype)->medium_chunk_bunch());
aoqi@0 3377 }
aoqi@0 3378
mchinnathamb@9058 3379 // For dumping shared archive, report error if allocation has failed.
mchinnathamb@9058 3380 if (DumpSharedSpaces && chunk == NULL) {
mchinnathamb@9058 3381 report_insufficient_metaspace(MetaspaceAux::committed_bytes() + chunk_word_size * BytesPerWord);
mchinnathamb@9058 3382 }
mchinnathamb@9058 3383
mchinnathamb@9058 3384 return chunk;
aoqi@0 3385 }
aoqi@0 3386
mchinnathamb@9058 3387 void Metaspace::verify_global_initialization() {
mchinnathamb@9058 3388 assert(space_list() != NULL, "Metadata VirtualSpaceList has not been initialized");
mchinnathamb@9058 3389 assert(chunk_manager_metadata() != NULL, "Metadata ChunkManager has not been initialized");
mchinnathamb@9058 3390
mchinnathamb@9058 3391 if (using_class_space()) {
mchinnathamb@9058 3392 assert(class_space_list() != NULL, "Class VirtualSpaceList has not been initialized");
mchinnathamb@9058 3393 assert(chunk_manager_class() != NULL, "Class ChunkManager has not been initialized");
mchinnathamb@9058 3394 }
mchinnathamb@9058 3395 }
mchinnathamb@9058 3396
aoqi@0 3397 void Metaspace::initialize(Mutex* lock, MetaspaceType type) {
mchinnathamb@9058 3398 verify_global_initialization();
mchinnathamb@9058 3399
mchinnathamb@9058 3400 // Allocate SpaceManager for metadata objects.
aoqi@0 3401 _vsm = new SpaceManager(NonClassType, lock);
aoqi@0 3402
aoqi@0 3403 if (using_class_space()) {
aoqi@0 3404 // Allocate SpaceManager for classes.
aoqi@0 3405 _class_vsm = new SpaceManager(ClassType, lock);
aoqi@0 3406 }
aoqi@0 3407
aoqi@0 3408 MutexLockerEx cl(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag);
aoqi@0 3409
aoqi@0 3410 // Allocate chunk for metadata objects
mchinnathamb@9058 3411 initialize_first_chunk(type, NonClassType);
aoqi@0 3412
aoqi@0 3413 // Allocate chunk for class metadata objects
aoqi@0 3414 if (using_class_space()) {
mchinnathamb@9058 3415 initialize_first_chunk(type, ClassType);
aoqi@0 3416 }
aoqi@0 3417
aoqi@0 3418 _alloc_record_head = NULL;
aoqi@0 3419 _alloc_record_tail = NULL;
aoqi@0 3420 }
aoqi@0 3421
aoqi@0 3422 size_t Metaspace::align_word_size_up(size_t word_size) {
aoqi@0 3423 size_t byte_size = word_size * wordSize;
aoqi@0 3424 return ReservedSpace::allocation_align_size_up(byte_size) / wordSize;
aoqi@0 3425 }
aoqi@0 3426
aoqi@0 3427 MetaWord* Metaspace::allocate(size_t word_size, MetadataType mdtype) {
aoqi@0 3428 // DumpSharedSpaces doesn't use class metadata area (yet)
aoqi@0 3429 // Also, don't use class_vsm() unless UseCompressedClassPointers is true.
aoqi@0 3430 if (is_class_space_allocation(mdtype)) {
aoqi@0 3431 return class_vsm()->allocate(word_size);
aoqi@0 3432 } else {
aoqi@0 3433 return vsm()->allocate(word_size);
aoqi@0 3434 }
aoqi@0 3435 }
aoqi@0 3436
aoqi@0 3437 MetaWord* Metaspace::expand_and_allocate(size_t word_size, MetadataType mdtype) {
aoqi@0 3438 size_t delta_bytes = MetaspaceGC::delta_capacity_until_GC(word_size * BytesPerWord);
aoqi@0 3439 assert(delta_bytes > 0, "Must be");
aoqi@0 3440
ehelin@7254 3441 size_t before = 0;
ehelin@7254 3442 size_t after = 0;
ehelin@7254 3443 MetaWord* res;
ehelin@7254 3444 bool incremented;
ehelin@7254 3445
ehelin@7254 3446 // Each thread increments the HWM at most once. Even if the thread fails to increment
ehelin@7254 3447 // the HWM, an allocation is still attempted. This is because another thread must then
ehelin@7254 3448 // have incremented the HWM and therefore the allocation might still succeed.
ehelin@7254 3449 do {
ehelin@7254 3450 incremented = MetaspaceGC::inc_capacity_until_GC(delta_bytes, &after, &before);
ehelin@7254 3451 res = allocate(word_size, mdtype);
ehelin@7254 3452 } while (!incremented && res == NULL);
ehelin@7254 3453
ehelin@7254 3454 if (incremented) {
ehelin@7254 3455 tracer()->report_gc_threshold(before, after,
ehelin@7254 3456 MetaspaceGCThresholdUpdater::ExpandAndAllocate);
ehelin@7254 3457 if (PrintGCDetails && Verbose) {
ehelin@7254 3458 gclog_or_tty->print_cr("Increase capacity to GC from " SIZE_FORMAT
ehelin@7254 3459 " to " SIZE_FORMAT, before, after);
ehelin@7254 3460 }
aoqi@0 3461 }
aoqi@0 3462
ehelin@7254 3463 return res;
aoqi@0 3464 }
aoqi@0 3465
aoqi@0 3466 // Space allocated in the Metaspace. This may
aoqi@0 3467 // be across several metadata virtual spaces.
aoqi@0 3468 char* Metaspace::bottom() const {
aoqi@0 3469 assert(DumpSharedSpaces, "only useful and valid for dumping shared spaces");
aoqi@0 3470 return (char*)vsm()->current_chunk()->bottom();
aoqi@0 3471 }
aoqi@0 3472
aoqi@0 3473 size_t Metaspace::used_words_slow(MetadataType mdtype) const {
aoqi@0 3474 if (mdtype == ClassType) {
aoqi@0 3475 return using_class_space() ? class_vsm()->sum_used_in_chunks_in_use() : 0;
aoqi@0 3476 } else {
aoqi@0 3477 return vsm()->sum_used_in_chunks_in_use(); // includes overhead!
aoqi@0 3478 }
aoqi@0 3479 }
aoqi@0 3480
aoqi@0 3481 size_t Metaspace::free_words_slow(MetadataType mdtype) const {
aoqi@0 3482 if (mdtype == ClassType) {
aoqi@0 3483 return using_class_space() ? class_vsm()->sum_free_in_chunks_in_use() : 0;
aoqi@0 3484 } else {
aoqi@0 3485 return vsm()->sum_free_in_chunks_in_use();
aoqi@0 3486 }
aoqi@0 3487 }
aoqi@0 3488
aoqi@0 3489 // Space capacity in the Metaspace. It includes
aoqi@0 3490 // space in the list of chunks from which allocations
aoqi@0 3491 // have been made. Don't include space in the global freelist and
aoqi@0 3492 // in the space available in the dictionary which
aoqi@0 3493 // is already counted in some chunk.
aoqi@0 3494 size_t Metaspace::capacity_words_slow(MetadataType mdtype) const {
aoqi@0 3495 if (mdtype == ClassType) {
aoqi@0 3496 return using_class_space() ? class_vsm()->sum_capacity_in_chunks_in_use() : 0;
aoqi@0 3497 } else {
aoqi@0 3498 return vsm()->sum_capacity_in_chunks_in_use();
aoqi@0 3499 }
aoqi@0 3500 }
aoqi@0 3501
aoqi@0 3502 size_t Metaspace::used_bytes_slow(MetadataType mdtype) const {
aoqi@0 3503 return used_words_slow(mdtype) * BytesPerWord;
aoqi@0 3504 }
aoqi@0 3505
aoqi@0 3506 size_t Metaspace::capacity_bytes_slow(MetadataType mdtype) const {
aoqi@0 3507 return capacity_words_slow(mdtype) * BytesPerWord;
aoqi@0 3508 }
aoqi@0 3509
dbuck@9063 3510 size_t Metaspace::allocated_blocks_bytes() const {
dbuck@9063 3511 return vsm()->allocated_blocks_bytes() +
dbuck@9063 3512 (using_class_space() ? class_vsm()->allocated_blocks_bytes() : 0);
dbuck@9063 3513 }
dbuck@9063 3514
dbuck@9063 3515 size_t Metaspace::allocated_chunks_bytes() const {
dbuck@9063 3516 return vsm()->allocated_chunks_bytes() +
dbuck@9063 3517 (using_class_space() ? class_vsm()->allocated_chunks_bytes() : 0);
dbuck@9063 3518 }
dbuck@9063 3519
aoqi@0 3520 void Metaspace::deallocate(MetaWord* ptr, size_t word_size, bool is_class) {
aoqi@0 3521 if (SafepointSynchronize::is_at_safepoint()) {
iklam@7089 3522 if (DumpSharedSpaces && PrintSharedSpaces) {
iklam@7089 3523 record_deallocation(ptr, vsm()->get_raw_word_size(word_size));
iklam@7089 3524 }
iklam@7089 3525
aoqi@0 3526 assert(Thread::current()->is_VM_thread(), "should be the VM thread");
aoqi@0 3527 // Don't take Heap_lock
aoqi@0 3528 MutexLockerEx ml(vsm()->lock(), Mutex::_no_safepoint_check_flag);
aoqi@0 3529 if (word_size < TreeChunk<Metablock, FreeList<Metablock> >::min_size()) {
aoqi@0 3530 // Dark matter. Too small for dictionary.
aoqi@0 3531 #ifdef ASSERT
aoqi@0 3532 Copy::fill_to_words((HeapWord*)ptr, word_size, 0xf5f5f5f5);
aoqi@0 3533 #endif
aoqi@0 3534 return;
aoqi@0 3535 }
aoqi@0 3536 if (is_class && using_class_space()) {
aoqi@0 3537 class_vsm()->deallocate(ptr, word_size);
aoqi@0 3538 } else {
aoqi@0 3539 vsm()->deallocate(ptr, word_size);
aoqi@0 3540 }
aoqi@0 3541 } else {
aoqi@0 3542 MutexLockerEx ml(vsm()->lock(), Mutex::_no_safepoint_check_flag);
aoqi@0 3543
aoqi@0 3544 if (word_size < TreeChunk<Metablock, FreeList<Metablock> >::min_size()) {
aoqi@0 3545 // Dark matter. Too small for dictionary.
aoqi@0 3546 #ifdef ASSERT
aoqi@0 3547 Copy::fill_to_words((HeapWord*)ptr, word_size, 0xf5f5f5f5);
aoqi@0 3548 #endif
aoqi@0 3549 return;
aoqi@0 3550 }
aoqi@0 3551 if (is_class && using_class_space()) {
aoqi@0 3552 class_vsm()->deallocate(ptr, word_size);
aoqi@0 3553 } else {
aoqi@0 3554 vsm()->deallocate(ptr, word_size);
aoqi@0 3555 }
aoqi@0 3556 }
aoqi@0 3557 }
aoqi@0 3558
aoqi@0 3559
aoqi@0 3560 MetaWord* Metaspace::allocate(ClassLoaderData* loader_data, size_t word_size,
aoqi@0 3561 bool read_only, MetaspaceObj::Type type, TRAPS) {
aoqi@0 3562 if (HAS_PENDING_EXCEPTION) {
aoqi@0 3563 assert(false, "Should not allocate with exception pending");
aoqi@0 3564 return NULL; // caller does a CHECK_NULL too
aoqi@0 3565 }
aoqi@0 3566
aoqi@0 3567 assert(loader_data != NULL, "Should never pass around a NULL loader_data. "
aoqi@0 3568 "ClassLoaderData::the_null_class_loader_data() should have been used.");
aoqi@0 3569
aoqi@0 3570 // Allocate in metaspaces without taking out a lock, because it deadlocks
aoqi@0 3571 // with the SymbolTable_lock. Dumping is single threaded for now. We'll have
aoqi@0 3572 // to revisit this for application class data sharing.
aoqi@0 3573 if (DumpSharedSpaces) {
aoqi@0 3574 assert(type > MetaspaceObj::UnknownType && type < MetaspaceObj::_number_of_types, "sanity");
aoqi@0 3575 Metaspace* space = read_only ? loader_data->ro_metaspace() : loader_data->rw_metaspace();
aoqi@0 3576 MetaWord* result = space->allocate(word_size, NonClassType);
aoqi@0 3577 if (result == NULL) {
aoqi@0 3578 report_out_of_shared_space(read_only ? SharedReadOnly : SharedReadWrite);
aoqi@0 3579 }
iklam@7089 3580 if (PrintSharedSpaces) {
iklam@7089 3581 space->record_allocation(result, type, space->vsm()->get_raw_word_size(word_size));
iklam@7089 3582 }
aoqi@0 3583
aoqi@0 3584 // Zero initialize.
aoqi@0 3585 Copy::fill_to_aligned_words((HeapWord*)result, word_size, 0);
aoqi@0 3586
aoqi@0 3587 return result;
aoqi@0 3588 }
aoqi@0 3589
aoqi@0 3590 MetadataType mdtype = (type == MetaspaceObj::ClassType) ? ClassType : NonClassType;
aoqi@0 3591
aoqi@0 3592 // Try to allocate metadata.
aoqi@0 3593 MetaWord* result = loader_data->metaspace_non_null()->allocate(word_size, mdtype);
aoqi@0 3594
aoqi@0 3595 if (result == NULL) {
aoqi@0 3596 tracer()->report_metaspace_allocation_failure(loader_data, word_size, type, mdtype);
aoqi@0 3597
aoqi@0 3598 // Allocation failed.
aoqi@0 3599 if (is_init_completed()) {
aoqi@0 3600 // Only start a GC if the bootstrapping has completed.
aoqi@0 3601
aoqi@0 3602 // Try to clean out some memory and retry.
aoqi@0 3603 result = Universe::heap()->collector_policy()->satisfy_failed_metadata_allocation(
aoqi@0 3604 loader_data, word_size, mdtype);
aoqi@0 3605 }
aoqi@0 3606 }
aoqi@0 3607
aoqi@0 3608 if (result == NULL) {
aoqi@0 3609 report_metadata_oome(loader_data, word_size, type, mdtype, CHECK_NULL);
aoqi@0 3610 }
aoqi@0 3611
aoqi@0 3612 // Zero initialize.
aoqi@0 3613 Copy::fill_to_aligned_words((HeapWord*)result, word_size, 0);
aoqi@0 3614
aoqi@0 3615 return result;
aoqi@0 3616 }
aoqi@0 3617
aoqi@0 3618 size_t Metaspace::class_chunk_size(size_t word_size) {
aoqi@0 3619 assert(using_class_space(), "Has to use class space");
aoqi@0 3620 return class_vsm()->calc_chunk_size(word_size);
aoqi@0 3621 }
aoqi@0 3622
aoqi@0 3623 void Metaspace::report_metadata_oome(ClassLoaderData* loader_data, size_t word_size, MetaspaceObj::Type type, MetadataType mdtype, TRAPS) {
aoqi@0 3624 tracer()->report_metadata_oom(loader_data, word_size, type, mdtype);
aoqi@0 3625
aoqi@0 3626 // If result is still null, we are out of memory.
aoqi@0 3627 if (Verbose && TraceMetadataChunkAllocation) {
aoqi@0 3628 gclog_or_tty->print_cr("Metaspace allocation failed for size "
aoqi@0 3629 SIZE_FORMAT, word_size);
aoqi@0 3630 if (loader_data->metaspace_or_null() != NULL) {
aoqi@0 3631 loader_data->dump(gclog_or_tty);
aoqi@0 3632 }
aoqi@0 3633 MetaspaceAux::dump(gclog_or_tty);
aoqi@0 3634 }
aoqi@0 3635
aoqi@0 3636 bool out_of_compressed_class_space = false;
aoqi@0 3637 if (is_class_space_allocation(mdtype)) {
aoqi@0 3638 Metaspace* metaspace = loader_data->metaspace_non_null();
aoqi@0 3639 out_of_compressed_class_space =
aoqi@0 3640 MetaspaceAux::committed_bytes(Metaspace::ClassType) +
aoqi@0 3641 (metaspace->class_chunk_size(word_size) * BytesPerWord) >
aoqi@0 3642 CompressedClassSpaceSize;
aoqi@0 3643 }
aoqi@0 3644
aoqi@0 3645 // -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError support
aoqi@0 3646 const char* space_string = out_of_compressed_class_space ?
aoqi@0 3647 "Compressed class space" : "Metaspace";
aoqi@0 3648
aoqi@0 3649 report_java_out_of_memory(space_string);
aoqi@0 3650
aoqi@0 3651 if (JvmtiExport::should_post_resource_exhausted()) {
aoqi@0 3652 JvmtiExport::post_resource_exhausted(
aoqi@0 3653 JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR,
aoqi@0 3654 space_string);
aoqi@0 3655 }
aoqi@0 3656
aoqi@0 3657 if (!is_init_completed()) {
aoqi@0 3658 vm_exit_during_initialization("OutOfMemoryError", space_string);
aoqi@0 3659 }
aoqi@0 3660
aoqi@0 3661 if (out_of_compressed_class_space) {
aoqi@0 3662 THROW_OOP(Universe::out_of_memory_error_class_metaspace());
aoqi@0 3663 } else {
aoqi@0 3664 THROW_OOP(Universe::out_of_memory_error_metaspace());
aoqi@0 3665 }
aoqi@0 3666 }
aoqi@0 3667
aoqi@0 3668 const char* Metaspace::metadata_type_name(Metaspace::MetadataType mdtype) {
aoqi@0 3669 switch (mdtype) {
aoqi@0 3670 case Metaspace::ClassType: return "Class";
aoqi@0 3671 case Metaspace::NonClassType: return "Metadata";
aoqi@0 3672 default:
aoqi@0 3673 assert(false, err_msg("Got bad mdtype: %d", (int) mdtype));
aoqi@0 3674 return NULL;
aoqi@0 3675 }
aoqi@0 3676 }
aoqi@0 3677
aoqi@0 3678 void Metaspace::record_allocation(void* ptr, MetaspaceObj::Type type, size_t word_size) {
aoqi@0 3679 assert(DumpSharedSpaces, "sanity");
aoqi@0 3680
iklam@7089 3681 int byte_size = (int)word_size * HeapWordSize;
iklam@7089 3682 AllocRecord *rec = new AllocRecord((address)ptr, type, byte_size);
iklam@7089 3683
aoqi@0 3684 if (_alloc_record_head == NULL) {
aoqi@0 3685 _alloc_record_head = _alloc_record_tail = rec;
iklam@7089 3686 } else if (_alloc_record_tail->_ptr + _alloc_record_tail->_byte_size == (address)ptr) {
aoqi@0 3687 _alloc_record_tail->_next = rec;
aoqi@0 3688 _alloc_record_tail = rec;
iklam@7089 3689 } else {
iklam@7089 3690 // slow linear search, but this doesn't happen that often, and only when dumping
iklam@7089 3691 for (AllocRecord *old = _alloc_record_head; old; old = old->_next) {
iklam@7089 3692 if (old->_ptr == ptr) {
iklam@7089 3693 assert(old->_type == MetaspaceObj::DeallocatedType, "sanity");
iklam@7089 3694 int remain_bytes = old->_byte_size - byte_size;
iklam@7089 3695 assert(remain_bytes >= 0, "sanity");
iklam@7089 3696 old->_type = type;
iklam@7089 3697
iklam@7089 3698 if (remain_bytes == 0) {
iklam@7089 3699 delete(rec);
iklam@7089 3700 } else {
iklam@7089 3701 address remain_ptr = address(ptr) + byte_size;
iklam@7089 3702 rec->_ptr = remain_ptr;
iklam@7089 3703 rec->_byte_size = remain_bytes;
iklam@7089 3704 rec->_type = MetaspaceObj::DeallocatedType;
iklam@7089 3705 rec->_next = old->_next;
iklam@7089 3706 old->_byte_size = byte_size;
iklam@7089 3707 old->_next = rec;
iklam@7089 3708 }
iklam@7089 3709 return;
iklam@7089 3710 }
iklam@7089 3711 }
iklam@7089 3712 assert(0, "reallocating a freed pointer that was not recorded");
aoqi@0 3713 }
aoqi@0 3714 }
aoqi@0 3715
iklam@7089 3716 void Metaspace::record_deallocation(void* ptr, size_t word_size) {
iklam@7089 3717 assert(DumpSharedSpaces, "sanity");
iklam@7089 3718
iklam@7089 3719 for (AllocRecord *rec = _alloc_record_head; rec; rec = rec->_next) {
iklam@7089 3720 if (rec->_ptr == ptr) {
iklam@7089 3721 assert(rec->_byte_size == (int)word_size * HeapWordSize, "sanity");
iklam@7089 3722 rec->_type = MetaspaceObj::DeallocatedType;
iklam@7089 3723 return;
iklam@7089 3724 }
iklam@7089 3725 }
iklam@7089 3726
iklam@7089 3727 assert(0, "deallocating a pointer that was not recorded");
iklam@7089 3728 }
iklam@7089 3729
aoqi@0 3730 void Metaspace::iterate(Metaspace::AllocRecordClosure *closure) {
aoqi@0 3731 assert(DumpSharedSpaces, "unimplemented for !DumpSharedSpaces");
aoqi@0 3732
aoqi@0 3733 address last_addr = (address)bottom();
aoqi@0 3734
aoqi@0 3735 for (AllocRecord *rec = _alloc_record_head; rec; rec = rec->_next) {
aoqi@0 3736 address ptr = rec->_ptr;
aoqi@0 3737 if (last_addr < ptr) {
aoqi@0 3738 closure->doit(last_addr, MetaspaceObj::UnknownType, ptr - last_addr);
aoqi@0 3739 }
aoqi@0 3740 closure->doit(ptr, rec->_type, rec->_byte_size);
aoqi@0 3741 last_addr = ptr + rec->_byte_size;
aoqi@0 3742 }
aoqi@0 3743
aoqi@0 3744 address top = ((address)bottom()) + used_bytes_slow(Metaspace::NonClassType);
aoqi@0 3745 if (last_addr < top) {
aoqi@0 3746 closure->doit(last_addr, MetaspaceObj::UnknownType, top - last_addr);
aoqi@0 3747 }
aoqi@0 3748 }
aoqi@0 3749
aoqi@0 3750 void Metaspace::purge(MetadataType mdtype) {
aoqi@0 3751 get_space_list(mdtype)->purge(get_chunk_manager(mdtype));
aoqi@0 3752 }
aoqi@0 3753
aoqi@0 3754 void Metaspace::purge() {
aoqi@0 3755 MutexLockerEx cl(SpaceManager::expand_lock(),
aoqi@0 3756 Mutex::_no_safepoint_check_flag);
aoqi@0 3757 purge(NonClassType);
aoqi@0 3758 if (using_class_space()) {
aoqi@0 3759 purge(ClassType);
aoqi@0 3760 }
aoqi@0 3761 }
aoqi@0 3762
aoqi@0 3763 void Metaspace::print_on(outputStream* out) const {
aoqi@0 3764 // Print both class virtual space counts and metaspace.
aoqi@0 3765 if (Verbose) {
aoqi@0 3766 vsm()->print_on(out);
aoqi@0 3767 if (using_class_space()) {
aoqi@0 3768 class_vsm()->print_on(out);
aoqi@0 3769 }
aoqi@0 3770 }
aoqi@0 3771 }
aoqi@0 3772
aoqi@0 3773 bool Metaspace::contains(const void* ptr) {
aoqi@0 3774 if (UseSharedSpaces && MetaspaceShared::is_in_shared_space(ptr)) {
aoqi@0 3775 return true;
aoqi@0 3776 }
aoqi@0 3777
aoqi@0 3778 if (using_class_space() && get_space_list(ClassType)->contains(ptr)) {
aoqi@0 3779 return true;
aoqi@0 3780 }
aoqi@0 3781
aoqi@0 3782 return get_space_list(NonClassType)->contains(ptr);
aoqi@0 3783 }
aoqi@0 3784
aoqi@0 3785 void Metaspace::verify() {
aoqi@0 3786 vsm()->verify();
aoqi@0 3787 if (using_class_space()) {
aoqi@0 3788 class_vsm()->verify();
aoqi@0 3789 }
aoqi@0 3790 }
aoqi@0 3791
aoqi@0 3792 void Metaspace::dump(outputStream* const out) const {
aoqi@0 3793 out->print_cr("\nVirtual space manager: " INTPTR_FORMAT, vsm());
aoqi@0 3794 vsm()->dump(out);
aoqi@0 3795 if (using_class_space()) {
aoqi@0 3796 out->print_cr("\nClass space manager: " INTPTR_FORMAT, class_vsm());
aoqi@0 3797 class_vsm()->dump(out);
aoqi@0 3798 }
aoqi@0 3799 }
aoqi@0 3800
aoqi@0 3801 /////////////// Unit tests ///////////////
aoqi@0 3802
aoqi@0 3803 #ifndef PRODUCT
aoqi@0 3804
aoqi@0 3805 class TestMetaspaceAuxTest : AllStatic {
aoqi@0 3806 public:
aoqi@0 3807 static void test_reserved() {
aoqi@0 3808 size_t reserved = MetaspaceAux::reserved_bytes();
aoqi@0 3809
aoqi@0 3810 assert(reserved > 0, "assert");
aoqi@0 3811
aoqi@0 3812 size_t committed = MetaspaceAux::committed_bytes();
aoqi@0 3813 assert(committed <= reserved, "assert");
aoqi@0 3814
aoqi@0 3815 size_t reserved_metadata = MetaspaceAux::reserved_bytes(Metaspace::NonClassType);
aoqi@0 3816 assert(reserved_metadata > 0, "assert");
aoqi@0 3817 assert(reserved_metadata <= reserved, "assert");
aoqi@0 3818
aoqi@0 3819 if (UseCompressedClassPointers) {
aoqi@0 3820 size_t reserved_class = MetaspaceAux::reserved_bytes(Metaspace::ClassType);
aoqi@0 3821 assert(reserved_class > 0, "assert");
aoqi@0 3822 assert(reserved_class < reserved, "assert");
aoqi@0 3823 }
aoqi@0 3824 }
aoqi@0 3825
aoqi@0 3826 static void test_committed() {
aoqi@0 3827 size_t committed = MetaspaceAux::committed_bytes();
aoqi@0 3828
aoqi@0 3829 assert(committed > 0, "assert");
aoqi@0 3830
aoqi@0 3831 size_t reserved = MetaspaceAux::reserved_bytes();
aoqi@0 3832 assert(committed <= reserved, "assert");
aoqi@0 3833
aoqi@0 3834 size_t committed_metadata = MetaspaceAux::committed_bytes(Metaspace::NonClassType);
aoqi@0 3835 assert(committed_metadata > 0, "assert");
aoqi@0 3836 assert(committed_metadata <= committed, "assert");
aoqi@0 3837
aoqi@0 3838 if (UseCompressedClassPointers) {
aoqi@0 3839 size_t committed_class = MetaspaceAux::committed_bytes(Metaspace::ClassType);
aoqi@0 3840 assert(committed_class > 0, "assert");
aoqi@0 3841 assert(committed_class < committed, "assert");
aoqi@0 3842 }
aoqi@0 3843 }
aoqi@0 3844
aoqi@0 3845 static void test_virtual_space_list_large_chunk() {
aoqi@0 3846 VirtualSpaceList* vs_list = new VirtualSpaceList(os::vm_allocation_granularity());
aoqi@0 3847 MutexLockerEx cl(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag);
aoqi@0 3848 // A size larger than VirtualSpaceSize (256k) and add one page to make it _not_ be
aoqi@0 3849 // vm_allocation_granularity aligned on Windows.
aoqi@0 3850 size_t large_size = (size_t)(2*256*K + (os::vm_page_size()/BytesPerWord));
aoqi@0 3851 large_size += (os::vm_page_size()/BytesPerWord);
mchinnathamb@9058 3852 vs_list->get_new_chunk(large_size, 0);
aoqi@0 3853 }
aoqi@0 3854
aoqi@0 3855 static void test() {
aoqi@0 3856 test_reserved();
aoqi@0 3857 test_committed();
aoqi@0 3858 test_virtual_space_list_large_chunk();
aoqi@0 3859 }
aoqi@0 3860 };
aoqi@0 3861
aoqi@0 3862 void TestMetaspaceAux_test() {
aoqi@0 3863 TestMetaspaceAuxTest::test();
aoqi@0 3864 }
aoqi@0 3865
aoqi@0 3866 class TestVirtualSpaceNodeTest {
aoqi@0 3867 static void chunk_up(size_t words_left, size_t& num_medium_chunks,
aoqi@0 3868 size_t& num_small_chunks,
aoqi@0 3869 size_t& num_specialized_chunks) {
aoqi@0 3870 num_medium_chunks = words_left / MediumChunk;
aoqi@0 3871 words_left = words_left % MediumChunk;
aoqi@0 3872
aoqi@0 3873 num_small_chunks = words_left / SmallChunk;
aoqi@0 3874 words_left = words_left % SmallChunk;
aoqi@0 3875 // how many specialized chunks can we get?
aoqi@0 3876 num_specialized_chunks = words_left / SpecializedChunk;
aoqi@0 3877 assert(words_left % SpecializedChunk == 0, "should be nothing left");
aoqi@0 3878 }
aoqi@0 3879
aoqi@0 3880 public:
aoqi@0 3881 static void test() {
aoqi@0 3882 MutexLockerEx ml(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag);
aoqi@0 3883 const size_t vsn_test_size_words = MediumChunk * 4;
aoqi@0 3884 const size_t vsn_test_size_bytes = vsn_test_size_words * BytesPerWord;
aoqi@0 3885
aoqi@0 3886 // The chunk sizes must be multiples of eachother, or this will fail
aoqi@0 3887 STATIC_ASSERT(MediumChunk % SmallChunk == 0);
aoqi@0 3888 STATIC_ASSERT(SmallChunk % SpecializedChunk == 0);
aoqi@0 3889
aoqi@0 3890 { // No committed memory in VSN
aoqi@0 3891 ChunkManager cm(SpecializedChunk, SmallChunk, MediumChunk);
aoqi@0 3892 VirtualSpaceNode vsn(vsn_test_size_bytes);
aoqi@0 3893 vsn.initialize();
aoqi@0 3894 vsn.retire(&cm);
aoqi@0 3895 assert(cm.sum_free_chunks_count() == 0, "did not commit any memory in the VSN");
aoqi@0 3896 }
aoqi@0 3897
aoqi@0 3898 { // All of VSN is committed, half is used by chunks
aoqi@0 3899 ChunkManager cm(SpecializedChunk, SmallChunk, MediumChunk);
aoqi@0 3900 VirtualSpaceNode vsn(vsn_test_size_bytes);
aoqi@0 3901 vsn.initialize();
aoqi@0 3902 vsn.expand_by(vsn_test_size_words, vsn_test_size_words);
aoqi@0 3903 vsn.get_chunk_vs(MediumChunk);
aoqi@0 3904 vsn.get_chunk_vs(MediumChunk);
aoqi@0 3905 vsn.retire(&cm);
aoqi@0 3906 assert(cm.sum_free_chunks_count() == 2, "should have been memory left for 2 medium chunks");
aoqi@0 3907 assert(cm.sum_free_chunks() == 2*MediumChunk, "sizes should add up");
aoqi@0 3908 }
aoqi@0 3909
aoqi@0 3910 { // 4 pages of VSN is committed, some is used by chunks
aoqi@0 3911 ChunkManager cm(SpecializedChunk, SmallChunk, MediumChunk);
aoqi@0 3912 VirtualSpaceNode vsn(vsn_test_size_bytes);
aoqi@0 3913 const size_t page_chunks = 4 * (size_t)os::vm_page_size() / BytesPerWord;
aoqi@0 3914 assert(page_chunks < MediumChunk, "Test expects medium chunks to be at least 4*page_size");
aoqi@0 3915 vsn.initialize();
aoqi@0 3916 vsn.expand_by(page_chunks, page_chunks);
aoqi@0 3917 vsn.get_chunk_vs(SmallChunk);
aoqi@0 3918 vsn.get_chunk_vs(SpecializedChunk);
aoqi@0 3919 vsn.retire(&cm);
aoqi@0 3920
aoqi@0 3921 // committed - used = words left to retire
aoqi@0 3922 const size_t words_left = page_chunks - SmallChunk - SpecializedChunk;
aoqi@0 3923
aoqi@0 3924 size_t num_medium_chunks, num_small_chunks, num_spec_chunks;
aoqi@0 3925 chunk_up(words_left, num_medium_chunks, num_small_chunks, num_spec_chunks);
aoqi@0 3926
aoqi@0 3927 assert(num_medium_chunks == 0, "should not get any medium chunks");
aoqi@0 3928 assert(cm.sum_free_chunks_count() == (num_small_chunks + num_spec_chunks), "should be space for 3 chunks");
aoqi@0 3929 assert(cm.sum_free_chunks() == words_left, "sizes should add up");
aoqi@0 3930 }
aoqi@0 3931
aoqi@0 3932 { // Half of VSN is committed, a humongous chunk is used
aoqi@0 3933 ChunkManager cm(SpecializedChunk, SmallChunk, MediumChunk);
aoqi@0 3934 VirtualSpaceNode vsn(vsn_test_size_bytes);
aoqi@0 3935 vsn.initialize();
aoqi@0 3936 vsn.expand_by(MediumChunk * 2, MediumChunk * 2);
aoqi@0 3937 vsn.get_chunk_vs(MediumChunk + SpecializedChunk); // Humongous chunks will be aligned up to MediumChunk + SpecializedChunk
aoqi@0 3938 vsn.retire(&cm);
aoqi@0 3939
aoqi@0 3940 const size_t words_left = MediumChunk * 2 - (MediumChunk + SpecializedChunk);
aoqi@0 3941 size_t num_medium_chunks, num_small_chunks, num_spec_chunks;
aoqi@0 3942 chunk_up(words_left, num_medium_chunks, num_small_chunks, num_spec_chunks);
aoqi@0 3943
aoqi@0 3944 assert(num_medium_chunks == 0, "should not get any medium chunks");
aoqi@0 3945 assert(cm.sum_free_chunks_count() == (num_small_chunks + num_spec_chunks), "should be space for 3 chunks");
aoqi@0 3946 assert(cm.sum_free_chunks() == words_left, "sizes should add up");
aoqi@0 3947 }
aoqi@0 3948
aoqi@0 3949 }
aoqi@0 3950
aoqi@0 3951 #define assert_is_available_positive(word_size) \
aoqi@0 3952 assert(vsn.is_available(word_size), \
aoqi@0 3953 err_msg(#word_size ": " PTR_FORMAT " bytes were not available in " \
aoqi@0 3954 "VirtualSpaceNode [" PTR_FORMAT ", " PTR_FORMAT ")", \
aoqi@0 3955 (uintptr_t)(word_size * BytesPerWord), vsn.bottom(), vsn.end()));
aoqi@0 3956
aoqi@0 3957 #define assert_is_available_negative(word_size) \
aoqi@0 3958 assert(!vsn.is_available(word_size), \
aoqi@0 3959 err_msg(#word_size ": " PTR_FORMAT " bytes should not be available in " \
aoqi@0 3960 "VirtualSpaceNode [" PTR_FORMAT ", " PTR_FORMAT ")", \
aoqi@0 3961 (uintptr_t)(word_size * BytesPerWord), vsn.bottom(), vsn.end()));
aoqi@0 3962
aoqi@0 3963 static void test_is_available_positive() {
aoqi@0 3964 // Reserve some memory.
aoqi@0 3965 VirtualSpaceNode vsn(os::vm_allocation_granularity());
aoqi@0 3966 assert(vsn.initialize(), "Failed to setup VirtualSpaceNode");
aoqi@0 3967
aoqi@0 3968 // Commit some memory.
aoqi@0 3969 size_t commit_word_size = os::vm_allocation_granularity() / BytesPerWord;
aoqi@0 3970 bool expanded = vsn.expand_by(commit_word_size, commit_word_size);
aoqi@0 3971 assert(expanded, "Failed to commit");
aoqi@0 3972
aoqi@0 3973 // Check that is_available accepts the committed size.
aoqi@0 3974 assert_is_available_positive(commit_word_size);
aoqi@0 3975
aoqi@0 3976 // Check that is_available accepts half the committed size.
aoqi@0 3977 size_t expand_word_size = commit_word_size / 2;
aoqi@0 3978 assert_is_available_positive(expand_word_size);
aoqi@0 3979 }
aoqi@0 3980
aoqi@0 3981 static void test_is_available_negative() {
aoqi@0 3982 // Reserve some memory.
aoqi@0 3983 VirtualSpaceNode vsn(os::vm_allocation_granularity());
aoqi@0 3984 assert(vsn.initialize(), "Failed to setup VirtualSpaceNode");
aoqi@0 3985
aoqi@0 3986 // Commit some memory.
aoqi@0 3987 size_t commit_word_size = os::vm_allocation_granularity() / BytesPerWord;
aoqi@0 3988 bool expanded = vsn.expand_by(commit_word_size, commit_word_size);
aoqi@0 3989 assert(expanded, "Failed to commit");
aoqi@0 3990
aoqi@0 3991 // Check that is_available doesn't accept a too large size.
aoqi@0 3992 size_t two_times_commit_word_size = commit_word_size * 2;
aoqi@0 3993 assert_is_available_negative(two_times_commit_word_size);
aoqi@0 3994 }
aoqi@0 3995
aoqi@0 3996 static void test_is_available_overflow() {
aoqi@0 3997 // Reserve some memory.
aoqi@0 3998 VirtualSpaceNode vsn(os::vm_allocation_granularity());
aoqi@0 3999 assert(vsn.initialize(), "Failed to setup VirtualSpaceNode");
aoqi@0 4000
aoqi@0 4001 // Commit some memory.
aoqi@0 4002 size_t commit_word_size = os::vm_allocation_granularity() / BytesPerWord;
aoqi@0 4003 bool expanded = vsn.expand_by(commit_word_size, commit_word_size);
aoqi@0 4004 assert(expanded, "Failed to commit");
aoqi@0 4005
aoqi@0 4006 // Calculate a size that will overflow the virtual space size.
aoqi@0 4007 void* virtual_space_max = (void*)(uintptr_t)-1;
aoqi@0 4008 size_t bottom_to_max = pointer_delta(virtual_space_max, vsn.bottom(), 1);
aoqi@0 4009 size_t overflow_size = bottom_to_max + BytesPerWord;
aoqi@0 4010 size_t overflow_word_size = overflow_size / BytesPerWord;
aoqi@0 4011
aoqi@0 4012 // Check that is_available can handle the overflow.
aoqi@0 4013 assert_is_available_negative(overflow_word_size);
aoqi@0 4014 }
aoqi@0 4015
aoqi@0 4016 static void test_is_available() {
aoqi@0 4017 TestVirtualSpaceNodeTest::test_is_available_positive();
aoqi@0 4018 TestVirtualSpaceNodeTest::test_is_available_negative();
aoqi@0 4019 TestVirtualSpaceNodeTest::test_is_available_overflow();
aoqi@0 4020 }
aoqi@0 4021 };
aoqi@0 4022
aoqi@0 4023 void TestVirtualSpaceNode_test() {
aoqi@0 4024 TestVirtualSpaceNodeTest::test();
aoqi@0 4025 TestVirtualSpaceNodeTest::test_is_available();
aoqi@0 4026 }
mchinnathamb@9058 4027
mchinnathamb@9058 4028 // The following test is placed here instead of a gtest / unittest file
mchinnathamb@9058 4029 // because the ChunkManager class is only available in this file.
mchinnathamb@9058 4030 class SpaceManagerTest : AllStatic {
mchinnathamb@9058 4031 friend void SpaceManager_test_adjust_initial_chunk_size();
mchinnathamb@9058 4032
mchinnathamb@9058 4033 static void test_adjust_initial_chunk_size(bool is_class) {
mchinnathamb@9058 4034 const size_t smallest = SpaceManager::smallest_chunk_size(is_class);
mchinnathamb@9058 4035 const size_t normal = SpaceManager::small_chunk_size(is_class);
mchinnathamb@9058 4036 const size_t medium = SpaceManager::medium_chunk_size(is_class);
mchinnathamb@9058 4037
mchinnathamb@9058 4038 #define test_adjust_initial_chunk_size(value, expected, is_class_value) \
mchinnathamb@9058 4039 do { \
mchinnathamb@9058 4040 size_t v = value; \
mchinnathamb@9058 4041 size_t e = expected; \
mchinnathamb@9058 4042 assert(SpaceManager::adjust_initial_chunk_size(v, (is_class_value)) == e, \
mchinnathamb@9058 4043 err_msg("Expected: " SIZE_FORMAT " got: " SIZE_FORMAT, e, v)); \
mchinnathamb@9058 4044 } while (0)
mchinnathamb@9058 4045
mchinnathamb@9058 4046 // Smallest (specialized)
mchinnathamb@9058 4047 test_adjust_initial_chunk_size(1, smallest, is_class);
mchinnathamb@9058 4048 test_adjust_initial_chunk_size(smallest - 1, smallest, is_class);
mchinnathamb@9058 4049 test_adjust_initial_chunk_size(smallest, smallest, is_class);
mchinnathamb@9058 4050
mchinnathamb@9058 4051 // Small
mchinnathamb@9058 4052 test_adjust_initial_chunk_size(smallest + 1, normal, is_class);
mchinnathamb@9058 4053 test_adjust_initial_chunk_size(normal - 1, normal, is_class);
mchinnathamb@9058 4054 test_adjust_initial_chunk_size(normal, normal, is_class);
mchinnathamb@9058 4055
mchinnathamb@9058 4056 // Medium
mchinnathamb@9058 4057 test_adjust_initial_chunk_size(normal + 1, medium, is_class);
mchinnathamb@9058 4058 test_adjust_initial_chunk_size(medium - 1, medium, is_class);
mchinnathamb@9058 4059 test_adjust_initial_chunk_size(medium, medium, is_class);
mchinnathamb@9058 4060
mchinnathamb@9058 4061 // Humongous
mchinnathamb@9058 4062 test_adjust_initial_chunk_size(medium + 1, medium + 1, is_class);
mchinnathamb@9058 4063
mchinnathamb@9058 4064 #undef test_adjust_initial_chunk_size
mchinnathamb@9058 4065 }
mchinnathamb@9058 4066
mchinnathamb@9058 4067 static void test_adjust_initial_chunk_size() {
mchinnathamb@9058 4068 test_adjust_initial_chunk_size(false);
mchinnathamb@9058 4069 test_adjust_initial_chunk_size(true);
mchinnathamb@9058 4070 }
mchinnathamb@9058 4071 };
mchinnathamb@9058 4072
mchinnathamb@9058 4073 void SpaceManager_test_adjust_initial_chunk_size() {
mchinnathamb@9058 4074 SpaceManagerTest::test_adjust_initial_chunk_size();
mchinnathamb@9058 4075 }
mchinnathamb@9058 4076
mchinnathamb@9064 4077 // The following test is placed here instead of a gtest / unittest file
mchinnathamb@9064 4078 // because the ChunkManager class is only available in this file.
mchinnathamb@9064 4079 void ChunkManager_test_list_index() {
mchinnathamb@9064 4080 ChunkManager manager(ClassSpecializedChunk, ClassSmallChunk, ClassMediumChunk);
mchinnathamb@9064 4081
mchinnathamb@9064 4082 // Test previous bug where a query for a humongous class metachunk,
mchinnathamb@9064 4083 // incorrectly matched the non-class medium metachunk size.
mchinnathamb@9064 4084 {
mchinnathamb@9064 4085 assert(MediumChunk > ClassMediumChunk, "Precondition for test");
mchinnathamb@9064 4086
mchinnathamb@9064 4087 ChunkIndex index = manager.list_index(MediumChunk);
mchinnathamb@9064 4088
mchinnathamb@9064 4089 assert(index == HumongousIndex,
mchinnathamb@9064 4090 err_msg("Requested size is larger than ClassMediumChunk,"
mchinnathamb@9064 4091 " so should return HumongousIndex. Got index: %d", (int)index));
mchinnathamb@9064 4092 }
mchinnathamb@9064 4093
mchinnathamb@9064 4094 // Check the specified sizes as well.
mchinnathamb@9064 4095 {
mchinnathamb@9064 4096 ChunkIndex index = manager.list_index(ClassSpecializedChunk);
mchinnathamb@9064 4097 assert(index == SpecializedIndex, err_msg("Wrong index returned. Got index: %d", (int)index));
mchinnathamb@9064 4098 }
mchinnathamb@9064 4099 {
mchinnathamb@9064 4100 ChunkIndex index = manager.list_index(ClassSmallChunk);
mchinnathamb@9064 4101 assert(index == SmallIndex, err_msg("Wrong index returned. Got index: %d", (int)index));
mchinnathamb@9064 4102 }
mchinnathamb@9064 4103 {
mchinnathamb@9064 4104 ChunkIndex index = manager.list_index(ClassMediumChunk);
mchinnathamb@9064 4105 assert(index == MediumIndex, err_msg("Wrong index returned. Got index: %d", (int)index));
mchinnathamb@9064 4106 }
mchinnathamb@9064 4107 {
mchinnathamb@9064 4108 ChunkIndex index = manager.list_index(ClassMediumChunk + 1);
mchinnathamb@9064 4109 assert(index == HumongousIndex, err_msg("Wrong index returned. Got index: %d", (int)index));
mchinnathamb@9064 4110 }
mchinnathamb@9064 4111 }
mchinnathamb@9064 4112
aoqi@0 4113 #endif

mercurial