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


1416   size_t committed_bytes = MetaspaceAux::committed_bytes();
1417   if (committed_bytes + word_size * BytesPerWord > MaxMetaspaceSize) {
1418     return false;
1419   }
1420 
1421   return true;
1422 }
1423 
1424 size_t MetaspaceGC::allowed_expansion() {
1425   size_t committed_bytes = MetaspaceAux::committed_bytes();
1426 
1427   size_t left_until_max  = MaxMetaspaceSize - committed_bytes;
1428 
1429   // Always grant expansion if we are initiating the JVM,
1430   // or if the GC_locker is preventing GCs.
1431   if (!is_init_completed() || GC_locker::is_active_and_needs_gc()) {
1432     return left_until_max / BytesPerWord;
1433   }
1434 
1435   size_t capacity_until_gc = capacity_until_GC();
1436   assert(capacity_until_gc >= committed_bytes,
1437          err_msg("capacity_until_gc: " SIZE_FORMAT " < committed_bytes: " SIZE_FORMAT,
1438                  capacity_until_gc, committed_bytes));

1439 
1440   size_t left_until_GC = capacity_until_gc - committed_bytes;
1441   size_t left_to_commit = MIN2(left_until_GC, left_until_max);
1442 
1443   return left_to_commit / BytesPerWord;
1444 }
1445 
1446 void MetaspaceGC::compute_new_size() {
1447   assert(_shrink_factor <= 100, "invalid shrink factor");
1448   uint current_shrink_factor = _shrink_factor;
1449   _shrink_factor = 0;
1450 
1451   // Using committed_bytes() for used_after_gc is an overestimation, since the
1452   // chunk free lists are included in committed_bytes() and the memory in an
1453   // un-fragmented chunk free list is available for future allocations.
1454   // However, if the chunk free lists becomes fragmented, then the memory may
1455   // not be available for future allocations and the memory is therefore "in use".
1456   // Including the chunk free lists in the definition of "in use" is therefore
1457   // necessary. Not including the chunk free lists can cause capacity_until_GC to
1458   // shrink below committed_bytes() and this has caused serious bugs in the past.
1459   const size_t used_after_gc = MetaspaceAux::committed_bytes();
1460   const size_t capacity_until_GC = MetaspaceGC::capacity_until_GC();
1461 
1462   const double minimum_free_percentage = MinMetaspaceFreeRatio / 100.0;
1463   const double maximum_used_percentage = 1.0 - minimum_free_percentage;
1464 
1465   const double min_tmp = used_after_gc / maximum_used_percentage;
1466   size_t minimum_desired_capacity =
1467     (size_t)MIN2(min_tmp, double(max_uintx));
1468   // Don't shrink less than the initial generation size
1469   minimum_desired_capacity = MAX2(minimum_desired_capacity,
1470                                   MetaspaceSize);
1471 
1472   if (PrintGCDetails && Verbose) {
1473     gclog_or_tty->print_cr("\nMetaspaceGC::compute_new_size: ");
1474     gclog_or_tty->print_cr("  "
1475                   "  minimum_free_percentage: %6.2f"
1476                   "  maximum_used_percentage: %6.2f",
1477                   minimum_free_percentage,
1478                   maximum_used_percentage);
1479     gclog_or_tty->print_cr("  "




1416   size_t committed_bytes = MetaspaceAux::committed_bytes();
1417   if (committed_bytes + word_size * BytesPerWord > MaxMetaspaceSize) {
1418     return false;
1419   }
1420 
1421   return true;
1422 }
1423 
1424 size_t MetaspaceGC::allowed_expansion() {
1425   size_t committed_bytes = MetaspaceAux::committed_bytes();
1426 
1427   size_t left_until_max  = MaxMetaspaceSize - committed_bytes;
1428 
1429   // Always grant expansion if we are initiating the JVM,
1430   // or if the GC_locker is preventing GCs.
1431   if (!is_init_completed() || GC_locker::is_active_and_needs_gc()) {
1432     return left_until_max / BytesPerWord;
1433   }
1434 
1435   size_t capacity_until_gc = capacity_until_GC();
1436 
1437   if (capacity_until_gc <= committed_bytes) {
1438     return 0;
1439   }
1440 
1441   size_t left_until_GC = capacity_until_gc - committed_bytes;
1442   size_t left_to_commit = MIN2(left_until_GC, left_until_max);
1443 
1444   return left_to_commit / BytesPerWord;
1445 }
1446 
1447 void MetaspaceGC::compute_new_size() {
1448   assert(_shrink_factor <= 100, "invalid shrink factor");
1449   uint current_shrink_factor = _shrink_factor;
1450   _shrink_factor = 0;
1451 
1452   const size_t used_after_gc = MetaspaceAux::capacity_bytes();








1453   const size_t capacity_until_GC = MetaspaceGC::capacity_until_GC();
1454 
1455   const double minimum_free_percentage = MinMetaspaceFreeRatio / 100.0;
1456   const double maximum_used_percentage = 1.0 - minimum_free_percentage;
1457 
1458   const double min_tmp = used_after_gc / maximum_used_percentage;
1459   size_t minimum_desired_capacity =
1460     (size_t)MIN2(min_tmp, double(max_uintx));
1461   // Don't shrink less than the initial generation size
1462   minimum_desired_capacity = MAX2(minimum_desired_capacity,
1463                                   MetaspaceSize);
1464 
1465   if (PrintGCDetails && Verbose) {
1466     gclog_or_tty->print_cr("\nMetaspaceGC::compute_new_size: ");
1467     gclog_or_tty->print_cr("  "
1468                   "  minimum_free_percentage: %6.2f"
1469                   "  maximum_used_percentage: %6.2f",
1470                   minimum_free_percentage,
1471                   maximum_used_percentage);
1472     gclog_or_tty->print_cr("  "