src/share/vm/memory/metaspace.cpp

Print this page
rev 6450 : 8043639: Backout JDK-8034852: Shrinking of Metaspace high-water-mark causes incorrect OutOfMemoryErrors or back-to-back GCs

*** 1431,1443 **** if (!is_init_completed() || GC_locker::is_active_and_needs_gc()) { return left_until_max / BytesPerWord; } size_t capacity_until_gc = capacity_until_GC(); ! assert(capacity_until_gc >= committed_bytes, ! err_msg("capacity_until_gc: " SIZE_FORMAT " < committed_bytes: " SIZE_FORMAT, ! capacity_until_gc, committed_bytes)); size_t left_until_GC = capacity_until_gc - committed_bytes; size_t left_to_commit = MIN2(left_until_GC, left_until_max); return left_to_commit / BytesPerWord; --- 1431,1444 ---- if (!is_init_completed() || GC_locker::is_active_and_needs_gc()) { return left_until_max / BytesPerWord; } size_t capacity_until_gc = capacity_until_GC(); ! ! if (capacity_until_gc <= committed_bytes) { ! return 0; ! } size_t left_until_GC = capacity_until_gc - committed_bytes; size_t left_to_commit = MIN2(left_until_GC, left_until_max); return left_to_commit / BytesPerWord;
*** 1446,1464 **** void MetaspaceGC::compute_new_size() { assert(_shrink_factor <= 100, "invalid shrink factor"); uint current_shrink_factor = _shrink_factor; _shrink_factor = 0; ! // Using committed_bytes() for used_after_gc is an overestimation, since the ! // chunk free lists are included in committed_bytes() and the memory in an ! // un-fragmented chunk free list is available for future allocations. ! // However, if the chunk free lists becomes fragmented, then the memory may ! // not be available for future allocations and the memory is therefore "in use". ! // Including the chunk free lists in the definition of "in use" is therefore ! // necessary. Not including the chunk free lists can cause capacity_until_GC to ! // shrink below committed_bytes() and this has caused serious bugs in the past. ! const size_t used_after_gc = MetaspaceAux::committed_bytes(); const size_t capacity_until_GC = MetaspaceGC::capacity_until_GC(); const double minimum_free_percentage = MinMetaspaceFreeRatio / 100.0; const double maximum_used_percentage = 1.0 - minimum_free_percentage; --- 1447,1457 ---- void MetaspaceGC::compute_new_size() { assert(_shrink_factor <= 100, "invalid shrink factor"); uint current_shrink_factor = _shrink_factor; _shrink_factor = 0; ! const size_t used_after_gc = MetaspaceAux::capacity_bytes(); const size_t capacity_until_GC = MetaspaceGC::capacity_until_GC(); const double minimum_free_percentage = MinMetaspaceFreeRatio / 100.0; const double maximum_used_percentage = 1.0 - minimum_free_percentage;