src/share/vm/memory/metaspace.cpp

changeset 9612
58ffe5f227a6
parent 9301
d47844b56aaf
child 9637
eef07cd490d4
child 9905
6c179587bf5b
equal deleted inserted replaced
9611:63ce4041b7ec 9612:58ffe5f227a6
1 /* 1 /*
2 * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
1420 size_t value = (size_t)OrderAccess::load_ptr_acquire(&_capacity_until_GC); 1420 size_t value = (size_t)OrderAccess::load_ptr_acquire(&_capacity_until_GC);
1421 assert(value >= MetaspaceSize, "Not initialied properly?"); 1421 assert(value >= MetaspaceSize, "Not initialied properly?");
1422 return value; 1422 return value;
1423 } 1423 }
1424 1424
1425 bool MetaspaceGC::inc_capacity_until_GC(size_t v, size_t* new_cap_until_GC, size_t* old_cap_until_GC) { 1425 // Try to increase the _capacity_until_GC limit counter by v bytes.
1426 // Returns true if it succeeded. It may fail if either another thread
1427 // concurrently increased the limit or the new limit would be larger
1428 // than MaxMetaspaceSize.
1429 // On success, optionally returns new and old metaspace capacity in
1430 // new_cap_until_GC and old_cap_until_GC respectively.
1431 // On error, optionally sets can_retry to indicate whether if there is
1432 // actually enough space remaining to satisfy the request.
1433 bool MetaspaceGC::inc_capacity_until_GC(size_t v, size_t* new_cap_until_GC, size_t* old_cap_until_GC, bool* can_retry) {
1426 assert_is_size_aligned(v, Metaspace::commit_alignment()); 1434 assert_is_size_aligned(v, Metaspace::commit_alignment());
1427 1435
1428 size_t capacity_until_GC = (size_t) _capacity_until_GC; 1436 size_t capacity_until_GC = (size_t) _capacity_until_GC;
1429 size_t new_value = capacity_until_GC + v; 1437 size_t new_value = capacity_until_GC + v;
1430 1438
1431 if (new_value < capacity_until_GC) { 1439 if (new_value < capacity_until_GC) {
1432 // The addition wrapped around, set new_value to aligned max value. 1440 // The addition wrapped around, set new_value to aligned max value.
1433 new_value = align_size_down(max_uintx, Metaspace::commit_alignment()); 1441 new_value = align_size_down(max_uintx, Metaspace::commit_alignment());
1442 }
1443
1444 if (new_value > MaxMetaspaceSize) {
1445 if (can_retry != NULL) {
1446 *can_retry = false;
1447 }
1448 return false;
1449 }
1450
1451 if (can_retry != NULL) {
1452 *can_retry = true;
1434 } 1453 }
1435 1454
1436 intptr_t expected = (intptr_t) capacity_until_GC; 1455 intptr_t expected = (intptr_t) capacity_until_GC;
1437 intptr_t actual = Atomic::cmpxchg_ptr((intptr_t) new_value, &_capacity_until_GC, expected); 1456 intptr_t actual = Atomic::cmpxchg_ptr((intptr_t) new_value, &_capacity_until_GC, expected);
1438 1457
1518 const double minimum_free_percentage = MinMetaspaceFreeRatio / 100.0; 1537 const double minimum_free_percentage = MinMetaspaceFreeRatio / 100.0;
1519 const double maximum_used_percentage = 1.0 - minimum_free_percentage; 1538 const double maximum_used_percentage = 1.0 - minimum_free_percentage;
1520 1539
1521 const double min_tmp = used_after_gc / maximum_used_percentage; 1540 const double min_tmp = used_after_gc / maximum_used_percentage;
1522 size_t minimum_desired_capacity = 1541 size_t minimum_desired_capacity =
1523 (size_t)MIN2(min_tmp, double(max_uintx)); 1542 (size_t)MIN2(min_tmp, double(MaxMetaspaceSize));
1524 // Don't shrink less than the initial generation size 1543 // Don't shrink less than the initial generation size
1525 minimum_desired_capacity = MAX2(minimum_desired_capacity, 1544 minimum_desired_capacity = MAX2(minimum_desired_capacity,
1526 MetaspaceSize); 1545 MetaspaceSize);
1527 1546
1528 if (PrintGCDetails && Verbose) { 1547 if (PrintGCDetails && Verbose) {
1577 // Should shrinking be considered? 1596 // Should shrinking be considered?
1578 if (MaxMetaspaceFreeRatio < 100) { 1597 if (MaxMetaspaceFreeRatio < 100) {
1579 const double maximum_free_percentage = MaxMetaspaceFreeRatio / 100.0; 1598 const double maximum_free_percentage = MaxMetaspaceFreeRatio / 100.0;
1580 const double minimum_used_percentage = 1.0 - maximum_free_percentage; 1599 const double minimum_used_percentage = 1.0 - maximum_free_percentage;
1581 const double max_tmp = used_after_gc / minimum_used_percentage; 1600 const double max_tmp = used_after_gc / minimum_used_percentage;
1582 size_t maximum_desired_capacity = (size_t)MIN2(max_tmp, double(max_uintx)); 1601 size_t maximum_desired_capacity = (size_t)MIN2(max_tmp, double(MaxMetaspaceSize));
1583 maximum_desired_capacity = MAX2(maximum_desired_capacity, 1602 maximum_desired_capacity = MAX2(maximum_desired_capacity,
1584 MetaspaceSize); 1603 MetaspaceSize);
1585 if (PrintGCDetails && Verbose) { 1604 if (PrintGCDetails && Verbose) {
1586 gclog_or_tty->print_cr(" " 1605 gclog_or_tty->print_cr(" "
1587 " maximum_free_percentage: %6.2f" 1606 " maximum_free_percentage: %6.2f"
3406 size_t delta_bytes = MetaspaceGC::delta_capacity_until_GC(word_size * BytesPerWord); 3425 size_t delta_bytes = MetaspaceGC::delta_capacity_until_GC(word_size * BytesPerWord);
3407 assert(delta_bytes > 0, "Must be"); 3426 assert(delta_bytes > 0, "Must be");
3408 3427
3409 size_t before = 0; 3428 size_t before = 0;
3410 size_t after = 0; 3429 size_t after = 0;
3430 bool can_retry = true;
3411 MetaWord* res; 3431 MetaWord* res;
3412 bool incremented; 3432 bool incremented;
3413 3433
3414 // Each thread increments the HWM at most once. Even if the thread fails to increment 3434 // Each thread increments the HWM at most once. Even if the thread fails to increment
3415 // the HWM, an allocation is still attempted. This is because another thread must then 3435 // the HWM, an allocation is still attempted. This is because another thread must then
3416 // have incremented the HWM and therefore the allocation might still succeed. 3436 // have incremented the HWM and therefore the allocation might still succeed.
3417 do { 3437 do {
3418 incremented = MetaspaceGC::inc_capacity_until_GC(delta_bytes, &after, &before); 3438 incremented = MetaspaceGC::inc_capacity_until_GC(delta_bytes, &after, &before, &can_retry);
3419 res = allocate(word_size, mdtype); 3439 res = allocate(word_size, mdtype);
3420 } while (!incremented && res == NULL); 3440 } while (!incremented && res == NULL && can_retry);
3421 3441
3422 if (incremented) { 3442 if (incremented) {
3423 tracer()->report_gc_threshold(before, after, 3443 tracer()->report_gc_threshold(before, after,
3424 MetaspaceGCThresholdUpdater::ExpandAndAllocate); 3444 MetaspaceGCThresholdUpdater::ExpandAndAllocate);
3425 if (PrintGCDetails && Verbose) { 3445 if (PrintGCDetails && Verbose) {

mercurial