1421 assert_is_size_aligned(v, Metaspace::commit_alignment()); |
1421 assert_is_size_aligned(v, Metaspace::commit_alignment()); |
1422 |
1422 |
1423 return (size_t)Atomic::add_ptr(-(intptr_t)v, &_capacity_until_GC); |
1423 return (size_t)Atomic::add_ptr(-(intptr_t)v, &_capacity_until_GC); |
1424 } |
1424 } |
1425 |
1425 |
|
1426 void MetaspaceGC::initialize() { |
|
1427 // Set the high-water mark to MaxMetapaceSize during VM initializaton since |
|
1428 // we can't do a GC during initialization. |
|
1429 _capacity_until_GC = MaxMetaspaceSize; |
|
1430 } |
|
1431 |
|
1432 void MetaspaceGC::post_initialize() { |
|
1433 // Reset the high-water mark once the VM initialization is done. |
|
1434 _capacity_until_GC = MAX2(MetaspaceAux::committed_bytes(), MetaspaceSize); |
|
1435 } |
|
1436 |
1426 bool MetaspaceGC::can_expand(size_t word_size, bool is_class) { |
1437 bool MetaspaceGC::can_expand(size_t word_size, bool is_class) { |
1427 // Check if the compressed class space is full. |
1438 // Check if the compressed class space is full. |
1428 if (is_class && Metaspace::using_class_space()) { |
1439 if (is_class && Metaspace::using_class_space()) { |
1429 size_t class_committed = MetaspaceAux::committed_bytes(Metaspace::ClassType); |
1440 size_t class_committed = MetaspaceAux::committed_bytes(Metaspace::ClassType); |
1430 if (class_committed + word_size * BytesPerWord > CompressedClassSpaceSize) { |
1441 if (class_committed + word_size * BytesPerWord > CompressedClassSpaceSize) { |
1441 return true; |
1452 return true; |
1442 } |
1453 } |
1443 |
1454 |
1444 size_t MetaspaceGC::allowed_expansion() { |
1455 size_t MetaspaceGC::allowed_expansion() { |
1445 size_t committed_bytes = MetaspaceAux::committed_bytes(); |
1456 size_t committed_bytes = MetaspaceAux::committed_bytes(); |
|
1457 size_t capacity_until_gc = capacity_until_GC(); |
|
1458 |
|
1459 assert(capacity_until_gc >= committed_bytes, |
|
1460 err_msg("capacity_until_gc: " SIZE_FORMAT " < committed_bytes: " SIZE_FORMAT, |
|
1461 capacity_until_gc, committed_bytes)); |
1446 |
1462 |
1447 size_t left_until_max = MaxMetaspaceSize - committed_bytes; |
1463 size_t left_until_max = MaxMetaspaceSize - committed_bytes; |
1448 |
|
1449 // Always grant expansion if we are initiating the JVM, |
|
1450 // or if the GC_locker is preventing GCs. |
|
1451 if (!is_init_completed() || GC_locker::is_active_and_needs_gc()) { |
|
1452 return left_until_max / BytesPerWord; |
|
1453 } |
|
1454 |
|
1455 size_t capacity_until_gc = capacity_until_GC(); |
|
1456 |
|
1457 if (capacity_until_gc <= committed_bytes) { |
|
1458 return 0; |
|
1459 } |
|
1460 |
|
1461 size_t left_until_GC = capacity_until_gc - committed_bytes; |
1464 size_t left_until_GC = capacity_until_gc - committed_bytes; |
1462 size_t left_to_commit = MIN2(left_until_GC, left_until_max); |
1465 size_t left_to_commit = MIN2(left_until_GC, left_until_max); |
1463 |
1466 |
1464 return left_to_commit / BytesPerWord; |
1467 return left_to_commit / BytesPerWord; |
1465 } |
1468 } |
1467 void MetaspaceGC::compute_new_size() { |
1470 void MetaspaceGC::compute_new_size() { |
1468 assert(_shrink_factor <= 100, "invalid shrink factor"); |
1471 assert(_shrink_factor <= 100, "invalid shrink factor"); |
1469 uint current_shrink_factor = _shrink_factor; |
1472 uint current_shrink_factor = _shrink_factor; |
1470 _shrink_factor = 0; |
1473 _shrink_factor = 0; |
1471 |
1474 |
1472 const size_t used_after_gc = MetaspaceAux::capacity_bytes(); |
1475 // Using committed_bytes() for used_after_gc is an overestimation, since the |
|
1476 // chunk free lists are included in committed_bytes() and the memory in an |
|
1477 // un-fragmented chunk free list is available for future allocations. |
|
1478 // However, if the chunk free lists becomes fragmented, then the memory may |
|
1479 // not be available for future allocations and the memory is therefore "in use". |
|
1480 // Including the chunk free lists in the definition of "in use" is therefore |
|
1481 // necessary. Not including the chunk free lists can cause capacity_until_GC to |
|
1482 // shrink below committed_bytes() and this has caused serious bugs in the past. |
|
1483 const size_t used_after_gc = MetaspaceAux::committed_bytes(); |
1473 const size_t capacity_until_GC = MetaspaceGC::capacity_until_GC(); |
1484 const size_t capacity_until_GC = MetaspaceGC::capacity_until_GC(); |
1474 |
1485 |
1475 const double minimum_free_percentage = MinMetaspaceFreeRatio / 100.0; |
1486 const double minimum_free_percentage = MinMetaspaceFreeRatio / 100.0; |
1476 const double maximum_used_percentage = 1.0 - minimum_free_percentage; |
1487 const double maximum_used_percentage = 1.0 - minimum_free_percentage; |
1477 |
1488 |
3092 CompressedClassSpaceSize = align_size_down_bounded(CompressedClassSpaceSize, _reserve_alignment); |
3103 CompressedClassSpaceSize = align_size_down_bounded(CompressedClassSpaceSize, _reserve_alignment); |
3093 set_compressed_class_space_size(CompressedClassSpaceSize); |
3104 set_compressed_class_space_size(CompressedClassSpaceSize); |
3094 } |
3105 } |
3095 |
3106 |
3096 void Metaspace::global_initialize() { |
3107 void Metaspace::global_initialize() { |
|
3108 MetaspaceGC::initialize(); |
|
3109 |
3097 // Initialize the alignment for shared spaces. |
3110 // Initialize the alignment for shared spaces. |
3098 int max_alignment = os::vm_allocation_granularity(); |
3111 int max_alignment = os::vm_allocation_granularity(); |
3099 size_t cds_total = 0; |
3112 size_t cds_total = 0; |
3100 |
3113 |
3101 MetaspaceShared::set_max_alignment(max_alignment); |
3114 MetaspaceShared::set_max_alignment(max_alignment); |
3199 if (!_space_list->initialization_succeeded()) { |
3212 if (!_space_list->initialization_succeeded()) { |
3200 vm_exit_during_initialization("Unable to setup metadata virtual space list.", NULL); |
3213 vm_exit_during_initialization("Unable to setup metadata virtual space list.", NULL); |
3201 } |
3214 } |
3202 } |
3215 } |
3203 |
3216 |
3204 MetaspaceGC::initialize(); |
|
3205 _tracer = new MetaspaceTracer(); |
3217 _tracer = new MetaspaceTracer(); |
|
3218 } |
|
3219 |
|
3220 void Metaspace::post_initialize() { |
|
3221 MetaspaceGC::post_initialize(); |
3206 } |
3222 } |
3207 |
3223 |
3208 Metachunk* Metaspace::get_initialization_chunk(MetadataType mdtype, |
3224 Metachunk* Metaspace::get_initialization_chunk(MetadataType mdtype, |
3209 size_t chunk_word_size, |
3225 size_t chunk_word_size, |
3210 size_t chunk_bunch) { |
3226 size_t chunk_bunch) { |