src/share/vm/memory/metaspace.cpp

Print this page




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("  "
1473                   "   used_after_gc       : %6.1fKB",
1474                   used_after_gc / (double) K);
1475   }
1476 
1477 
1478   size_t shrink_bytes = 0;
1479   if (capacity_until_GC < minimum_desired_capacity) {
1480     // If we have less capacity below the metaspace HWM, then
1481     // increment the HWM.
1482     size_t expand_bytes = minimum_desired_capacity - capacity_until_GC;
1483     expand_bytes = align_size_up(expand_bytes, Metaspace::commit_alignment());


1499                       new_capacity_until_GC / (double) K);
1500       }
1501     }
1502     return;
1503   }
1504 
1505   // No expansion, now see if we want to shrink
1506   // We would never want to shrink more than this
1507   assert(capacity_until_GC >= minimum_desired_capacity,
1508          err_msg(SIZE_FORMAT " >= " SIZE_FORMAT,
1509                  capacity_until_GC, minimum_desired_capacity));
1510   size_t max_shrink_bytes = capacity_until_GC - minimum_desired_capacity;
1511 
1512   // Should shrinking be considered?
1513   if (MaxMetaspaceFreeRatio < 100) {
1514     const double maximum_free_percentage = MaxMetaspaceFreeRatio / 100.0;
1515     const double minimum_used_percentage = 1.0 - maximum_free_percentage;
1516     const double max_tmp = used_after_gc / minimum_used_percentage;
1517     size_t maximum_desired_capacity = (size_t)MIN2(max_tmp, double(max_uintx));
1518     maximum_desired_capacity = MAX2(maximum_desired_capacity,
1519                                     MetaspaceSize);
1520     if (PrintGCDetails && Verbose) {
1521       gclog_or_tty->print_cr("  "
1522                              "  maximum_free_percentage: %6.2f"
1523                              "  minimum_used_percentage: %6.2f",
1524                              maximum_free_percentage,
1525                              minimum_used_percentage);
1526       gclog_or_tty->print_cr("  "
1527                              "  minimum_desired_capacity: %6.1fKB"
1528                              "  maximum_desired_capacity: %6.1fKB",
1529                              minimum_desired_capacity / (double) K,
1530                              maximum_desired_capacity / (double) K);
1531     }
1532 
1533     assert(minimum_desired_capacity <= maximum_desired_capacity,
1534            "sanity check");
1535 
1536     if (capacity_until_GC > maximum_desired_capacity) {
1537       // Capacity too large, compute shrinking size
1538       shrink_bytes = capacity_until_GC - maximum_desired_capacity;
1539       // We don't want shrink all the way back to initSize if people call


3162     // If UseCompressedClassPointers is set then allocate the metaspace area
3163     // above the heap and above the CDS area (if it exists).
3164     if (using_class_space()) {
3165       if (UseSharedSpaces) {
3166         char* cds_end = (char*)(cds_address + cds_total);
3167         cds_end = (char *)align_ptr_up(cds_end, _reserve_alignment);
3168         allocate_metaspace_compressed_klass_ptrs(cds_end, cds_address);
3169       } else {
3170         char* base = (char*)align_ptr_up(Universe::heap()->reserved_region().end(), _reserve_alignment);
3171         allocate_metaspace_compressed_klass_ptrs(base, 0);
3172       }
3173     }
3174 #endif
3175 
3176     // Initialize these before initializing the VirtualSpaceList
3177     _first_chunk_word_size = InitialBootClassLoaderMetaspaceSize / BytesPerWord;
3178     _first_chunk_word_size = align_word_size_up(_first_chunk_word_size);
3179     // Make the first class chunk bigger than a medium chunk so it's not put
3180     // on the medium chunk list.   The next chunk will be small and progress
3181     // from there.  This size calculated by -version.
3182     _first_class_chunk_word_size = MIN2((size_t)MediumChunk*6,
3183                                        (CompressedClassSpaceSize/BytesPerWord)*2);
3184     _first_class_chunk_word_size = align_word_size_up(_first_class_chunk_word_size);
3185     // Arbitrarily set the initial virtual space to a multiple
3186     // of the boot class loader size.
3187     size_t word_size = VIRTUALSPACEMULTIPLIER * _first_chunk_word_size;
3188     word_size = align_size_up(word_size, Metaspace::reserve_alignment_words());
3189 
3190     // Initialize the list of virtual spaces.
3191     _space_list = new VirtualSpaceList(word_size);
3192     _chunk_manager_metadata = new ChunkManager(SpecializedChunk, SmallChunk, MediumChunk);
3193 
3194     if (!_space_list->initialization_succeeded()) {
3195       vm_exit_during_initialization("Unable to setup metadata virtual space list.", NULL);
3196     }
3197   }
3198 
3199   MetaspaceGC::initialize();
3200   _tracer = new MetaspaceTracer();
3201 }
3202 




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                                   (size_t)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("  "
1473                   "   used_after_gc       : %6.1fKB",
1474                   used_after_gc / (double) K);
1475   }
1476 
1477 
1478   size_t shrink_bytes = 0;
1479   if (capacity_until_GC < minimum_desired_capacity) {
1480     // If we have less capacity below the metaspace HWM, then
1481     // increment the HWM.
1482     size_t expand_bytes = minimum_desired_capacity - capacity_until_GC;
1483     expand_bytes = align_size_up(expand_bytes, Metaspace::commit_alignment());


1499                       new_capacity_until_GC / (double) K);
1500       }
1501     }
1502     return;
1503   }
1504 
1505   // No expansion, now see if we want to shrink
1506   // We would never want to shrink more than this
1507   assert(capacity_until_GC >= minimum_desired_capacity,
1508          err_msg(SIZE_FORMAT " >= " SIZE_FORMAT,
1509                  capacity_until_GC, minimum_desired_capacity));
1510   size_t max_shrink_bytes = capacity_until_GC - minimum_desired_capacity;
1511 
1512   // Should shrinking be considered?
1513   if (MaxMetaspaceFreeRatio < 100) {
1514     const double maximum_free_percentage = MaxMetaspaceFreeRatio / 100.0;
1515     const double minimum_used_percentage = 1.0 - maximum_free_percentage;
1516     const double max_tmp = used_after_gc / minimum_used_percentage;
1517     size_t maximum_desired_capacity = (size_t)MIN2(max_tmp, double(max_uintx));
1518     maximum_desired_capacity = MAX2(maximum_desired_capacity,
1519                                     (size_t)MetaspaceSize);
1520     if (PrintGCDetails && Verbose) {
1521       gclog_or_tty->print_cr("  "
1522                              "  maximum_free_percentage: %6.2f"
1523                              "  minimum_used_percentage: %6.2f",
1524                              maximum_free_percentage,
1525                              minimum_used_percentage);
1526       gclog_or_tty->print_cr("  "
1527                              "  minimum_desired_capacity: %6.1fKB"
1528                              "  maximum_desired_capacity: %6.1fKB",
1529                              minimum_desired_capacity / (double) K,
1530                              maximum_desired_capacity / (double) K);
1531     }
1532 
1533     assert(minimum_desired_capacity <= maximum_desired_capacity,
1534            "sanity check");
1535 
1536     if (capacity_until_GC > maximum_desired_capacity) {
1537       // Capacity too large, compute shrinking size
1538       shrink_bytes = capacity_until_GC - maximum_desired_capacity;
1539       // We don't want shrink all the way back to initSize if people call


3162     // If UseCompressedClassPointers is set then allocate the metaspace area
3163     // above the heap and above the CDS area (if it exists).
3164     if (using_class_space()) {
3165       if (UseSharedSpaces) {
3166         char* cds_end = (char*)(cds_address + cds_total);
3167         cds_end = (char *)align_ptr_up(cds_end, _reserve_alignment);
3168         allocate_metaspace_compressed_klass_ptrs(cds_end, cds_address);
3169       } else {
3170         char* base = (char*)align_ptr_up(Universe::heap()->reserved_region().end(), _reserve_alignment);
3171         allocate_metaspace_compressed_klass_ptrs(base, 0);
3172       }
3173     }
3174 #endif
3175 
3176     // Initialize these before initializing the VirtualSpaceList
3177     _first_chunk_word_size = InitialBootClassLoaderMetaspaceSize / BytesPerWord;
3178     _first_chunk_word_size = align_word_size_up(_first_chunk_word_size);
3179     // Make the first class chunk bigger than a medium chunk so it's not put
3180     // on the medium chunk list.   The next chunk will be small and progress
3181     // from there.  This size calculated by -version.
3182     _first_class_chunk_word_size = MIN2((uintx)MediumChunk*6,
3183                                        (CompressedClassSpaceSize/BytesPerWord)*2);
3184     _first_class_chunk_word_size = align_word_size_up(_first_class_chunk_word_size);
3185     // Arbitrarily set the initial virtual space to a multiple
3186     // of the boot class loader size.
3187     size_t word_size = VIRTUALSPACEMULTIPLIER * _first_chunk_word_size;
3188     word_size = align_size_up(word_size, Metaspace::reserve_alignment_words());
3189 
3190     // Initialize the list of virtual spaces.
3191     _space_list = new VirtualSpaceList(word_size);
3192     _chunk_manager_metadata = new ChunkManager(SpecializedChunk, SmallChunk, MediumChunk);
3193 
3194     if (!_space_list->initialization_succeeded()) {
3195       vm_exit_during_initialization("Unable to setup metadata virtual space list.", NULL);
3196     }
3197   }
3198 
3199   MetaspaceGC::initialize();
3200   _tracer = new MetaspaceTracer();
3201 }
3202