# HG changeset patch # User stuefe # Date 1549476645 -3600 # Wed Feb 06 19:10:45 2019 +0100 # Node ID e8e34947da6faf787c2cb8ddbf9ca2e22a8bfa36 # Parent 645ba889ee5f7db1c1d35745f9df37566466c2b2 [mq]: metaspace-rename-container-count diff -r 645ba889ee5f -r e8e34947da6f src/hotspot/share/memory/metaspace.cpp --- a/src/hotspot/share/memory/metaspace.cpp Mon Jan 28 16:42:23 2019 +0100 +++ b/src/hotspot/share/memory/metaspace.cpp Wed Feb 06 19:10:45 2019 +0100 @@ -440,7 +440,6 @@ if (chunk_manager == NULL) { return 0; } - chunk_manager->slow_verify(); return chunk_manager->free_chunks_total_words(); } @@ -844,9 +843,9 @@ } void MetaspaceUtils::verify_free_chunks() { - Metaspace::chunk_manager_metadata()->verify(); + Metaspace::chunk_manager_metadata()->verify(false); if (Metaspace::using_class_space()) { - Metaspace::chunk_manager_class()->verify(); + Metaspace::chunk_manager_class()->verify(false); } } diff -r 645ba889ee5f -r e8e34947da6f src/hotspot/share/memory/metaspace/chunkManager.cpp --- a/src/hotspot/share/memory/metaspace/chunkManager.cpp Mon Jan 28 16:42:23 2019 +0100 +++ b/src/hotspot/share/memory/metaspace/chunkManager.cpp Wed Feb 06 19:10:45 2019 +0100 @@ -29,6 +29,7 @@ #include "memory/freeList.inline.hpp" #include "memory/metaspace/chunkManager.hpp" #include "memory/metaspace/metachunk.hpp" +#include "memory/metaspace/metaDebug.hpp" #include "memory/metaspace/metaspaceCommon.hpp" #include "memory/metaspace/metaspaceStatistics.hpp" #include "memory/metaspace/occupancyMap.hpp" @@ -140,15 +141,23 @@ _free_chunks_count -= num_chunks_removed; _free_chunks_count ++; - // VirtualSpaceNode::container_count does not have to be modified: + // VirtualSpaceNode::chunk_count does not have to be modified: // it means "number of active (non-free) chunks", so merging free chunks // should not affect that count. // At the end of a chunk merge, run verification tests. - if (VerifyMetaspace) { - DEBUG_ONLY(this->locked_verify()); - DEBUG_ONLY(vsn->verify()); - } +#ifdef ASSERT + + EVERY_NTH(VerifyMetaspaceInterval) + locked_verify(false); + END_EVERY_NTH + + EVERY_NTH(VerifyMetaspaceInterval * 100) + locked_verify(true); + vsn->verify(); + END_EVERY_NTH + +#endif return true; } @@ -189,14 +198,6 @@ return num_removed; } -size_t ChunkManager::free_chunks_total_words() { - return _free_chunks_total; -} - -size_t ChunkManager::free_chunks_total_bytes() { - return free_chunks_total_words() * BytesPerWord; -} - // Update internal accounting after a chunk was added void ChunkManager::account_for_added_chunk(const Metachunk* c) { assert_lock_strong(MetaspaceExpand_lock); @@ -216,19 +217,6 @@ _free_chunks_total -= c->word_size(); } -size_t ChunkManager::free_chunks_count() { -#ifdef ASSERT - if (!UseConcMarkSweepGC && !MetaspaceExpand_lock->is_locked()) { - MutexLockerEx cl(MetaspaceExpand_lock, - Mutex::_no_safepoint_check_flag); - // This lock is only needed in debug because the verification - // of the _free_chunks_totals walks the list of free chunks - slow_locked_verify_free_chunks_count(); - } -#endif - return _free_chunks_count; -} - ChunkIndex ChunkManager::list_index(size_t size) { return get_chunk_type_by_size(size, is_class()); } @@ -239,42 +227,37 @@ return get_size_for_nonhumongous_chunktype(index, is_class()); } -void ChunkManager::locked_verify_free_chunks_total() { - assert_lock_strong(MetaspaceExpand_lock); - assert(sum_free_chunks() == _free_chunks_total, - "_free_chunks_total " SIZE_FORMAT " is not the" - " same as sum " SIZE_FORMAT, _free_chunks_total, - sum_free_chunks()); +void ChunkManager::verify(bool slow) const { + MutexLockerEx cl(MetaspaceExpand_lock, + Mutex::_no_safepoint_check_flag); + locked_verify(slow); } -void ChunkManager::locked_verify_free_chunks_count() { +void ChunkManager::locked_verify(bool slow) const { assert_lock_strong(MetaspaceExpand_lock); - assert(sum_free_chunks_count() == _free_chunks_count, - "_free_chunks_count " SIZE_FORMAT " is not the" - " same as sum " SIZE_FORMAT, _free_chunks_count, - sum_free_chunks_count()); -} - -void ChunkManager::verify() { - MutexLockerEx cl(MetaspaceExpand_lock, - Mutex::_no_safepoint_check_flag); - locked_verify(); -} - -void ChunkManager::locked_verify() { - locked_verify_free_chunks_count(); - locked_verify_free_chunks_total(); + size_t chunks_counted = 0; + size_t wordsize_chunks_counted = 0; for (ChunkIndex i = ZeroIndex; i < NumberOfFreeLists; i = next_chunk_index(i)) { - ChunkList* list = free_chunks(i); + const ChunkList* list = free_chunks(i); if (list != NULL) { Metachunk* chunk = list->head(); while (chunk) { - DEBUG_ONLY(do_verify_chunk(chunk);) + if (slow) { + do_verify_chunk(chunk); + } assert(chunk->is_tagged_free(), "Chunk should be tagged as free."); + chunks_counted ++; + wordsize_chunks_counted += chunk->size(); chunk = chunk->next(); } } } + assert(chunks_counted == _free_chunks_count && wordsize_chunks_counted == _free_chunks_total, + "freelist accounting mismatch: " + "we think: " SIZE_FORMAT " chunks, total " SIZE_FORMAT " words, " + "reality: " SIZE_FORMAT " chunks, total " SIZE_FORMAT " words.", + _free_chunks_count, _free_chunks_total, + chunks_counted, wordsize_chunks_counted); } void ChunkManager::locked_print_free_chunks(outputStream* st) { @@ -283,49 +266,14 @@ _free_chunks_total, _free_chunks_count); } -void ChunkManager::locked_print_sum_free_chunks(outputStream* st) { - assert_lock_strong(MetaspaceExpand_lock); - st->print_cr("Sum free chunk total " SIZE_FORMAT " count " SIZE_FORMAT, - sum_free_chunks(), sum_free_chunks_count()); -} - ChunkList* ChunkManager::free_chunks(ChunkIndex index) { assert(index == SpecializedIndex || index == SmallIndex || index == MediumIndex, "Bad index: %d", (int)index); - return &_free_chunks[index]; } -// These methods that sum the free chunk lists are used in printing -// methods that are used in product builds. -size_t ChunkManager::sum_free_chunks() { - assert_lock_strong(MetaspaceExpand_lock); - size_t result = 0; - for (ChunkIndex i = ZeroIndex; i < NumberOfFreeLists; i = next_chunk_index(i)) { - ChunkList* list = free_chunks(i); - - if (list == NULL) { - continue; - } - - result = result + list->count() * list->size(); - } - result = result + humongous_dictionary()->total_size(); - return result; -} - -size_t ChunkManager::sum_free_chunks_count() { - assert_lock_strong(MetaspaceExpand_lock); - size_t count = 0; - for (ChunkIndex i = ZeroIndex; i < NumberOfFreeLists; i = next_chunk_index(i)) { - ChunkList* list = free_chunks(i); - if (list == NULL) { - continue; - } - count = count + list->count(); - } - count = count + humongous_dictionary()->total_free_blocks(); - return count; +const ChunkList* ChunkManager::free_chunks(ChunkIndex index) const { + return const_cast(this)->free_chunks(index); } ChunkList* ChunkManager::find_free_chunks_list(size_t word_size) { @@ -427,14 +375,26 @@ } + // At the end of a chunk split, run verification tests. +#ifdef ASSERT + + EVERY_NTH(VerifyMetaspaceInterval) + locked_verify(false); + END_EVERY_NTH + + EVERY_NTH(VerifyMetaspaceInterval * 100) + locked_verify(true); + vsn->verify(); + END_EVERY_NTH + +#endif + return target_chunk; } Metachunk* ChunkManager::free_chunks_get(size_t word_size) { assert_lock_strong(MetaspaceExpand_lock); - slow_locked_verify(); - Metachunk* chunk = NULL; bool we_did_split_a_chunk = false; @@ -515,7 +475,7 @@ // Chunk has been removed from the chunk manager; update counters. account_for_removed_chunk(chunk); do_update_in_use_info_for_chunk(chunk, true); - chunk->container()->inc_container_count(); + chunk->container()->inc_chunk_count(); chunk->inc_use_count(); // Remove it from the links to this freelist @@ -524,14 +484,14 @@ // Run some verifications (some more if we did a chunk split) #ifdef ASSERT - if (VerifyMetaspace) { - locked_verify(); + EVERY_NTH(VerifyMetaspaceInterval) + locked_verify(true); VirtualSpaceNode* const vsn = chunk->container(); vsn->verify(); if (we_did_split_a_chunk) { vsn->verify_free_chunks_are_ideally_merged(); } - } + END_EVERY_NTH #endif return chunk; @@ -539,7 +499,6 @@ Metachunk* ChunkManager::chunk_freelist_allocate(size_t word_size) { assert_lock_strong(MetaspaceExpand_lock); - slow_locked_verify(); // Take from the beginning of the list Metachunk* chunk = free_chunks_get(word_size); @@ -599,7 +558,7 @@ log_trace(gc, metaspace, freelist)("returned one %s chunk at " PTR_FORMAT " (word size " SIZE_FORMAT ") to freelist.", chunk_size_name(index), p2i(chunk), chunk->word_size()); } - chunk->container()->dec_container_count(); + chunk->container()->dec_chunk_count(); do_update_in_use_info_for_chunk(chunk, false); // Chunk has been added; update counters. diff -r 645ba889ee5f -r e8e34947da6f src/hotspot/share/memory/metaspace/chunkManager.hpp --- a/src/hotspot/share/memory/metaspace/chunkManager.hpp Mon Jan 28 16:42:23 2019 +0100 +++ b/src/hotspot/share/memory/metaspace/chunkManager.hpp Wed Feb 06 19:10:45 2019 +0100 @@ -33,7 +33,7 @@ #include "memory/metaspaceChunkFreeListSummary.hpp" #include "utilities/globalDefinitions.hpp" -class ChunkManagerTest; +class ChunkManagerTestAccessor; namespace metaspace { @@ -42,7 +42,7 @@ // Manages the global free lists of chunks. class ChunkManager : public CHeapObj { - friend class ::ChunkManagerTest; + friend class ::ChunkManagerTestAccessor; // Free list of chunks of different sizes. // SpecializedChunk @@ -55,6 +55,7 @@ // Return non-humongous chunk list by its index. ChunkList* free_chunks(ChunkIndex index); + const ChunkList* free_chunks(ChunkIndex index) const; // Returns non-humongous chunk list for the given chunk word size. ChunkList* find_free_chunks_list(size_t word_size); @@ -76,22 +77,6 @@ void account_for_added_chunk(const Metachunk* c); void account_for_removed_chunk(const Metachunk* c); - size_t sum_free_chunks(); - size_t sum_free_chunks_count(); - - void locked_verify_free_chunks_total(); - void slow_locked_verify_free_chunks_total() { - if (VerifyMetaspace) { - locked_verify_free_chunks_total(); - } - } - void locked_verify_free_chunks_count(); - void slow_locked_verify_free_chunks_count() { - if (VerifyMetaspace) { - locked_verify_free_chunks_count(); - } - } - // Given a pointer to a chunk, attempts to merge it with neighboring // free chunks to form a bigger chunk. Returns true if successful. bool attempt_to_coalesce_around_chunk(Metachunk* chunk, ChunkIndex target_chunk_type); @@ -147,11 +132,11 @@ void return_chunk_list(Metachunk* chunk); // Total of the space in the free chunks list - size_t free_chunks_total_words(); - size_t free_chunks_total_bytes(); + size_t free_chunks_total_words() const { return _free_chunks_total; } + size_t free_chunks_total_bytes() const { return free_chunks_total_words() * BytesPerWord; } // Number of chunks in the free chunks list - size_t free_chunks_count(); + size_t free_chunks_count() const { return _free_chunks_count; } // Remove from a list by size. Selects list based on size of chunk. Metachunk* free_chunks_get(size_t chunk_word_size); @@ -196,21 +181,11 @@ } // Debug support - void verify(); - void slow_verify() { - if (VerifyMetaspace) { - verify(); - } - } - void locked_verify(); - void slow_locked_verify() { - if (VerifyMetaspace) { - locked_verify(); - } - } + // Verify free list integrity. slow=true: verify chunk-internal integrity too. + void verify(bool slow) const; + void locked_verify(bool slow) const; void locked_print_free_chunks(outputStream* st); - void locked_print_sum_free_chunks(outputStream* st); // Fill in current statistic values to the given statistics object. void collect_statistics(ChunkManagerStatistics* out) const; diff -r 645ba889ee5f -r e8e34947da6f src/hotspot/share/memory/metaspace/metaDebug.cpp --- a/src/hotspot/share/memory/metaspace/metaDebug.cpp Mon Jan 28 16:42:23 2019 +0100 +++ b/src/hotspot/share/memory/metaspace/metaDebug.cpp Wed Feb 06 19:10:45 2019 +0100 @@ -57,7 +57,6 @@ } #endif - } // namespace metaspace diff -r 645ba889ee5f -r e8e34947da6f src/hotspot/share/memory/metaspace/metaDebug.hpp --- a/src/hotspot/share/memory/metaspace/metaDebug.hpp Mon Jan 28 16:42:23 2019 +0100 +++ b/src/hotspot/share/memory/metaspace/metaDebug.hpp Wed Feb 06 19:10:45 2019 +0100 @@ -41,6 +41,17 @@ #endif }; +#ifdef ASSERT +#define EVERY_NTH(n) \ +{ static int counter_ = 0; \ + if (n > 0) { \ + counter_ ++; \ + if (counter_ > n) { \ + counter_ = 0; \ + +#define END_EVERY_NTH } } } +#endif // ASSERT + } // namespace metaspace #endif // SHARE_MEMORY_METASPACE_METADEBUG_HPP diff -r 645ba889ee5f -r e8e34947da6f src/hotspot/share/memory/metaspace/metaspaceCommon.hpp --- a/src/hotspot/share/memory/metaspace/metaspaceCommon.hpp Mon Jan 28 16:42:23 2019 +0100 +++ b/src/hotspot/share/memory/metaspace/metaspaceCommon.hpp Wed Feb 06 19:10:45 2019 +0100 @@ -123,4 +123,5 @@ } // namespace metaspace + #endif // SHARE_MEMORY_METASPACE_METASPACECOMMON_HPP diff -r 645ba889ee5f -r e8e34947da6f src/hotspot/share/memory/metaspace/spaceManager.cpp --- a/src/hotspot/share/memory/metaspace/spaceManager.cpp Mon Jan 28 16:42:23 2019 +0100 +++ b/src/hotspot/share/memory/metaspace/spaceManager.cpp Wed Feb 06 19:10:45 2019 +0100 @@ -287,8 +287,6 @@ MutexLockerEx fcl(MetaspaceExpand_lock, Mutex::_no_safepoint_check_flag); - chunk_manager()->slow_locked_verify(); - account_for_spacemanager_death(); Log(gc, metaspace, freelist) log; @@ -313,7 +311,11 @@ _current_chunk = NULL; #endif - chunk_manager()->slow_locked_verify(); +#ifdef ASSERT + EVERY_NTH(VerifyMetaspaceInterval) + chunk_manager()->locked_verify(true); + END_EVERY_NTH +#endif if (_block_freelists != NULL) { delete _block_freelists; @@ -405,8 +407,6 @@ BlockFreelist* fl = block_freelists(); MetaWord* p = NULL; - DEBUG_ONLY(if (VerifyMetaspace) verify_metrics_locked()); - // Allocation from the dictionary is expensive in the sense that // the dictionary has to be searched for a size. Don't allocate // from the dictionary until it starts to get fat. Is this @@ -422,6 +422,12 @@ p = allocate_work(raw_word_size); } +#ifdef ASSERT + EVERY_NTH(VerifyMetaspaceInterval) + verify_metrics_locked(); + END_EVERY_NTH +#endif + return p; } diff -r 645ba889ee5f -r e8e34947da6f src/hotspot/share/memory/metaspace/virtualSpaceList.cpp --- a/src/hotspot/share/memory/metaspace/virtualSpaceList.cpp Mon Jan 28 16:42:23 2019 +0100 +++ b/src/hotspot/share/memory/metaspace/virtualSpaceList.cpp Wed Feb 06 19:10:45 2019 +0100 @@ -97,11 +97,11 @@ VirtualSpaceNode* next_vsl = prev_vsl; while (next_vsl != NULL) { VirtualSpaceNode* vsl = next_vsl; - DEBUG_ONLY(vsl->verify_container_count();) + DEBUG_ONLY(vsl->verify_chunk_count();) next_vsl = vsl->next(); // Don't free the current virtual space since it will likely // be needed soon. - if (vsl->container_count() == 0 && vsl != current_virtual_space()) { + if (vsl->chunk_count() == 0 && vsl != current_virtual_space()) { log_trace(gc, metaspace, freelist)("Purging VirtualSpaceNode " PTR_FORMAT " (capacity: " SIZE_FORMAT ", used: " SIZE_FORMAT ").", p2i(vsl), vsl->capacity_words_in_vs(), vsl->used_words_in_vs()); DEBUG_ONLY(Atomic::inc(&g_internal_statistics.num_vsnodes_purged)); diff -r 645ba889ee5f -r e8e34947da6f src/hotspot/share/memory/metaspace/virtualSpaceNode.cpp --- a/src/hotspot/share/memory/metaspace/virtualSpaceNode.cpp Mon Jan 28 16:42:23 2019 +0100 +++ b/src/hotspot/share/memory/metaspace/virtualSpaceNode.cpp Wed Feb 06 19:10:45 2019 +0100 @@ -29,6 +29,7 @@ #include "memory/metaspace/metachunk.hpp" #include "memory/metaspace.hpp" #include "memory/metaspace/chunkManager.hpp" +#include "memory/metaspace/metaDebug.hpp" #include "memory/metaspace/metaspaceCommon.hpp" #include "memory/metaspace/occupancyMap.hpp" #include "memory/metaspace/virtualSpaceNode.hpp" @@ -57,7 +58,7 @@ // byte_size is the size of the associated virtualspace. VirtualSpaceNode::VirtualSpaceNode(bool is_class, size_t bytes) : - _next(NULL), _is_class(is_class), _rs(), _top(NULL), _container_count(0), _occupancy_map(NULL) { + _next(NULL), _is_class(is_class), _rs(), _top(NULL), _chunk_count(0), _occupancy_map(NULL) { assert_is_aligned(bytes, Metaspace::reserve_alignment()); bool large_pages = should_commit_large_pages_when_reserving(bytes); _rs = ReservedSpace(bytes, Metaspace::reserve_alignment(), large_pages); @@ -171,7 +172,7 @@ #ifdef ASSERT -uintx VirtualSpaceNode::container_count_slow() { +uintx VirtualSpaceNode::chunk_count_slow() { uintx count = 0; Metachunk* chunk = first_chunk(); Metachunk* invalid_chunk = (Metachunk*) top(); @@ -206,8 +207,8 @@ MetaWord* next = ((MetaWord*)chunk) + chunk->word_size(); chunk = (Metachunk*) next; } - assert(_container_count == num_in_use_chunks, "Container count mismatch (real: " UINTX_FORMAT - ", counter: " UINTX_FORMAT ".", num_in_use_chunks, _container_count); + assert(_chunk_count == num_in_use_chunks, "Container count mismatch (real: " UINTX_FORMAT + ", counter: " UINTX_FORMAT ".", num_in_use_chunks, _chunk_count); // Also verify the occupancy map. occupancy_map()->verify(this->bottom(), this->top()); } @@ -261,21 +262,21 @@ } #endif // ASSERT -void VirtualSpaceNode::inc_container_count() { +void VirtualSpaceNode::inc_chunk_count() { assert_lock_strong(MetaspaceExpand_lock); - _container_count++; + _chunk_count++; } -void VirtualSpaceNode::dec_container_count() { +void VirtualSpaceNode::dec_chunk_count() { assert_lock_strong(MetaspaceExpand_lock); - _container_count--; + _chunk_count--; } #ifdef ASSERT -void VirtualSpaceNode::verify_container_count() { - assert(_container_count == container_count_slow(), - "Inconsistency in container_count _container_count " UINTX_FORMAT - " container_count_slow() " UINTX_FORMAT, _container_count, container_count_slow()); +void VirtualSpaceNode::verify_chunk_count() { + assert(_chunk_count == chunk_count_slow(), + "Inconsistency in chunk_count _chunk_count " UINTX_FORMAT + " chunk_count_slow() " UINTX_FORMAT, _chunk_count, chunk_count_slow()); } #endif @@ -351,7 +352,7 @@ do_update_in_use_info_for_chunk(padding_chunk, true); // Return Chunk to freelist. - inc_container_count(); + inc_chunk_count(); chunk_manager->return_single_chunk(padding_chunk); // Please note: at this point, ChunkManager::return_single_chunk() // may already have merged the padding chunk with neighboring chunks, so @@ -448,14 +449,15 @@ occupancy_map()->set_chunk_starts_at_address((MetaWord*)result, true); do_update_in_use_info_for_chunk(result, true); - inc_container_count(); + inc_chunk_count(); - if (VerifyMetaspace) { - DEBUG_ONLY(chunk_manager->locked_verify()); - DEBUG_ONLY(this->verify()); - } - - DEBUG_ONLY(do_verify_chunk(result)); +#ifdef ASSERT + EVERY_NTH(VerifyMetaspaceInterval) + chunk_manager->locked_verify(true); + this->verify(); + END_EVERY_NTH + do_verify_chunk(result); +#endif result->inc_use_count(); @@ -558,7 +560,7 @@ #endif // ASSERT void VirtualSpaceNode::retire(ChunkManager* chunk_manager) { - DEBUG_ONLY(verify_container_count();) + DEBUG_ONLY(verify_chunk_count();) assert(this->is_class() == chunk_manager->is_class(), "Wrong ChunkManager?"); for (int i = (int)MediumIndex; i >= (int)ZeroIndex; --i) { ChunkIndex index = (ChunkIndex)i; @@ -577,7 +579,7 @@ } chunk_manager->return_single_chunk(chunk); } - DEBUG_ONLY(verify_container_count();) + DEBUG_ONLY(verify_chunk_count();) } assert(free_words_in_vs() == 0, "should be empty now"); } diff -r 645ba889ee5f -r e8e34947da6f src/hotspot/share/memory/metaspace/virtualSpaceNode.hpp --- a/src/hotspot/share/memory/metaspace/virtualSpaceNode.hpp Mon Jan 28 16:42:23 2019 +0100 +++ b/src/hotspot/share/memory/metaspace/virtualSpaceNode.hpp Wed Feb 06 19:10:45 2019 +0100 @@ -53,7 +53,7 @@ VirtualSpace _virtual_space; MetaWord* _top; // count of chunks contained in this VirtualSpace - uintx _container_count; + uintx _chunk_count; OccupancyMap* _occupancy_map; @@ -75,11 +75,16 @@ // until top is at the given address. void allocate_padding_chunks_until_top_is_at(MetaWord* target_top); +#ifdef ASSERT + uintx chunk_count_slow(); + void verify_chunk_count(); +#endif + public: VirtualSpaceNode(bool is_class, size_t byte_size); VirtualSpaceNode(bool is_class, ReservedSpace rs) : - _next(NULL), _is_class(is_class), _rs(rs), _top(NULL), _container_count(0), _occupancy_map(NULL) {} + _next(NULL), _is_class(is_class), _rs(rs), _top(NULL), _chunk_count(0), _occupancy_map(NULL) {} ~VirtualSpaceNode(); // Convenience functions for logical bottom and end @@ -112,13 +117,9 @@ MetaWord* top() const { return _top; } void inc_top(size_t word_size) { _top += word_size; } - uintx container_count() { return _container_count; } - void inc_container_count(); - void dec_container_count(); -#ifdef ASSERT - uintx container_count_slow(); - void verify_container_count(); -#endif + uintx chunk_count() { return _chunk_count; } + void inc_chunk_count(); + void dec_chunk_count(); // used and capacity in this single entry in the list size_t used_words_in_vs() const; diff -r 645ba889ee5f -r e8e34947da6f src/hotspot/share/runtime/globals.hpp --- a/src/hotspot/share/runtime/globals.hpp Mon Jan 28 16:42:23 2019 +0100 +++ b/src/hotspot/share/runtime/globals.hpp Wed Feb 06 19:10:45 2019 +0100 @@ -2558,8 +2558,9 @@ "File of size Xmx is pre-allocated for performance reason, so" \ "we need that much space available") \ \ - develop(bool, VerifyMetaspace, false, \ - "Verify metaspace on chunk movements.") \ + develop(int, VerifyMetaspaceInterval, DEBUG_ONLY(4096) NOT_DEBUG(0), \ + "Run periodic metaspace verifications (0 - none, " \ + "1 - always, >1 every nth interval)") \ \ diagnostic(bool, ShowRegistersOnAssert, true, \ "On internal errors, include registers in error report.") \ diff -r 645ba889ee5f -r e8e34947da6f test/hotspot/gtest/memory/test_virtualSpaceNode.cpp --- a/test/hotspot/gtest/memory/test_virtualSpaceNode.cpp Mon Jan 28 16:42:23 2019 +0100 +++ b/test/hotspot/gtest/memory/test_virtualSpaceNode.cpp Wed Feb 06 19:10:45 2019 +0100 @@ -59,14 +59,9 @@ }; } -class ChunkManagerTest { +// Note: class exists to be friend to ChunkManager. +class ChunkManagerTestAccessor { public: - static size_t sum_free_chunks(ChunkManager* cm) { - return cm->sum_free_chunks(); - } - static size_t sum_free_chunks_count(ChunkManager* cm) { - return cm->sum_free_chunks_count(); - } static ChunkList* free_chunks(ChunkManager* cm, ChunkIndex i) { return cm->free_chunks(i); } @@ -79,9 +74,9 @@ int _count_pre_existing; public: ChunkManagerRestorer(metaspace::ChunkManager* cm) : _cm(cm), _count_pre_existing(0) { - _cm->locked_verify(); + _cm->locked_verify(true); for (metaspace::ChunkIndex i = metaspace::ZeroIndex; i < metaspace::NumberOfFreeLists; i = next_chunk_index(i)) { - metaspace::ChunkList* l = ChunkManagerTest::free_chunks(_cm, i); + metaspace::ChunkList* l = ChunkManagerTestAccessor::free_chunks(_cm, i); _count_pre_existing += l->count(); std::vector *v = new std::vector(l->count()); metaspace::Metachunk* c = l->head(); @@ -93,9 +88,9 @@ } } ~ChunkManagerRestorer() { - _cm->locked_verify(); + _cm->locked_verify(true); for (metaspace::ChunkIndex i = metaspace::ZeroIndex; i < metaspace::NumberOfFreeLists; i = next_chunk_index(i)) { - metaspace::ChunkList* l = ChunkManagerTest::free_chunks(_cm, i); + metaspace::ChunkList* l = ChunkManagerTestAccessor::free_chunks(_cm, i); std::vector *v = _free_chunks[i]; ssize_t count = l->count(); for (ssize_t j = 0; j < count; j++) { @@ -118,11 +113,11 @@ } int count_after_cleanup = 0; for (ChunkIndex i = ZeroIndex; i < NumberOfFreeLists; i = next_chunk_index(i)) { - ChunkList* l = ChunkManagerTest::free_chunks(_cm, i); + ChunkList* l = ChunkManagerTestAccessor::free_chunks(_cm, i); count_after_cleanup += l->count(); } EXPECT_EQ(_count_pre_existing, count_after_cleanup); - _cm->locked_verify(); + _cm->locked_verify(true); } }; @@ -159,9 +154,6 @@ chunk_up(words_left, num_medium_chunks, num_small_chunks, num_spec_chunks); EXPECT_EQ(0UL, num_medium_chunks) << "should not get any medium chunks"; - // DISABLED: checks started to fail after 8198423 - // EXPECT_EQ((num_small_chunks + num_spec_chunks), ChunkManagerTest::sum_free_chunks_count(&cm)) << "should be space for 3 chunks"; - // EXPECT_EQ(words_left, ChunkManagerTest::sum_free_chunks(&cm)) << "sizes should add up"; } TEST_VM(VirtualSpaceNodeTest, half_vsn_is_committed_humongous_chunk_is_used) { @@ -181,9 +173,6 @@ ASSERT_NO_FATAL_FAILURE(chunk_up(words_left, num_medium_chunks, num_small_chunks, num_spec_chunks)); EXPECT_EQ(0UL, num_medium_chunks) << "should not get any medium chunks"; - // DISABLED: checks started to fail after 8198423 - // EXPECT_EQ((num_small_chunks + num_spec_chunks), ChunkManagerTest::sum_free_chunks_count(&cm)) << "should be space for 3 chunks"; - // EXPECT_EQ(words_left, ChunkManagerTest::sum_free_chunks(&cm)) << "sizes should add up"; } TEST_VM(VirtualSpaceNodeTest, all_vsn_is_committed_half_is_used_by_chunks) { @@ -198,9 +187,6 @@ vsn.get_chunk_vs(MediumChunk); vsn.retire(&cm); - // DISABLED: checks started to fail after 8198423 - // EXPECT_EQ(2UL, ChunkManagerTest::sum_free_chunks_count(&cm)) << "should have been memory left for 2 chunks"; - // EXPECT_EQ(2UL * MediumChunk, ChunkManagerTest::sum_free_chunks(&cm)) << "sizes should add up"; } TEST_VM(VirtualSpaceNodeTest, no_committed_memory) { @@ -212,7 +198,7 @@ vsn.initialize(); vsn.retire(&cm); - ASSERT_EQ(0UL, ChunkManagerTest::sum_free_chunks_count(&cm)) << "did not commit any memory in the VSN"; + ASSERT_EQ(0UL, cm.free_chunks_count()) << "did not commit any memory in the VSN"; } TEST_VM(VirtualSpaceNodeTest, is_available_positive) {