comparison src/share/vm/memory/metaspace.cpp @ 17979:e204777ac770

8042933: assert(capacity_until_gc >= committed_bytes) failed Reviewed-by: stefank, jmasa
author ehelin
date Fri, 13 Jun 2014 08:44:11 +0200
parents 78bbf4d43a14
children 52b4284cb496 ce8f6bb717c9
comparison
equal deleted inserted replaced
17978:ad51f24671c2 17979:e204777ac770
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
3091 CompressedClassSpaceSize = align_size_down_bounded(CompressedClassSpaceSize, _reserve_alignment); 3102 CompressedClassSpaceSize = align_size_down_bounded(CompressedClassSpaceSize, _reserve_alignment);
3092 set_compressed_class_space_size(CompressedClassSpaceSize); 3103 set_compressed_class_space_size(CompressedClassSpaceSize);
3093 } 3104 }
3094 3105
3095 void Metaspace::global_initialize() { 3106 void Metaspace::global_initialize() {
3107 MetaspaceGC::initialize();
3108
3096 // Initialize the alignment for shared spaces. 3109 // Initialize the alignment for shared spaces.
3097 int max_alignment = os::vm_page_size(); 3110 int max_alignment = os::vm_page_size();
3098 size_t cds_total = 0; 3111 size_t cds_total = 0;
3099 3112
3100 MetaspaceShared::set_max_alignment(max_alignment); 3113 MetaspaceShared::set_max_alignment(max_alignment);
3198 if (!_space_list->initialization_succeeded()) { 3211 if (!_space_list->initialization_succeeded()) {
3199 vm_exit_during_initialization("Unable to setup metadata virtual space list.", NULL); 3212 vm_exit_during_initialization("Unable to setup metadata virtual space list.", NULL);
3200 } 3213 }
3201 } 3214 }
3202 3215
3203 MetaspaceGC::initialize();
3204 _tracer = new MetaspaceTracer(); 3216 _tracer = new MetaspaceTracer();
3217 }
3218
3219 void Metaspace::post_initialize() {
3220 MetaspaceGC::post_initialize();
3205 } 3221 }
3206 3222
3207 Metachunk* Metaspace::get_initialization_chunk(MetadataType mdtype, 3223 Metachunk* Metaspace::get_initialization_chunk(MetadataType mdtype,
3208 size_t chunk_word_size, 3224 size_t chunk_word_size,
3209 size_t chunk_bunch) { 3225 size_t chunk_bunch) {