1413 size_t value = (size_t)OrderAccess::load_ptr_acquire(&_capacity_until_GC); |
1413 size_t value = (size_t)OrderAccess::load_ptr_acquire(&_capacity_until_GC); |
1414 assert(value >= MetaspaceSize, "Not initialied properly?"); |
1414 assert(value >= MetaspaceSize, "Not initialied properly?"); |
1415 return value; |
1415 return value; |
1416 } |
1416 } |
1417 |
1417 |
1418 size_t MetaspaceGC::inc_capacity_until_GC(size_t v) { |
1418 bool MetaspaceGC::inc_capacity_until_GC(size_t v, size_t* new_cap_until_GC, size_t* old_cap_until_GC) { |
1419 assert_is_size_aligned(v, Metaspace::commit_alignment()); |
1419 assert_is_size_aligned(v, Metaspace::commit_alignment()); |
1420 |
1420 |
1421 return (size_t)Atomic::add_ptr(v, &_capacity_until_GC); |
1421 size_t capacity_until_GC = (size_t) _capacity_until_GC; |
|
1422 size_t new_value = capacity_until_GC + v; |
|
1423 |
|
1424 if (new_value < capacity_until_GC) { |
|
1425 // The addition wrapped around, set new_value to aligned max value. |
|
1426 new_value = align_size_down(max_uintx, Metaspace::commit_alignment()); |
|
1427 } |
|
1428 |
|
1429 intptr_t expected = (intptr_t) capacity_until_GC; |
|
1430 intptr_t actual = Atomic::cmpxchg_ptr((intptr_t) new_value, &_capacity_until_GC, expected); |
|
1431 |
|
1432 if (expected != actual) { |
|
1433 return false; |
|
1434 } |
|
1435 |
|
1436 if (new_cap_until_GC != NULL) { |
|
1437 *new_cap_until_GC = new_value; |
|
1438 } |
|
1439 if (old_cap_until_GC != NULL) { |
|
1440 *old_cap_until_GC = capacity_until_GC; |
|
1441 } |
|
1442 return true; |
1422 } |
1443 } |
1423 |
1444 |
1424 size_t MetaspaceGC::dec_capacity_until_GC(size_t v) { |
1445 size_t MetaspaceGC::dec_capacity_until_GC(size_t v) { |
1425 assert_is_size_aligned(v, Metaspace::commit_alignment()); |
1446 assert_is_size_aligned(v, Metaspace::commit_alignment()); |
1426 |
1447 |
1516 // increment the HWM. |
1537 // increment the HWM. |
1517 size_t expand_bytes = minimum_desired_capacity - capacity_until_GC; |
1538 size_t expand_bytes = minimum_desired_capacity - capacity_until_GC; |
1518 expand_bytes = align_size_up(expand_bytes, Metaspace::commit_alignment()); |
1539 expand_bytes = align_size_up(expand_bytes, Metaspace::commit_alignment()); |
1519 // Don't expand unless it's significant |
1540 // Don't expand unless it's significant |
1520 if (expand_bytes >= MinMetaspaceExpansion) { |
1541 if (expand_bytes >= MinMetaspaceExpansion) { |
1521 size_t new_capacity_until_GC = MetaspaceGC::inc_capacity_until_GC(expand_bytes); |
1542 size_t new_capacity_until_GC = 0; |
|
1543 bool succeeded = MetaspaceGC::inc_capacity_until_GC(expand_bytes, &new_capacity_until_GC); |
|
1544 assert(succeeded, "Should always succesfully increment HWM when at safepoint"); |
|
1545 |
1522 Metaspace::tracer()->report_gc_threshold(capacity_until_GC, |
1546 Metaspace::tracer()->report_gc_threshold(capacity_until_GC, |
1523 new_capacity_until_GC, |
1547 new_capacity_until_GC, |
1524 MetaspaceGCThresholdUpdater::ComputeNewSize); |
1548 MetaspaceGCThresholdUpdater::ComputeNewSize); |
1525 if (PrintGCDetails && Verbose) { |
1549 if (PrintGCDetails && Verbose) { |
1526 gclog_or_tty->print_cr(" expanding:" |
1550 gclog_or_tty->print_cr(" expanding:" |
3319 |
3343 |
3320 MetaWord* Metaspace::expand_and_allocate(size_t word_size, MetadataType mdtype) { |
3344 MetaWord* Metaspace::expand_and_allocate(size_t word_size, MetadataType mdtype) { |
3321 size_t delta_bytes = MetaspaceGC::delta_capacity_until_GC(word_size * BytesPerWord); |
3345 size_t delta_bytes = MetaspaceGC::delta_capacity_until_GC(word_size * BytesPerWord); |
3322 assert(delta_bytes > 0, "Must be"); |
3346 assert(delta_bytes > 0, "Must be"); |
3323 |
3347 |
3324 size_t after_inc = MetaspaceGC::inc_capacity_until_GC(delta_bytes); |
3348 size_t before = 0; |
3325 |
3349 size_t after = 0; |
3326 // capacity_until_GC might be updated concurrently, must calculate previous value. |
3350 MetaWord* res; |
3327 size_t before_inc = after_inc - delta_bytes; |
3351 bool incremented; |
3328 |
3352 |
3329 tracer()->report_gc_threshold(before_inc, after_inc, |
3353 // Each thread increments the HWM at most once. Even if the thread fails to increment |
3330 MetaspaceGCThresholdUpdater::ExpandAndAllocate); |
3354 // the HWM, an allocation is still attempted. This is because another thread must then |
3331 if (PrintGCDetails && Verbose) { |
3355 // have incremented the HWM and therefore the allocation might still succeed. |
3332 gclog_or_tty->print_cr("Increase capacity to GC from " SIZE_FORMAT |
3356 do { |
3333 " to " SIZE_FORMAT, before_inc, after_inc); |
3357 incremented = MetaspaceGC::inc_capacity_until_GC(delta_bytes, &after, &before); |
3334 } |
3358 res = allocate(word_size, mdtype); |
3335 |
3359 } while (!incremented && res == NULL); |
3336 return allocate(word_size, mdtype); |
3360 |
|
3361 if (incremented) { |
|
3362 tracer()->report_gc_threshold(before, after, |
|
3363 MetaspaceGCThresholdUpdater::ExpandAndAllocate); |
|
3364 if (PrintGCDetails && Verbose) { |
|
3365 gclog_or_tty->print_cr("Increase capacity to GC from " SIZE_FORMAT |
|
3366 " to " SIZE_FORMAT, before, after); |
|
3367 } |
|
3368 } |
|
3369 |
|
3370 return res; |
3337 } |
3371 } |
3338 |
3372 |
3339 // Space allocated in the Metaspace. This may |
3373 // Space allocated in the Metaspace. This may |
3340 // be across several metadata virtual spaces. |
3374 // be across several metadata virtual spaces. |
3341 char* Metaspace::bottom() const { |
3375 char* Metaspace::bottom() const { |