# HG changeset patch # User stuefe # Date 1562660105 -7200 # Tue Jul 09 10:15:05 2019 +0200 # Node ID 4296ff899d02393ede28cf9e784c69ebf9a211e5 # Parent 0b470386f5f7d68415a8cd7ee526d2cf12bb1b77 [mq]: memleak diff -r 0b470386f5f7 -r 4296ff899d02 src/hotspot/share/memory/metaspace.cpp --- a/src/hotspot/share/memory/metaspace.cpp Tue Jul 09 09:20:04 2019 +0200 +++ b/src/hotspot/share/memory/metaspace.cpp Tue Jul 09 10:15:05 2019 +0200 @@ -195,22 +195,12 @@ _capacity_until_GC = MAX2(MetaspaceUtils::committed_bytes(), MetaspaceSize); } -bool MetaspaceGC::can_expand(size_t word_size, bool is_class) { - // Check if the compressed class space is full. - if (is_class && Metaspace::using_class_space()) { - size_t class_committed = MetaspaceUtils::committed_bytes(Metaspace::ClassType); - if (class_committed + word_size * BytesPerWord > CompressedClassSpaceSize) { - log_trace(gc, metaspace, freelist)("Cannot expand %s metaspace by " SIZE_FORMAT " words (CompressedClassSpaceSize = " SIZE_FORMAT " words)", - (is_class ? "class" : "non-class"), word_size, CompressedClassSpaceSize / sizeof(MetaWord)); - return false; - } - } - +bool MetaspaceGC::can_expand(size_t word_size) { // Check if the user has imposed a limit on the metaspace memory. size_t committed_bytes = MetaspaceUtils::committed_bytes(); if (committed_bytes + word_size * BytesPerWord > MaxMetaspaceSize) { - log_trace(gc, metaspace, freelist)("Cannot expand %s metaspace by " SIZE_FORMAT " words (MaxMetaspaceSize = " SIZE_FORMAT " words)", - (is_class ? "class" : "non-class"), word_size, MaxMetaspaceSize / sizeof(MetaWord)); + log_trace(gc, metaspace, freelist)("Cannot expand metaspace by " SIZE_FORMAT " words (MaxMetaspaceSize = " SIZE_FORMAT " words)", + word_size, MaxMetaspaceSize / sizeof(MetaWord)); return false; } @@ -1526,17 +1516,28 @@ } } +volatile char* p = NULL; + MetaWord* ClassLoaderMetaspace::allocate(size_t word_size, Metaspace::MetadataType mdtype) { Metaspace::assert_not_frozen(); DEBUG_ONLY(Atomic::inc(&g_internal_statistics.num_allocs)); - // Don't use class_vsm() unless UseCompressedClassPointers is true. + // MEmleak + if (UseNewCode) { + for (int i = 0; i < 1024; i ++) { + p = (char*) os::malloc(10 * K, mtInternal); + } + } + + // Don't use class_vsm() unless UseCompressedClassPointers is true. if (Metaspace::is_class_space_allocation(mdtype)) { return class_vsm()->allocate(word_size); } else { return vsm()->allocate(word_size); } + + } MetaWord* ClassLoaderMetaspace::expand_and_allocate(size_t word_size, Metaspace::MetadataType mdtype) { diff -r 0b470386f5f7 -r 4296ff899d02 src/hotspot/share/memory/metaspace.hpp --- a/src/hotspot/share/memory/metaspace.hpp Tue Jul 09 09:20:04 2019 +0200 +++ b/src/hotspot/share/memory/metaspace.hpp Tue Jul 09 10:15:05 2019 +0200 @@ -468,8 +468,9 @@ // The amount to increase the high-water-mark (_capacity_until_GC) static size_t delta_capacity_until_GC(size_t bytes); - // Tells if we have can expand metaspace without hitting set limits. - static bool can_expand(size_t words, bool is_class); + // Returns true if we can commit more memory for the Metaspace without + // hitting MaxMetaspaceSize. + static bool can_expand(size_t words); // Returns amount that we can expand without hitting a GC, // measured in words. diff -r 0b470386f5f7 -r 4296ff899d02 src/hotspot/share/memory/metaspace/virtualSpaceList.cpp --- a/src/hotspot/share/memory/metaspace/virtualSpaceList.cpp Tue Jul 09 09:20:04 2019 +0200 +++ b/src/hotspot/share/memory/metaspace/virtualSpaceList.cpp Tue Jul 09 10:15:05 2019 +0200 @@ -285,7 +285,7 @@ const char* const class_or_not = (is_class() ? "class" : "non-class"); - if (!MetaspaceGC::can_expand(min_words, this->is_class())) { + if (!MetaspaceGC::can_expand(min_words)) { log_trace(gc, metaspace, freelist)("Cannot expand %s virtual space list.", class_or_not); return false; @@ -309,6 +309,14 @@ class_or_not); return true; } + + if (is_class()) { + // In Compressed Class Space we are done here since we cannot create new nodes. + log_trace(gc, metaspace, freelist)("%s virtual space list: Class space exhausted.", + class_or_not); + return false; + } + log_trace(gc, metaspace, freelist)("%s virtual space list: retire current node.", class_or_not); retire_current_virtual_space(); diff -r 0b470386f5f7 -r 4296ff899d02 src/hotspot/share/memory/metaspace/virtualSpaceNode.cpp --- a/src/hotspot/share/memory/metaspace/virtualSpaceNode.cpp Tue Jul 09 09:20:04 2019 +0200 +++ b/src/hotspot/share/memory/metaspace/virtualSpaceNode.cpp Tue Jul 09 10:15:05 2019 +0200 @@ -46,8 +46,7 @@ static bool should_commit_large_pages_when_reserving(size_t bytes) { if (UseLargePages && UseLargePagesInMetaspace && !os::can_commit_large_page_memory()) { size_t words = bytes / BytesPerWord; - bool is_class = false; // We never reserve large pages for the class space. - if (MetaspaceGC::can_expand(words, is_class) && + if (MetaspaceGC::can_expand(words) && MetaspaceGC::allowed_expansion() >= words) { return true; }