src/hotspot/share/memory/metaspace.cpp
changeset 47634 6a0c42c40cd1
parent 47599 0fb1d501c408
child 47654 dbd1f4f276ba
equal deleted inserted replaced
47633:1c21c60f51bf 47634:6a0c42c40cd1
  1497 
  1497 
  1498   return delta;
  1498   return delta;
  1499 }
  1499 }
  1500 
  1500 
  1501 size_t MetaspaceGC::capacity_until_GC() {
  1501 size_t MetaspaceGC::capacity_until_GC() {
  1502   size_t value = (size_t)OrderAccess::load_ptr_acquire(&_capacity_until_GC);
  1502   size_t value = OrderAccess::load_acquire(&_capacity_until_GC);
  1503   assert(value >= MetaspaceSize, "Not initialized properly?");
  1503   assert(value >= MetaspaceSize, "Not initialized properly?");
  1504   return value;
  1504   return value;
  1505 }
  1505 }
  1506 
  1506 
  1507 bool MetaspaceGC::inc_capacity_until_GC(size_t v, size_t* new_cap_until_GC, size_t* old_cap_until_GC) {
  1507 bool MetaspaceGC::inc_capacity_until_GC(size_t v, size_t* new_cap_until_GC, size_t* old_cap_until_GC) {
  1508   assert_is_aligned(v, Metaspace::commit_alignment());
  1508   assert_is_aligned(v, Metaspace::commit_alignment());
  1509 
  1509 
  1510   size_t capacity_until_GC = (size_t) _capacity_until_GC;
  1510   intptr_t capacity_until_GC = _capacity_until_GC;
  1511   size_t new_value = capacity_until_GC + v;
  1511   intptr_t new_value = capacity_until_GC + v;
  1512 
  1512 
  1513   if (new_value < capacity_until_GC) {
  1513   if (new_value < capacity_until_GC) {
  1514     // The addition wrapped around, set new_value to aligned max value.
  1514     // The addition wrapped around, set new_value to aligned max value.
  1515     new_value = align_down(max_uintx, Metaspace::commit_alignment());
  1515     new_value = align_down(max_uintx, Metaspace::commit_alignment());
  1516   }
  1516   }
  1517 
  1517 
  1518   intptr_t expected = (intptr_t) capacity_until_GC;
  1518   intptr_t expected = _capacity_until_GC;
  1519   intptr_t actual = Atomic::cmpxchg_ptr((intptr_t) new_value, &_capacity_until_GC, expected);
  1519   intptr_t actual = Atomic::cmpxchg(new_value, &_capacity_until_GC, expected);
  1520 
  1520 
  1521   if (expected != actual) {
  1521   if (expected != actual) {
  1522     return false;
  1522     return false;
  1523   }
  1523   }
  1524 
  1524 
  1532 }
  1532 }
  1533 
  1533 
  1534 size_t MetaspaceGC::dec_capacity_until_GC(size_t v) {
  1534 size_t MetaspaceGC::dec_capacity_until_GC(size_t v) {
  1535   assert_is_aligned(v, Metaspace::commit_alignment());
  1535   assert_is_aligned(v, Metaspace::commit_alignment());
  1536 
  1536 
  1537   return (size_t)Atomic::add_ptr(-(intptr_t)v, &_capacity_until_GC);
  1537   return (size_t)Atomic::sub((intptr_t)v, &_capacity_until_GC);
  1538 }
  1538 }
  1539 
  1539 
  1540 void MetaspaceGC::initialize() {
  1540 void MetaspaceGC::initialize() {
  1541   // Set the high-water mark to MaxMetapaceSize during VM initializaton since
  1541   // Set the high-water mark to MaxMetapaceSize during VM initializaton since
  1542   // we can't do a GC during initialization.
  1542   // we can't do a GC during initialization.
  2396   MetaspaceAux::inc_used(mdtype(), Metachunk::overhead());
  2396   MetaspaceAux::inc_used(mdtype(), Metachunk::overhead());
  2397 }
  2397 }
  2398 
  2398 
  2399 void SpaceManager::inc_used_metrics(size_t words) {
  2399 void SpaceManager::inc_used_metrics(size_t words) {
  2400   // Add to the per SpaceManager total
  2400   // Add to the per SpaceManager total
  2401   Atomic::add_ptr(words, &_allocated_blocks_words);
  2401   Atomic::add(words, &_allocated_blocks_words);
  2402   // Add to the global total
  2402   // Add to the global total
  2403   MetaspaceAux::inc_used(mdtype(), words);
  2403   MetaspaceAux::inc_used(mdtype(), words);
  2404 }
  2404 }
  2405 
  2405 
  2406 void SpaceManager::dec_total_from_size_metrics() {
  2406 void SpaceManager::dec_total_from_size_metrics() {
  2751          words, mdtype, used_words(mdtype));
  2751          words, mdtype, used_words(mdtype));
  2752   // For CMS deallocation of the Metaspaces occurs during the
  2752   // For CMS deallocation of the Metaspaces occurs during the
  2753   // sweep which is a concurrent phase.  Protection by the expand_lock()
  2753   // sweep which is a concurrent phase.  Protection by the expand_lock()
  2754   // is not enough since allocation is on a per Metaspace basis
  2754   // is not enough since allocation is on a per Metaspace basis
  2755   // and protected by the Metaspace lock.
  2755   // and protected by the Metaspace lock.
  2756   jlong minus_words = (jlong) - (jlong) words;
  2756   Atomic::sub(words, &_used_words[mdtype]);
  2757   Atomic::add_ptr(minus_words, &_used_words[mdtype]);
       
  2758 }
  2757 }
  2759 
  2758 
  2760 void MetaspaceAux::inc_used(Metaspace::MetadataType mdtype, size_t words) {
  2759 void MetaspaceAux::inc_used(Metaspace::MetadataType mdtype, size_t words) {
  2761   // _used_words tracks allocations for
  2760   // _used_words tracks allocations for
  2762   // each piece of metadata.  Those allocations are
  2761   // each piece of metadata.  Those allocations are
  2763   // generally done concurrently by different application
  2762   // generally done concurrently by different application
  2764   // threads so must be done atomically.
  2763   // threads so must be done atomically.
  2765   Atomic::add_ptr(words, &_used_words[mdtype]);
  2764   Atomic::add(words, &_used_words[mdtype]);
  2766 }
  2765 }
  2767 
  2766 
  2768 size_t MetaspaceAux::used_bytes_slow(Metaspace::MetadataType mdtype) {
  2767 size_t MetaspaceAux::used_bytes_slow(Metaspace::MetadataType mdtype) {
  2769   size_t used = 0;
  2768   size_t used = 0;
  2770   ClassLoaderDataGraphMetaspaceIterator iter;
  2769   ClassLoaderDataGraphMetaspaceIterator iter;