hotspot/src/share/vm/memory/metaspace.cpp
changeset 33105 294e48b4f704
parent 31374 9280d10f1f26
child 34242 e530decd7c63
equal deleted inserted replaced
33104:a7c0f60a1294 33105:294e48b4f704
   187 
   187 
   188 #define index_bounds_check(index)                                         \
   188 #define index_bounds_check(index)                                         \
   189   assert(index == SpecializedIndex ||                                     \
   189   assert(index == SpecializedIndex ||                                     \
   190          index == SmallIndex ||                                           \
   190          index == SmallIndex ||                                           \
   191          index == MediumIndex ||                                          \
   191          index == MediumIndex ||                                          \
   192          index == HumongousIndex, err_msg("Bad index: %d", (int) index))
   192          index == HumongousIndex, "Bad index: %d", (int) index)
   193 
   193 
   194   size_t num_free_chunks(ChunkIndex index) const {
   194   size_t num_free_chunks(ChunkIndex index) const {
   195     index_bounds_check(index);
   195     index_bounds_check(index);
   196 
   196 
   197     if (index == HumongousIndex) {
   197     if (index == HumongousIndex) {
   376   void print_on(outputStream* st) const;
   376   void print_on(outputStream* st) const;
   377 };
   377 };
   378 
   378 
   379 #define assert_is_ptr_aligned(ptr, alignment) \
   379 #define assert_is_ptr_aligned(ptr, alignment) \
   380   assert(is_ptr_aligned(ptr, alignment),      \
   380   assert(is_ptr_aligned(ptr, alignment),      \
   381     err_msg(PTR_FORMAT " is not aligned to "  \
   381          PTR_FORMAT " is not aligned to "     \
   382       SIZE_FORMAT, p2i(ptr), alignment))
   382          SIZE_FORMAT, p2i(ptr), alignment)
   383 
   383 
   384 #define assert_is_size_aligned(size, alignment) \
   384 #define assert_is_size_aligned(size, alignment) \
   385   assert(is_size_aligned(size, alignment),      \
   385   assert(is_size_aligned(size, alignment),      \
   386     err_msg(SIZE_FORMAT " is not aligned to "   \
   386          SIZE_FORMAT " is not aligned to "      \
   387        SIZE_FORMAT, size, alignment))
   387          SIZE_FORMAT, size, alignment)
   388 
   388 
   389 
   389 
   390 // Decide if large pages should be committed when the memory is reserved.
   390 // Decide if large pages should be committed when the memory is reserved.
   391 static bool should_commit_large_pages_when_reserving(size_t bytes) {
   391 static bool should_commit_large_pages_when_reserving(size_t bytes) {
   392   if (UseLargePages && UseLargePagesInMetaspace && !os::can_commit_large_page_memory()) {
   392   if (UseLargePages && UseLargePagesInMetaspace && !os::can_commit_large_page_memory()) {
   799 }
   799 }
   800 
   800 
   801 #ifdef ASSERT
   801 #ifdef ASSERT
   802 void VirtualSpaceNode::verify_container_count() {
   802 void VirtualSpaceNode::verify_container_count() {
   803   assert(_container_count == container_count_slow(),
   803   assert(_container_count == container_count_slow(),
   804     err_msg("Inconsistency in container_count _container_count " UINTX_FORMAT
   804          "Inconsistency in container_count _container_count " UINTX_FORMAT
   805             " container_count_slow() " UINTX_FORMAT, _container_count, container_count_slow()));
   805          " container_count_slow() " UINTX_FORMAT, _container_count, container_count_slow());
   806 }
   806 }
   807 #endif
   807 #endif
   808 
   808 
   809 // BlockFreelist methods
   809 // BlockFreelist methods
   810 
   810 
   963     set_top((MetaWord*)virtual_space()->low());
   963     set_top((MetaWord*)virtual_space()->low());
   964     set_reserved(MemRegion((HeapWord*)_rs.base(),
   964     set_reserved(MemRegion((HeapWord*)_rs.base(),
   965                  (HeapWord*)(_rs.base() + _rs.size())));
   965                  (HeapWord*)(_rs.base() + _rs.size())));
   966 
   966 
   967     assert(reserved()->start() == (HeapWord*) _rs.base(),
   967     assert(reserved()->start() == (HeapWord*) _rs.base(),
   968       err_msg("Reserved start was not set properly " PTR_FORMAT
   968            "Reserved start was not set properly " PTR_FORMAT
   969         " != " PTR_FORMAT, p2i(reserved()->start()), p2i(_rs.base())));
   969            " != " PTR_FORMAT, p2i(reserved()->start()), p2i(_rs.base()));
   970     assert(reserved()->word_size() == _rs.size() / BytesPerWord,
   970     assert(reserved()->word_size() == _rs.size() / BytesPerWord,
   971       err_msg("Reserved size was not set properly " SIZE_FORMAT
   971            "Reserved size was not set properly " SIZE_FORMAT
   972         " != " SIZE_FORMAT, reserved()->word_size(),
   972            " != " SIZE_FORMAT, reserved()->word_size(),
   973         _rs.size() / BytesPerWord));
   973            _rs.size() / BytesPerWord);
   974   }
   974   }
   975 
   975 
   976   return result;
   976   return result;
   977 }
   977 }
   978 
   978 
  1014 void VirtualSpaceList::dec_reserved_words(size_t v) {
  1014 void VirtualSpaceList::dec_reserved_words(size_t v) {
  1015   assert_lock_strong(SpaceManager::expand_lock());
  1015   assert_lock_strong(SpaceManager::expand_lock());
  1016   _reserved_words = _reserved_words - v;
  1016   _reserved_words = _reserved_words - v;
  1017 }
  1017 }
  1018 
  1018 
  1019 #define assert_committed_below_limit()                             \
  1019 #define assert_committed_below_limit()                        \
  1020   assert(MetaspaceAux::committed_bytes() <= MaxMetaspaceSize,      \
  1020   assert(MetaspaceAux::committed_bytes() <= MaxMetaspaceSize, \
  1021       err_msg("Too much committed memory. Committed: " SIZE_FORMAT \
  1021          "Too much committed memory. Committed: " SIZE_FORMAT \
  1022               " limit (MaxMetaspaceSize): " SIZE_FORMAT,           \
  1022          " limit (MaxMetaspaceSize): " SIZE_FORMAT,           \
  1023           MetaspaceAux::committed_bytes(), MaxMetaspaceSize));
  1023          MetaspaceAux::committed_bytes(), MaxMetaspaceSize);
  1024 
  1024 
  1025 void VirtualSpaceList::inc_committed_words(size_t v) {
  1025 void VirtualSpaceList::inc_committed_words(size_t v) {
  1026   assert_lock_strong(SpaceManager::expand_lock());
  1026   assert_lock_strong(SpaceManager::expand_lock());
  1027   _committed_words = _committed_words + v;
  1027   _committed_words = _committed_words + v;
  1028 
  1028 
  1459 size_t MetaspaceGC::allowed_expansion() {
  1459 size_t MetaspaceGC::allowed_expansion() {
  1460   size_t committed_bytes = MetaspaceAux::committed_bytes();
  1460   size_t committed_bytes = MetaspaceAux::committed_bytes();
  1461   size_t capacity_until_gc = capacity_until_GC();
  1461   size_t capacity_until_gc = capacity_until_GC();
  1462 
  1462 
  1463   assert(capacity_until_gc >= committed_bytes,
  1463   assert(capacity_until_gc >= committed_bytes,
  1464         err_msg("capacity_until_gc: " SIZE_FORMAT " < committed_bytes: " SIZE_FORMAT,
  1464          "capacity_until_gc: " SIZE_FORMAT " < committed_bytes: " SIZE_FORMAT,
  1465                 capacity_until_gc, committed_bytes));
  1465          capacity_until_gc, committed_bytes);
  1466 
  1466 
  1467   size_t left_until_max  = MaxMetaspaceSize - committed_bytes;
  1467   size_t left_until_max  = MaxMetaspaceSize - committed_bytes;
  1468   size_t left_until_GC = capacity_until_gc - committed_bytes;
  1468   size_t left_until_GC = capacity_until_gc - committed_bytes;
  1469   size_t left_to_commit = MIN2(left_until_GC, left_until_max);
  1469   size_t left_to_commit = MIN2(left_until_GC, left_until_max);
  1470 
  1470 
  1541   }
  1541   }
  1542 
  1542 
  1543   // No expansion, now see if we want to shrink
  1543   // No expansion, now see if we want to shrink
  1544   // We would never want to shrink more than this
  1544   // We would never want to shrink more than this
  1545   assert(capacity_until_GC >= minimum_desired_capacity,
  1545   assert(capacity_until_GC >= minimum_desired_capacity,
  1546          err_msg(SIZE_FORMAT " >= " SIZE_FORMAT,
  1546          SIZE_FORMAT " >= " SIZE_FORMAT,
  1547                  capacity_until_GC, minimum_desired_capacity));
  1547          capacity_until_GC, minimum_desired_capacity);
  1548   size_t max_shrink_bytes = capacity_until_GC - minimum_desired_capacity;
  1548   size_t max_shrink_bytes = capacity_until_GC - minimum_desired_capacity;
  1549 
  1549 
  1550   // Should shrinking be considered?
  1550   // Should shrinking be considered?
  1551   if (MaxMetaspaceFreeRatio < 100) {
  1551   if (MaxMetaspaceFreeRatio < 100) {
  1552     const double maximum_free_percentage = MaxMetaspaceFreeRatio / 100.0;
  1552     const double maximum_free_percentage = MaxMetaspaceFreeRatio / 100.0;
  1583       shrink_bytes = shrink_bytes / 100 * current_shrink_factor;
  1583       shrink_bytes = shrink_bytes / 100 * current_shrink_factor;
  1584 
  1584 
  1585       shrink_bytes = align_size_down(shrink_bytes, Metaspace::commit_alignment());
  1585       shrink_bytes = align_size_down(shrink_bytes, Metaspace::commit_alignment());
  1586 
  1586 
  1587       assert(shrink_bytes <= max_shrink_bytes,
  1587       assert(shrink_bytes <= max_shrink_bytes,
  1588         err_msg("invalid shrink size " SIZE_FORMAT " not <= " SIZE_FORMAT,
  1588              "invalid shrink size " SIZE_FORMAT " not <= " SIZE_FORMAT,
  1589           shrink_bytes, max_shrink_bytes));
  1589              shrink_bytes, max_shrink_bytes);
  1590       if (current_shrink_factor == 0) {
  1590       if (current_shrink_factor == 0) {
  1591         _shrink_factor = 10;
  1591         _shrink_factor = 10;
  1592       } else {
  1592       } else {
  1593         _shrink_factor = MIN2(current_shrink_factor * 4, (uint) 100);
  1593         _shrink_factor = MIN2(current_shrink_factor * 4, (uint) 100);
  1594       }
  1594       }
  1674 }
  1674 }
  1675 
  1675 
  1676 void ChunkManager::locked_verify_free_chunks_total() {
  1676 void ChunkManager::locked_verify_free_chunks_total() {
  1677   assert_lock_strong(SpaceManager::expand_lock());
  1677   assert_lock_strong(SpaceManager::expand_lock());
  1678   assert(sum_free_chunks() == _free_chunks_total,
  1678   assert(sum_free_chunks() == _free_chunks_total,
  1679     err_msg("_free_chunks_total " SIZE_FORMAT " is not the"
  1679          "_free_chunks_total " SIZE_FORMAT " is not the"
  1680            " same as sum " SIZE_FORMAT, _free_chunks_total,
  1680          " same as sum " SIZE_FORMAT, _free_chunks_total,
  1681            sum_free_chunks()));
  1681          sum_free_chunks());
  1682 }
  1682 }
  1683 
  1683 
  1684 void ChunkManager::verify_free_chunks_total() {
  1684 void ChunkManager::verify_free_chunks_total() {
  1685   MutexLockerEx cl(SpaceManager::expand_lock(),
  1685   MutexLockerEx cl(SpaceManager::expand_lock(),
  1686                      Mutex::_no_safepoint_check_flag);
  1686                      Mutex::_no_safepoint_check_flag);
  1688 }
  1688 }
  1689 
  1689 
  1690 void ChunkManager::locked_verify_free_chunks_count() {
  1690 void ChunkManager::locked_verify_free_chunks_count() {
  1691   assert_lock_strong(SpaceManager::expand_lock());
  1691   assert_lock_strong(SpaceManager::expand_lock());
  1692   assert(sum_free_chunks_count() == _free_chunks_count,
  1692   assert(sum_free_chunks_count() == _free_chunks_count,
  1693     err_msg("_free_chunks_count " SIZE_FORMAT " is not the"
  1693          "_free_chunks_count " SIZE_FORMAT " is not the"
  1694            " same as sum " SIZE_FORMAT, _free_chunks_count,
  1694          " same as sum " SIZE_FORMAT, _free_chunks_count,
  1695            sum_free_chunks_count()));
  1695          sum_free_chunks_count());
  1696 }
  1696 }
  1697 
  1697 
  1698 void ChunkManager::verify_free_chunks_count() {
  1698 void ChunkManager::verify_free_chunks_count() {
  1699 #ifdef ASSERT
  1699 #ifdef ASSERT
  1700   MutexLockerEx cl(SpaceManager::expand_lock(),
  1700   MutexLockerEx cl(SpaceManager::expand_lock(),
  1889     *chunk_word_size = SmallChunk;
  1889     *chunk_word_size = SmallChunk;
  1890     *class_chunk_word_size = ClassSmallChunk;
  1890     *class_chunk_word_size = ClassSmallChunk;
  1891     break;
  1891     break;
  1892   }
  1892   }
  1893   assert(*chunk_word_size != 0 && *class_chunk_word_size != 0,
  1893   assert(*chunk_word_size != 0 && *class_chunk_word_size != 0,
  1894     err_msg("Initial chunks sizes bad: data  " SIZE_FORMAT
  1894          "Initial chunks sizes bad: data  " SIZE_FORMAT
  1895             " class " SIZE_FORMAT,
  1895          " class " SIZE_FORMAT,
  1896             *chunk_word_size, *class_chunk_word_size));
  1896          *chunk_word_size, *class_chunk_word_size);
  1897 }
  1897 }
  1898 
  1898 
  1899 size_t SpaceManager::sum_free_in_chunks_in_use() const {
  1899 size_t SpaceManager::sum_free_in_chunks_in_use() const {
  1900   MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
  1900   MutexLockerEx cl(lock(), Mutex::_no_safepoint_check_flag);
  1901   size_t free = 0;
  1901   size_t free = 0;
  2034   chunk_word_size =
  2034   chunk_word_size =
  2035     MAX2((size_t) chunk_word_size, if_humongous_sized_chunk);
  2035     MAX2((size_t) chunk_word_size, if_humongous_sized_chunk);
  2036 
  2036 
  2037   assert(!SpaceManager::is_humongous(word_size) ||
  2037   assert(!SpaceManager::is_humongous(word_size) ||
  2038          chunk_word_size == if_humongous_sized_chunk,
  2038          chunk_word_size == if_humongous_sized_chunk,
  2039          err_msg("Size calculation is wrong, word_size " SIZE_FORMAT
  2039          "Size calculation is wrong, word_size " SIZE_FORMAT
  2040                  " chunk_word_size " SIZE_FORMAT,
  2040          " chunk_word_size " SIZE_FORMAT,
  2041                  word_size, chunk_word_size));
  2041          word_size, chunk_word_size);
  2042   if (TraceMetadataHumongousAllocation &&
  2042   if (TraceMetadataHumongousAllocation &&
  2043       SpaceManager::is_humongous(word_size)) {
  2043       SpaceManager::is_humongous(word_size)) {
  2044     gclog_or_tty->print_cr("Metadata humongous allocation:");
  2044     gclog_or_tty->print_cr("Metadata humongous allocation:");
  2045     gclog_or_tty->print_cr("  word_size " PTR_FORMAT, word_size);
  2045     gclog_or_tty->print_cr("  word_size " PTR_FORMAT, word_size);
  2046     gclog_or_tty->print_cr("  chunk_word_size " PTR_FORMAT,
  2046     gclog_or_tty->print_cr("  chunk_word_size " PTR_FORMAT,
  2200 }
  2200 }
  2201 
  2201 
  2202 SpaceManager::~SpaceManager() {
  2202 SpaceManager::~SpaceManager() {
  2203   // This call this->_lock which can't be done while holding expand_lock()
  2203   // This call this->_lock which can't be done while holding expand_lock()
  2204   assert(sum_capacity_in_chunks_in_use() == allocated_chunks_words(),
  2204   assert(sum_capacity_in_chunks_in_use() == allocated_chunks_words(),
  2205     err_msg("sum_capacity_in_chunks_in_use() " SIZE_FORMAT
  2205          "sum_capacity_in_chunks_in_use() " SIZE_FORMAT
  2206             " allocated_chunks_words() " SIZE_FORMAT,
  2206          " allocated_chunks_words() " SIZE_FORMAT,
  2207             sum_capacity_in_chunks_in_use(), allocated_chunks_words()));
  2207          sum_capacity_in_chunks_in_use(), allocated_chunks_words());
  2208 
  2208 
  2209   MutexLockerEx fcl(SpaceManager::expand_lock(),
  2209   MutexLockerEx fcl(SpaceManager::expand_lock(),
  2210                     Mutex::_no_safepoint_check_flag);
  2210                     Mutex::_no_safepoint_check_flag);
  2211 
  2211 
  2212   chunk_manager()->slow_locked_verify();
  2212   chunk_manager()->slow_locked_verify();
  2273                           humongous_chunks->word_size());
  2273                           humongous_chunks->word_size());
  2274     }
  2274     }
  2275     assert(humongous_chunks->word_size() == (size_t)
  2275     assert(humongous_chunks->word_size() == (size_t)
  2276            align_size_up(humongous_chunks->word_size(),
  2276            align_size_up(humongous_chunks->word_size(),
  2277                              smallest_chunk_size()),
  2277                              smallest_chunk_size()),
  2278            err_msg("Humongous chunk size is wrong: word size " SIZE_FORMAT
  2278            "Humongous chunk size is wrong: word size " SIZE_FORMAT
  2279                    " granularity " SIZE_FORMAT,
  2279            " granularity " SIZE_FORMAT,
  2280                    humongous_chunks->word_size(), smallest_chunk_size()));
  2280            humongous_chunks->word_size(), smallest_chunk_size());
  2281     Metachunk* next_humongous_chunks = humongous_chunks->next();
  2281     Metachunk* next_humongous_chunks = humongous_chunks->next();
  2282     humongous_chunks->container()->dec_container_count();
  2282     humongous_chunks->container()->dec_container_count();
  2283     chunk_manager()->humongous_dictionary()->return_chunk(humongous_chunks);
  2283     chunk_manager()->humongous_dictionary()->return_chunk(humongous_chunks);
  2284     humongous_chunks = next_humongous_chunks;
  2284     humongous_chunks = next_humongous_chunks;
  2285   }
  2285   }
  2329 void SpaceManager::deallocate(MetaWord* p, size_t word_size) {
  2329 void SpaceManager::deallocate(MetaWord* p, size_t word_size) {
  2330   assert_lock_strong(_lock);
  2330   assert_lock_strong(_lock);
  2331   size_t raw_word_size = get_raw_word_size(word_size);
  2331   size_t raw_word_size = get_raw_word_size(word_size);
  2332   size_t min_size = TreeChunk<Metablock, FreeList<Metablock> >::min_size();
  2332   size_t min_size = TreeChunk<Metablock, FreeList<Metablock> >::min_size();
  2333   assert(raw_word_size >= min_size,
  2333   assert(raw_word_size >= min_size,
  2334          err_msg("Should not deallocate dark matter " SIZE_FORMAT "<" SIZE_FORMAT, word_size, min_size));
  2334          "Should not deallocate dark matter " SIZE_FORMAT "<" SIZE_FORMAT, word_size, min_size);
  2335   block_freelists()->return_block(p, raw_word_size);
  2335   block_freelists()->return_block(p, raw_word_size);
  2336 }
  2336 }
  2337 
  2337 
  2338 // Adds a chunk to the list of chunks in use.
  2338 // Adds a chunk to the list of chunks in use.
  2339 void SpaceManager::add_chunk(Metachunk* new_chunk, bool make_current) {
  2339 void SpaceManager::add_chunk(Metachunk* new_chunk, bool make_current) {
  2539 void SpaceManager::verify_allocated_blocks_words() {
  2539 void SpaceManager::verify_allocated_blocks_words() {
  2540   // Verification is only guaranteed at a safepoint.
  2540   // Verification is only guaranteed at a safepoint.
  2541   assert(SafepointSynchronize::is_at_safepoint() || !Universe::is_fully_initialized(),
  2541   assert(SafepointSynchronize::is_at_safepoint() || !Universe::is_fully_initialized(),
  2542     "Verification can fail if the applications is running");
  2542     "Verification can fail if the applications is running");
  2543   assert(allocated_blocks_words() == sum_used_in_chunks_in_use(),
  2543   assert(allocated_blocks_words() == sum_used_in_chunks_in_use(),
  2544     err_msg("allocation total is not consistent " SIZE_FORMAT
  2544          "allocation total is not consistent " SIZE_FORMAT
  2545             " vs " SIZE_FORMAT,
  2545          " vs " SIZE_FORMAT,
  2546             allocated_blocks_words(), sum_used_in_chunks_in_use()));
  2546          allocated_blocks_words(), sum_used_in_chunks_in_use());
  2547 }
  2547 }
  2548 
  2548 
  2549 #endif
  2549 #endif
  2550 
  2550 
  2551 void SpaceManager::dump(outputStream* const out) const {
  2551 void SpaceManager::dump(outputStream* const out) const {
  2614 }
  2614 }
  2615 
  2615 
  2616 void MetaspaceAux::dec_capacity(Metaspace::MetadataType mdtype, size_t words) {
  2616 void MetaspaceAux::dec_capacity(Metaspace::MetadataType mdtype, size_t words) {
  2617   assert_lock_strong(SpaceManager::expand_lock());
  2617   assert_lock_strong(SpaceManager::expand_lock());
  2618   assert(words <= capacity_words(mdtype),
  2618   assert(words <= capacity_words(mdtype),
  2619     err_msg("About to decrement below 0: words " SIZE_FORMAT
  2619          "About to decrement below 0: words " SIZE_FORMAT
  2620             " is greater than _capacity_words[%u] " SIZE_FORMAT,
  2620          " is greater than _capacity_words[%u] " SIZE_FORMAT,
  2621             words, mdtype, capacity_words(mdtype)));
  2621          words, mdtype, capacity_words(mdtype));
  2622   _capacity_words[mdtype] -= words;
  2622   _capacity_words[mdtype] -= words;
  2623 }
  2623 }
  2624 
  2624 
  2625 void MetaspaceAux::inc_capacity(Metaspace::MetadataType mdtype, size_t words) {
  2625 void MetaspaceAux::inc_capacity(Metaspace::MetadataType mdtype, size_t words) {
  2626   assert_lock_strong(SpaceManager::expand_lock());
  2626   assert_lock_strong(SpaceManager::expand_lock());
  2628   _capacity_words[mdtype] += words;
  2628   _capacity_words[mdtype] += words;
  2629 }
  2629 }
  2630 
  2630 
  2631 void MetaspaceAux::dec_used(Metaspace::MetadataType mdtype, size_t words) {
  2631 void MetaspaceAux::dec_used(Metaspace::MetadataType mdtype, size_t words) {
  2632   assert(words <= used_words(mdtype),
  2632   assert(words <= used_words(mdtype),
  2633     err_msg("About to decrement below 0: words " SIZE_FORMAT
  2633          "About to decrement below 0: words " SIZE_FORMAT
  2634             " is greater than _used_words[%u] " SIZE_FORMAT,
  2634          " is greater than _used_words[%u] " SIZE_FORMAT,
  2635             words, mdtype, used_words(mdtype)));
  2635          words, mdtype, used_words(mdtype));
  2636   // For CMS deallocation of the Metaspaces occurs during the
  2636   // For CMS deallocation of the Metaspaces occurs during the
  2637   // sweep which is a concurrent phase.  Protection by the expand_lock()
  2637   // sweep which is a concurrent phase.  Protection by the expand_lock()
  2638   // is not enough since allocation is on a per Metaspace basis
  2638   // is not enough since allocation is on a per Metaspace basis
  2639   // and protected by the Metaspace lock.
  2639   // and protected by the Metaspace lock.
  2640   jlong minus_words = (jlong) - (jlong) words;
  2640   jlong minus_words = (jlong) - (jlong) words;
  2697   guarantee(false, "Should not call capacity_bytes_slow() in the PRODUCT");
  2697   guarantee(false, "Should not call capacity_bytes_slow() in the PRODUCT");
  2698 #endif
  2698 #endif
  2699   size_t class_capacity = capacity_bytes_slow(Metaspace::ClassType);
  2699   size_t class_capacity = capacity_bytes_slow(Metaspace::ClassType);
  2700   size_t non_class_capacity = capacity_bytes_slow(Metaspace::NonClassType);
  2700   size_t non_class_capacity = capacity_bytes_slow(Metaspace::NonClassType);
  2701   assert(capacity_bytes() == class_capacity + non_class_capacity,
  2701   assert(capacity_bytes() == class_capacity + non_class_capacity,
  2702       err_msg("bad accounting: capacity_bytes() " SIZE_FORMAT
  2702          "bad accounting: capacity_bytes() " SIZE_FORMAT
  2703         " class_capacity + non_class_capacity " SIZE_FORMAT
  2703          " class_capacity + non_class_capacity " SIZE_FORMAT
  2704         " class_capacity " SIZE_FORMAT " non_class_capacity " SIZE_FORMAT,
  2704          " class_capacity " SIZE_FORMAT " non_class_capacity " SIZE_FORMAT,
  2705         capacity_bytes(), class_capacity + non_class_capacity,
  2705          capacity_bytes(), class_capacity + non_class_capacity,
  2706         class_capacity, non_class_capacity));
  2706          class_capacity, non_class_capacity);
  2707 
  2707 
  2708   return class_capacity + non_class_capacity;
  2708   return class_capacity + non_class_capacity;
  2709 }
  2709 }
  2710 
  2710 
  2711 size_t MetaspaceAux::reserved_bytes(Metaspace::MetadataType mdtype) {
  2711 size_t MetaspaceAux::reserved_bytes(Metaspace::MetadataType mdtype) {
  2902 #ifdef ASSERT
  2902 #ifdef ASSERT
  2903   size_t running_sum_capacity_bytes = capacity_bytes();
  2903   size_t running_sum_capacity_bytes = capacity_bytes();
  2904   // For purposes of the running sum of capacity, verify against capacity
  2904   // For purposes of the running sum of capacity, verify against capacity
  2905   size_t capacity_in_use_bytes = capacity_bytes_slow();
  2905   size_t capacity_in_use_bytes = capacity_bytes_slow();
  2906   assert(running_sum_capacity_bytes == capacity_in_use_bytes,
  2906   assert(running_sum_capacity_bytes == capacity_in_use_bytes,
  2907     err_msg("capacity_words() * BytesPerWord " SIZE_FORMAT
  2907          "capacity_words() * BytesPerWord " SIZE_FORMAT
  2908             " capacity_bytes_slow()" SIZE_FORMAT,
  2908          " capacity_bytes_slow()" SIZE_FORMAT,
  2909             running_sum_capacity_bytes, capacity_in_use_bytes));
  2909          running_sum_capacity_bytes, capacity_in_use_bytes);
  2910   for (Metaspace::MetadataType i = Metaspace::ClassType;
  2910   for (Metaspace::MetadataType i = Metaspace::ClassType;
  2911        i < Metaspace:: MetadataTypeCount;
  2911        i < Metaspace:: MetadataTypeCount;
  2912        i = (Metaspace::MetadataType)(i + 1)) {
  2912        i = (Metaspace::MetadataType)(i + 1)) {
  2913     size_t capacity_in_use_bytes = capacity_bytes_slow(i);
  2913     size_t capacity_in_use_bytes = capacity_bytes_slow(i);
  2914     assert(capacity_bytes(i) == capacity_in_use_bytes,
  2914     assert(capacity_bytes(i) == capacity_in_use_bytes,
  2915       err_msg("capacity_bytes(%u) " SIZE_FORMAT
  2915            "capacity_bytes(%u) " SIZE_FORMAT
  2916               " capacity_bytes_slow(%u)" SIZE_FORMAT,
  2916            " capacity_bytes_slow(%u)" SIZE_FORMAT,
  2917               i, capacity_bytes(i), i, capacity_in_use_bytes));
  2917            i, capacity_bytes(i), i, capacity_in_use_bytes);
  2918   }
  2918   }
  2919 #endif
  2919 #endif
  2920 }
  2920 }
  2921 
  2921 
  2922 void MetaspaceAux::verify_used() {
  2922 void MetaspaceAux::verify_used() {
  2923 #ifdef ASSERT
  2923 #ifdef ASSERT
  2924   size_t running_sum_used_bytes = used_bytes();
  2924   size_t running_sum_used_bytes = used_bytes();
  2925   // For purposes of the running sum of used, verify against used
  2925   // For purposes of the running sum of used, verify against used
  2926   size_t used_in_use_bytes = used_bytes_slow();
  2926   size_t used_in_use_bytes = used_bytes_slow();
  2927   assert(used_bytes() == used_in_use_bytes,
  2927   assert(used_bytes() == used_in_use_bytes,
  2928     err_msg("used_bytes() " SIZE_FORMAT
  2928          "used_bytes() " SIZE_FORMAT
  2929             " used_bytes_slow()" SIZE_FORMAT,
  2929          " used_bytes_slow()" SIZE_FORMAT,
  2930             used_bytes(), used_in_use_bytes));
  2930          used_bytes(), used_in_use_bytes);
  2931   for (Metaspace::MetadataType i = Metaspace::ClassType;
  2931   for (Metaspace::MetadataType i = Metaspace::ClassType;
  2932        i < Metaspace:: MetadataTypeCount;
  2932        i < Metaspace:: MetadataTypeCount;
  2933        i = (Metaspace::MetadataType)(i + 1)) {
  2933        i = (Metaspace::MetadataType)(i + 1)) {
  2934     size_t used_in_use_bytes = used_bytes_slow(i);
  2934     size_t used_in_use_bytes = used_bytes_slow(i);
  2935     assert(used_bytes(i) == used_in_use_bytes,
  2935     assert(used_bytes(i) == used_in_use_bytes,
  2936       err_msg("used_bytes(%u) " SIZE_FORMAT
  2936            "used_bytes(%u) " SIZE_FORMAT
  2937               " used_bytes_slow(%u)" SIZE_FORMAT,
  2937            " used_bytes_slow(%u)" SIZE_FORMAT,
  2938               i, used_bytes(i), i, used_in_use_bytes));
  2938            i, used_bytes(i), i, used_in_use_bytes);
  2939   }
  2939   }
  2940 #endif
  2940 #endif
  2941 }
  2941 }
  2942 
  2942 
  2943 void MetaspaceAux::verify_metrics() {
  2943 void MetaspaceAux::verify_metrics() {
  3155 // For UseCompressedClassPointers the class space is reserved above the top of
  3155 // For UseCompressedClassPointers the class space is reserved above the top of
  3156 // the Java heap.  The argument passed in is at the base of the compressed space.
  3156 // the Java heap.  The argument passed in is at the base of the compressed space.
  3157 void Metaspace::initialize_class_space(ReservedSpace rs) {
  3157 void Metaspace::initialize_class_space(ReservedSpace rs) {
  3158   // The reserved space size may be bigger because of alignment, esp with UseLargePages
  3158   // The reserved space size may be bigger because of alignment, esp with UseLargePages
  3159   assert(rs.size() >= CompressedClassSpaceSize,
  3159   assert(rs.size() >= CompressedClassSpaceSize,
  3160          err_msg(SIZE_FORMAT " != " SIZE_FORMAT, rs.size(), CompressedClassSpaceSize));
  3160          SIZE_FORMAT " != " SIZE_FORMAT, rs.size(), CompressedClassSpaceSize);
  3161   assert(using_class_space(), "Must be using class space");
  3161   assert(using_class_space(), "Must be using class space");
  3162   _class_space_list = new VirtualSpaceList(rs);
  3162   _class_space_list = new VirtualSpaceList(rs);
  3163   _chunk_manager_class = new ChunkManager(SpecializedChunk, ClassSmallChunk, ClassMediumChunk);
  3163   _chunk_manager_class = new ChunkManager(SpecializedChunk, ClassSmallChunk, ClassMediumChunk);
  3164 
  3164 
  3165   if (!_class_space_list->initialization_succeeded()) {
  3165   if (!_class_space_list->initialization_succeeded()) {
  3686 const char* Metaspace::metadata_type_name(Metaspace::MetadataType mdtype) {
  3686 const char* Metaspace::metadata_type_name(Metaspace::MetadataType mdtype) {
  3687   switch (mdtype) {
  3687   switch (mdtype) {
  3688     case Metaspace::ClassType: return "Class";
  3688     case Metaspace::ClassType: return "Class";
  3689     case Metaspace::NonClassType: return "Metadata";
  3689     case Metaspace::NonClassType: return "Metadata";
  3690     default:
  3690     default:
  3691       assert(false, err_msg("Got bad mdtype: %d", (int) mdtype));
  3691       assert(false, "Got bad mdtype: %d", (int) mdtype);
  3692       return NULL;
  3692       return NULL;
  3693   }
  3693   }
  3694 }
  3694 }
  3695 
  3695 
  3696 void Metaspace::record_allocation(void* ptr, MetaspaceObj::Type type, size_t word_size) {
  3696 void Metaspace::record_allocation(void* ptr, MetaspaceObj::Type type, size_t word_size) {
  3968 
  3968 
  3969   }
  3969   }
  3970 
  3970 
  3971 #define assert_is_available_positive(word_size) \
  3971 #define assert_is_available_positive(word_size) \
  3972   assert(vsn.is_available(word_size), \
  3972   assert(vsn.is_available(word_size), \
  3973     err_msg(#word_size ": " PTR_FORMAT " bytes were not available in " \
  3973          #word_size ": " PTR_FORMAT " bytes were not available in " \
  3974             "VirtualSpaceNode [" PTR_FORMAT ", " PTR_FORMAT ")", \
  3974          "VirtualSpaceNode [" PTR_FORMAT ", " PTR_FORMAT ")", \
  3975             (uintptr_t)(word_size * BytesPerWord), p2i(vsn.bottom()), p2i(vsn.end())));
  3975          (uintptr_t)(word_size * BytesPerWord), p2i(vsn.bottom()), p2i(vsn.end()));
  3976 
  3976 
  3977 #define assert_is_available_negative(word_size) \
  3977 #define assert_is_available_negative(word_size) \
  3978   assert(!vsn.is_available(word_size), \
  3978   assert(!vsn.is_available(word_size), \
  3979     err_msg(#word_size ": " PTR_FORMAT " bytes should not be available in " \
  3979          #word_size ": " PTR_FORMAT " bytes should not be available in " \
  3980             "VirtualSpaceNode [" PTR_FORMAT ", " PTR_FORMAT ")", \
  3980          "VirtualSpaceNode [" PTR_FORMAT ", " PTR_FORMAT ")", \
  3981             (uintptr_t)(word_size * BytesPerWord), p2i(vsn.bottom()), p2i(vsn.end())));
  3981          (uintptr_t)(word_size * BytesPerWord), p2i(vsn.bottom()), p2i(vsn.end()));
  3982 
  3982 
  3983   static void test_is_available_positive() {
  3983   static void test_is_available_positive() {
  3984     // Reserve some memory.
  3984     // Reserve some memory.
  3985     VirtualSpaceNode vsn(os::vm_allocation_granularity());
  3985     VirtualSpaceNode vsn(os::vm_allocation_granularity());
  3986     assert(vsn.initialize(), "Failed to setup VirtualSpaceNode");
  3986     assert(vsn.initialize(), "Failed to setup VirtualSpaceNode");