< prev index next >

src/hotspot/share/memory/metaspace.cpp

Print this page
rev 50191 : [mq]: 8203262-capacity-until-gc2


2400   } else {
2401     // This allocation is large but the next ones are probably not
2402     // so increase by the minimum.
2403     delta = delta + min_delta;
2404   }
2405 
2406   assert_is_aligned(delta, Metaspace::commit_alignment());
2407 
2408   return delta;
2409 }
2410 
2411 size_t MetaspaceGC::capacity_until_GC() {
2412   size_t value = OrderAccess::load_acquire(&_capacity_until_GC);
2413   assert(value >= MetaspaceSize, "Not initialized properly?");
2414   return value;
2415 }
2416 
2417 bool MetaspaceGC::inc_capacity_until_GC(size_t v, size_t* new_cap_until_GC, size_t* old_cap_until_GC) {
2418   assert_is_aligned(v, Metaspace::commit_alignment());
2419 
2420   size_t capacity_until_GC = _capacity_until_GC;
2421   size_t new_value = capacity_until_GC + v;
2422 
2423   if (new_value < capacity_until_GC) {
2424     // The addition wrapped around, set new_value to aligned max value.
2425     new_value = align_down(max_uintx, Metaspace::commit_alignment());
2426   }
2427 
2428   size_t expected = _capacity_until_GC;
2429   size_t actual = Atomic::cmpxchg(new_value, &_capacity_until_GC, expected);
2430 
2431   if (expected != actual) {
2432     return false;
2433   }
2434 
2435   if (new_cap_until_GC != NULL) {
2436     *new_cap_until_GC = new_value;
2437   }
2438   if (old_cap_until_GC != NULL) {
2439     *old_cap_until_GC = capacity_until_GC;
2440   }
2441   return true;
2442 }
2443 
2444 size_t MetaspaceGC::dec_capacity_until_GC(size_t v) {
2445   assert_is_aligned(v, Metaspace::commit_alignment());
2446 
2447   return Atomic::sub(v, &_capacity_until_GC);
2448 }
2449 
2450 void MetaspaceGC::initialize() {
2451   // Set the high-water mark to MaxMetapaceSize during VM initializaton since
2452   // we can't do a GC during initialization.
2453   _capacity_until_GC = MaxMetaspaceSize;
2454 }
2455 
2456 void MetaspaceGC::post_initialize() {
2457   // Reset the high-water mark once the VM initialization is done.
2458   _capacity_until_GC = MAX2(MetaspaceUtils::committed_bytes(), MetaspaceSize);
2459 }




2400   } else {
2401     // This allocation is large but the next ones are probably not
2402     // so increase by the minimum.
2403     delta = delta + min_delta;
2404   }
2405 
2406   assert_is_aligned(delta, Metaspace::commit_alignment());
2407 
2408   return delta;
2409 }
2410 
2411 size_t MetaspaceGC::capacity_until_GC() {
2412   size_t value = OrderAccess::load_acquire(&_capacity_until_GC);
2413   assert(value >= MetaspaceSize, "Not initialized properly?");
2414   return value;
2415 }
2416 
2417 bool MetaspaceGC::inc_capacity_until_GC(size_t v, size_t* new_cap_until_GC, size_t* old_cap_until_GC) {
2418   assert_is_aligned(v, Metaspace::commit_alignment());
2419 
2420   size_t old_value = _capacity_until_GC;
2421   size_t new_value = old_value + v;
2422 
2423   if (new_value < old_value) {
2424     // The addition wrapped around, set new_value to aligned max value.
2425     new_value = align_down(max_uintx, Metaspace::commit_alignment());
2426   }
2427 
2428   size_t res = Atomic::cmpxchg(new_value, &_capacity_until_GC, old_value);

2429 
2430   if (old_value != res) {
2431     return false;
2432   }
2433 
2434   if (new_cap_until_GC != NULL) {
2435     *new_cap_until_GC = new_value;
2436   }
2437   if (old_cap_until_GC != NULL) {
2438     *old_cap_until_GC = old_value;
2439   }
2440   return true;
2441 }
2442 
2443 size_t MetaspaceGC::dec_capacity_until_GC(size_t v) {
2444   assert_is_aligned(v, Metaspace::commit_alignment());
2445 
2446   return Atomic::sub(v, &_capacity_until_GC);
2447 }
2448 
2449 void MetaspaceGC::initialize() {
2450   // Set the high-water mark to MaxMetapaceSize during VM initializaton since
2451   // we can't do a GC during initialization.
2452   _capacity_until_GC = MaxMetaspaceSize;
2453 }
2454 
2455 void MetaspaceGC::post_initialize() {
2456   // Reset the high-water mark once the VM initialization is done.
2457   _capacity_until_GC = MAX2(MetaspaceUtils::committed_bytes(), MetaspaceSize);
2458 }


< prev index next >