src/share/vm/memory/metaspace.cpp

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

mercurial