8023476: Metaspace capacity > reserved

Thu, 12 Sep 2013 10:15:30 +0200

author
ehelin
date
Thu, 12 Sep 2013 10:15:30 +0200
changeset 5703
d6c266999345
parent 5702
b82260e84582
child 5704
c4c768305a8f

8023476: Metaspace capacity > reserved
Reviewed-by: stefank, hseigel, mgerdin

src/share/vm/gc_interface/collectedHeap.cpp file | annotate | diff | comparison | revisions
src/share/vm/memory/metaspace.cpp file | annotate | diff | comparison | revisions
src/share/vm/memory/metaspace.hpp file | annotate | diff | comparison | revisions
src/share/vm/memory/metaspaceCounters.cpp file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/gc_interface/collectedHeap.cpp	Wed Sep 11 18:47:54 2013 +0200
     1.2 +++ b/src/share/vm/gc_interface/collectedHeap.cpp	Thu Sep 12 10:15:30 2013 +0200
     1.3 @@ -87,15 +87,15 @@
     1.4    const MetaspaceSizes meta_space(
     1.5        MetaspaceAux::allocated_capacity_bytes(),
     1.6        MetaspaceAux::allocated_used_bytes(),
     1.7 -      MetaspaceAux::reserved_in_bytes());
     1.8 +      MetaspaceAux::reserved_bytes());
     1.9    const MetaspaceSizes data_space(
    1.10        MetaspaceAux::allocated_capacity_bytes(Metaspace::NonClassType),
    1.11        MetaspaceAux::allocated_used_bytes(Metaspace::NonClassType),
    1.12 -      MetaspaceAux::reserved_in_bytes(Metaspace::NonClassType));
    1.13 +      MetaspaceAux::reserved_bytes(Metaspace::NonClassType));
    1.14    const MetaspaceSizes class_space(
    1.15        MetaspaceAux::allocated_capacity_bytes(Metaspace::ClassType),
    1.16        MetaspaceAux::allocated_used_bytes(Metaspace::ClassType),
    1.17 -      MetaspaceAux::reserved_in_bytes(Metaspace::ClassType));
    1.18 +      MetaspaceAux::reserved_bytes(Metaspace::ClassType));
    1.19  
    1.20    return MetaspaceSummary(meta_space, data_space, class_space);
    1.21  }
     2.1 --- a/src/share/vm/memory/metaspace.cpp	Wed Sep 11 18:47:54 2013 +0200
     2.2 +++ b/src/share/vm/memory/metaspace.cpp	Thu Sep 12 10:15:30 2013 +0200
     2.3 @@ -177,8 +177,8 @@
     2.4    void return_chunks(ChunkIndex index, Metachunk* chunks);
     2.5  
     2.6    // Total of the space in the free chunks list
     2.7 -  size_t free_chunks_total();
     2.8 -  size_t free_chunks_total_in_bytes();
     2.9 +  size_t free_chunks_total_words();
    2.10 +  size_t free_chunks_total_bytes();
    2.11  
    2.12    // Number of chunks in the free chunks list
    2.13    size_t free_chunks_count();
    2.14 @@ -1080,12 +1080,12 @@
    2.15      // Sum used region [bottom, top) in each virtualspace
    2.16      allocated_by_vs += vsl->used_words_in_vs();
    2.17    }
    2.18 -  assert(allocated_by_vs >= chunk_manager()->free_chunks_total(),
    2.19 +  assert(allocated_by_vs >= chunk_manager()->free_chunks_total_words(),
    2.20      err_msg("Total in free chunks " SIZE_FORMAT
    2.21              " greater than total from virtual_spaces " SIZE_FORMAT,
    2.22 -            allocated_by_vs, chunk_manager()->free_chunks_total()));
    2.23 +            allocated_by_vs, chunk_manager()->free_chunks_total_words()));
    2.24    size_t used =
    2.25 -    allocated_by_vs - chunk_manager()->free_chunks_total();
    2.26 +    allocated_by_vs - chunk_manager()->free_chunks_total_words();
    2.27    return used;
    2.28  }
    2.29  
    2.30 @@ -1526,7 +1526,7 @@
    2.31                                 sm->sum_count_in_chunks_in_use());
    2.32          dummy_chunk->print_on(gclog_or_tty);
    2.33          gclog_or_tty->print_cr("  Free chunks total %d  count %d",
    2.34 -                               vsl->chunk_manager()->free_chunks_total(),
    2.35 +                               vsl->chunk_manager()->free_chunks_total_words(),
    2.36                                 vsl->chunk_manager()->free_chunks_count());
    2.37        }
    2.38      }
    2.39 @@ -1583,12 +1583,12 @@
    2.40  
    2.41  // ChunkManager methods
    2.42  
    2.43 -size_t ChunkManager::free_chunks_total() {
    2.44 +size_t ChunkManager::free_chunks_total_words() {
    2.45    return _free_chunks_total;
    2.46  }
    2.47  
    2.48 -size_t ChunkManager::free_chunks_total_in_bytes() {
    2.49 -  return free_chunks_total() * BytesPerWord;
    2.50 +size_t ChunkManager::free_chunks_total_bytes() {
    2.51 +  return free_chunks_total_words() * BytesPerWord;
    2.52  }
    2.53  
    2.54  size_t ChunkManager::free_chunks_count() {
    2.55 @@ -2567,13 +2567,13 @@
    2.56    return used * BytesPerWord;
    2.57  }
    2.58  
    2.59 -size_t MetaspaceAux::free_in_bytes(Metaspace::MetadataType mdtype) {
    2.60 +size_t MetaspaceAux::free_bytes_slow(Metaspace::MetadataType mdtype) {
    2.61    size_t free = 0;
    2.62    ClassLoaderDataGraphMetaspaceIterator iter;
    2.63    while (iter.repeat()) {
    2.64      Metaspace* msp = iter.get_next();
    2.65      if (msp != NULL) {
    2.66 -      free += msp->free_words(mdtype);
    2.67 +      free += msp->free_words_slow(mdtype);
    2.68      }
    2.69    }
    2.70    return free * BytesPerWord;
    2.71 @@ -2596,34 +2596,51 @@
    2.72    return capacity * BytesPerWord;
    2.73  }
    2.74  
    2.75 -size_t MetaspaceAux::reserved_in_bytes(Metaspace::MetadataType mdtype) {
    2.76 +size_t MetaspaceAux::capacity_bytes_slow() {
    2.77 +#ifdef PRODUCT
    2.78 +  // Use allocated_capacity_bytes() in PRODUCT instead of this function.
    2.79 +  guarantee(false, "Should not call capacity_bytes_slow() in the PRODUCT");
    2.80 +#endif
    2.81 +  size_t class_capacity = capacity_bytes_slow(Metaspace::ClassType);
    2.82 +  size_t non_class_capacity = capacity_bytes_slow(Metaspace::NonClassType);
    2.83 +  assert(allocated_capacity_bytes() == class_capacity + non_class_capacity,
    2.84 +      err_msg("bad accounting: allocated_capacity_bytes() " SIZE_FORMAT
    2.85 +        " class_capacity + non_class_capacity " SIZE_FORMAT
    2.86 +        " class_capacity " SIZE_FORMAT " non_class_capacity " SIZE_FORMAT,
    2.87 +        allocated_capacity_bytes(), class_capacity + non_class_capacity,
    2.88 +        class_capacity, non_class_capacity));
    2.89 +
    2.90 +  return class_capacity + non_class_capacity;
    2.91 +}
    2.92 +
    2.93 +size_t MetaspaceAux::reserved_bytes(Metaspace::MetadataType mdtype) {
    2.94    VirtualSpaceList* list = Metaspace::get_space_list(mdtype);
    2.95 -  return list == NULL ? 0 : list->virtual_space_total();
    2.96 +  return list == NULL ? 0 : list->virtual_space_total() * BytesPerWord;
    2.97  }
    2.98  
    2.99 -size_t MetaspaceAux::min_chunk_size() { return Metaspace::first_chunk_word_size(); }
   2.100 -
   2.101 -size_t MetaspaceAux::free_chunks_total(Metaspace::MetadataType mdtype) {
   2.102 +size_t MetaspaceAux::min_chunk_size_words() { return Metaspace::first_chunk_word_size(); }
   2.103 +
   2.104 +size_t MetaspaceAux::free_chunks_total_words(Metaspace::MetadataType mdtype) {
   2.105    VirtualSpaceList* list = Metaspace::get_space_list(mdtype);
   2.106    if (list == NULL) {
   2.107      return 0;
   2.108    }
   2.109    ChunkManager* chunk = list->chunk_manager();
   2.110    chunk->slow_verify();
   2.111 -  return chunk->free_chunks_total();
   2.112 +  return chunk->free_chunks_total_words();
   2.113  }
   2.114  
   2.115 -size_t MetaspaceAux::free_chunks_total_in_bytes(Metaspace::MetadataType mdtype) {
   2.116 -  return free_chunks_total(mdtype) * BytesPerWord;
   2.117 +size_t MetaspaceAux::free_chunks_total_bytes(Metaspace::MetadataType mdtype) {
   2.118 +  return free_chunks_total_words(mdtype) * BytesPerWord;
   2.119  }
   2.120  
   2.121 -size_t MetaspaceAux::free_chunks_total() {
   2.122 -  return free_chunks_total(Metaspace::ClassType) +
   2.123 -         free_chunks_total(Metaspace::NonClassType);
   2.124 +size_t MetaspaceAux::free_chunks_total_words() {
   2.125 +  return free_chunks_total_words(Metaspace::ClassType) +
   2.126 +         free_chunks_total_words(Metaspace::NonClassType);
   2.127  }
   2.128  
   2.129 -size_t MetaspaceAux::free_chunks_total_in_bytes() {
   2.130 -  return free_chunks_total() * BytesPerWord;
   2.131 +size_t MetaspaceAux::free_chunks_total_bytes() {
   2.132 +  return free_chunks_total_words() * BytesPerWord;
   2.133  }
   2.134  
   2.135  void MetaspaceAux::print_metaspace_change(size_t prev_metadata_used) {
   2.136 @@ -2634,14 +2651,14 @@
   2.137                          "("  SIZE_FORMAT ")",
   2.138                          prev_metadata_used,
   2.139                          allocated_used_bytes(),
   2.140 -                        reserved_in_bytes());
   2.141 +                        reserved_bytes());
   2.142    } else {
   2.143      gclog_or_tty->print(" "  SIZE_FORMAT "K"
   2.144                          "->" SIZE_FORMAT "K"
   2.145                          "("  SIZE_FORMAT "K)",
   2.146 -                        prev_metadata_used / K,
   2.147 -                        allocated_used_bytes() / K,
   2.148 -                        reserved_in_bytes()/ K);
   2.149 +                        prev_metadata_used/K,
   2.150 +                        allocated_used_bytes()/K,
   2.151 +                        reserved_bytes()/K);
   2.152    }
   2.153  
   2.154    gclog_or_tty->print("]");
   2.155 @@ -2654,14 +2671,14 @@
   2.156    out->print_cr(" Metaspace total "
   2.157                  SIZE_FORMAT "K, used " SIZE_FORMAT "K,"
   2.158                  " reserved " SIZE_FORMAT "K",
   2.159 -                allocated_capacity_bytes()/K, allocated_used_bytes()/K, reserved_in_bytes()/K);
   2.160 +                allocated_capacity_bytes()/K, allocated_used_bytes()/K, reserved_bytes()/K);
   2.161  
   2.162    out->print_cr("  data space     "
   2.163                  SIZE_FORMAT "K, used " SIZE_FORMAT "K,"
   2.164                  " reserved " SIZE_FORMAT "K",
   2.165                  allocated_capacity_bytes(nct)/K,
   2.166                  allocated_used_bytes(nct)/K,
   2.167 -                reserved_in_bytes(nct)/K);
   2.168 +                reserved_bytes(nct)/K);
   2.169    if (Metaspace::using_class_space()) {
   2.170      Metaspace::MetadataType ct = Metaspace::ClassType;
   2.171      out->print_cr("  class space    "
   2.172 @@ -2669,17 +2686,17 @@
   2.173                    " reserved " SIZE_FORMAT "K",
   2.174                    allocated_capacity_bytes(ct)/K,
   2.175                    allocated_used_bytes(ct)/K,
   2.176 -                  reserved_in_bytes(ct)/K);
   2.177 +                  reserved_bytes(ct)/K);
   2.178    }
   2.179  }
   2.180  
   2.181  // Print information for class space and data space separately.
   2.182  // This is almost the same as above.
   2.183  void MetaspaceAux::print_on(outputStream* out, Metaspace::MetadataType mdtype) {
   2.184 -  size_t free_chunks_capacity_bytes = free_chunks_total_in_bytes(mdtype);
   2.185 +  size_t free_chunks_capacity_bytes = free_chunks_total_bytes(mdtype);
   2.186    size_t capacity_bytes = capacity_bytes_slow(mdtype);
   2.187    size_t used_bytes = used_bytes_slow(mdtype);
   2.188 -  size_t free_bytes = free_in_bytes(mdtype);
   2.189 +  size_t free_bytes = free_bytes_slow(mdtype);
   2.190    size_t used_and_free = used_bytes + free_bytes +
   2.191                             free_chunks_capacity_bytes;
   2.192    out->print_cr("  Chunk accounting: used in chunks " SIZE_FORMAT
   2.193 @@ -3132,7 +3149,7 @@
   2.194    }
   2.195  }
   2.196  
   2.197 -size_t Metaspace::free_words(MetadataType mdtype) const {
   2.198 +size_t Metaspace::free_words_slow(MetadataType mdtype) const {
   2.199    if (mdtype == ClassType) {
   2.200      return using_class_space() ? class_vsm()->sum_free_in_chunks_in_use() : 0;
   2.201    } else {
     3.1 --- a/src/share/vm/memory/metaspace.hpp	Wed Sep 11 18:47:54 2013 +0200
     3.2 +++ b/src/share/vm/memory/metaspace.hpp	Thu Sep 12 10:15:30 2013 +0200
     3.3 @@ -182,9 +182,8 @@
     3.4  
     3.5    char*  bottom() const;
     3.6    size_t used_words_slow(MetadataType mdtype) const;
     3.7 -  size_t free_words(MetadataType mdtype) const;
     3.8 +  size_t free_words_slow(MetadataType mdtype) const;
     3.9    size_t capacity_words_slow(MetadataType mdtype) const;
    3.10 -  size_t waste_words(MetadataType mdtype) const;
    3.11  
    3.12    size_t used_bytes_slow(MetadataType mdtype) const;
    3.13    size_t capacity_bytes_slow(MetadataType mdtype) const;
    3.14 @@ -221,19 +220,14 @@
    3.15  };
    3.16  
    3.17  class MetaspaceAux : AllStatic {
    3.18 -  static size_t free_chunks_total(Metaspace::MetadataType mdtype);
    3.19 -
    3.20 - public:
    3.21 -  // Statistics for class space and data space in metaspace.
    3.22 +  static size_t free_chunks_total_words(Metaspace::MetadataType mdtype);
    3.23  
    3.24    // These methods iterate over the classloader data graph
    3.25    // for the given Metaspace type.  These are slow.
    3.26    static size_t used_bytes_slow(Metaspace::MetadataType mdtype);
    3.27 -  static size_t free_in_bytes(Metaspace::MetadataType mdtype);
    3.28 +  static size_t free_bytes_slow(Metaspace::MetadataType mdtype);
    3.29    static size_t capacity_bytes_slow(Metaspace::MetadataType mdtype);
    3.30 -
    3.31 -  // Iterates over the virtual space list.
    3.32 -  static size_t reserved_in_bytes(Metaspace::MetadataType mdtype);
    3.33 +  static size_t capacity_bytes_slow();
    3.34  
    3.35    // Running sum of space in all Metachunks that has been
    3.36    // allocated to a Metaspace.  This is used instead of
    3.37 @@ -263,17 +257,16 @@
    3.38    }
    3.39  
    3.40    // Used by MetaspaceCounters
    3.41 -  static size_t free_chunks_total();
    3.42 -  static size_t free_chunks_total_in_bytes();
    3.43 -  static size_t free_chunks_total_in_bytes(Metaspace::MetadataType mdtype);
    3.44 +  static size_t free_chunks_total_words();
    3.45 +  static size_t free_chunks_total_bytes();
    3.46 +  static size_t free_chunks_total_bytes(Metaspace::MetadataType mdtype);
    3.47  
    3.48    static size_t allocated_capacity_words(Metaspace::MetadataType mdtype) {
    3.49      return _allocated_capacity_words[mdtype];
    3.50    }
    3.51    static size_t allocated_capacity_words() {
    3.52 -    return _allocated_capacity_words[Metaspace::NonClassType] +
    3.53 -           (Metaspace::using_class_space() ?
    3.54 -           _allocated_capacity_words[Metaspace::ClassType] : 0);
    3.55 +    return allocated_capacity_words(Metaspace::NonClassType) +
    3.56 +           allocated_capacity_words(Metaspace::ClassType);
    3.57    }
    3.58    static size_t allocated_capacity_bytes(Metaspace::MetadataType mdtype) {
    3.59      return allocated_capacity_words(mdtype) * BytesPerWord;
    3.60 @@ -286,9 +279,8 @@
    3.61      return _allocated_used_words[mdtype];
    3.62    }
    3.63    static size_t allocated_used_words() {
    3.64 -    return _allocated_used_words[Metaspace::NonClassType] +
    3.65 -           (Metaspace::using_class_space() ?
    3.66 -           _allocated_used_words[Metaspace::ClassType] : 0);
    3.67 +    return allocated_used_words(Metaspace::NonClassType) +
    3.68 +           allocated_used_words(Metaspace::ClassType);
    3.69    }
    3.70    static size_t allocated_used_bytes(Metaspace::MetadataType mdtype) {
    3.71      return allocated_used_words(mdtype) * BytesPerWord;
    3.72 @@ -301,31 +293,17 @@
    3.73    static size_t free_bytes(Metaspace::MetadataType mdtype);
    3.74  
    3.75    // Total capacity in all Metaspaces
    3.76 -  static size_t capacity_bytes_slow() {
    3.77 -#ifdef PRODUCT
    3.78 -    // Use allocated_capacity_bytes() in PRODUCT instead of this function.
    3.79 -    guarantee(false, "Should not call capacity_bytes_slow() in the PRODUCT");
    3.80 -#endif
    3.81 -    size_t class_capacity = capacity_bytes_slow(Metaspace::ClassType);
    3.82 -    size_t non_class_capacity = capacity_bytes_slow(Metaspace::NonClassType);
    3.83 -    assert(allocated_capacity_bytes() == class_capacity + non_class_capacity,
    3.84 -           err_msg("bad accounting: allocated_capacity_bytes() " SIZE_FORMAT
    3.85 -             " class_capacity + non_class_capacity " SIZE_FORMAT
    3.86 -             " class_capacity " SIZE_FORMAT " non_class_capacity " SIZE_FORMAT,
    3.87 -             allocated_capacity_bytes(), class_capacity + non_class_capacity,
    3.88 -             class_capacity, non_class_capacity));
    3.89 -
    3.90 -    return class_capacity + non_class_capacity;
    3.91 +  static size_t reserved_bytes(Metaspace::MetadataType mdtype);
    3.92 +  static size_t reserved_bytes() {
    3.93 +    return reserved_bytes(Metaspace::ClassType) +
    3.94 +           reserved_bytes(Metaspace::NonClassType);
    3.95    }
    3.96  
    3.97 -  // Total space reserved in all Metaspaces
    3.98 -  static size_t reserved_in_bytes() {
    3.99 -    return reserved_in_bytes(Metaspace::ClassType) +
   3.100 -           reserved_in_bytes(Metaspace::NonClassType);
   3.101 +  static size_t min_chunk_size_words();
   3.102 +  static size_t min_chunk_size_bytes() {
   3.103 +    return min_chunk_size_words() * BytesPerWord;
   3.104    }
   3.105  
   3.106 -  static size_t min_chunk_size();
   3.107 -
   3.108    // Print change in used metadata.
   3.109    static void print_metaspace_change(size_t prev_metadata_used);
   3.110    static void print_on(outputStream * out);
     4.1 --- a/src/share/vm/memory/metaspaceCounters.cpp	Wed Sep 11 18:47:54 2013 +0200
     4.2 +++ b/src/share/vm/memory/metaspaceCounters.cpp	Thu Sep 12 10:15:30 2013 +0200
     4.3 @@ -71,7 +71,7 @@
     4.4    //   2) unused space at the end of each Metachunk
     4.5    //   3) space in the freelist
     4.6    size_t total_capacity = MetaspaceAux::allocated_capacity_bytes()
     4.7 -    + MetaspaceAux::free_bytes() + MetaspaceAux::free_chunks_total_in_bytes();
     4.8 +    + MetaspaceAux::free_bytes() + MetaspaceAux::free_chunks_total_bytes();
     4.9    return total_capacity;
    4.10  }
    4.11  
    4.12 @@ -79,9 +79,9 @@
    4.13    if (UsePerfData) {
    4.14      assert(_perf_counters == NULL, "Should only be initialized once");
    4.15  
    4.16 -    size_t min_capacity = MetaspaceAux::min_chunk_size();
    4.17 +    size_t min_capacity = MetaspaceAux::min_chunk_size_bytes();
    4.18      size_t capacity = calculate_capacity();
    4.19 -    size_t max_capacity = MetaspaceAux::reserved_in_bytes();
    4.20 +    size_t max_capacity = MetaspaceAux::reserved_bytes();
    4.21      size_t used = MetaspaceAux::allocated_used_bytes();
    4.22  
    4.23      _perf_counters = new MetaspacePerfCounters("metaspace", min_capacity, capacity, max_capacity, used);
    4.24 @@ -93,7 +93,7 @@
    4.25      assert(_perf_counters != NULL, "Should be initialized");
    4.26  
    4.27      size_t capacity = calculate_capacity();
    4.28 -    size_t max_capacity = MetaspaceAux::reserved_in_bytes();
    4.29 +    size_t max_capacity = MetaspaceAux::reserved_bytes();
    4.30      size_t used = MetaspaceAux::allocated_used_bytes();
    4.31  
    4.32      _perf_counters->update(capacity, max_capacity, used);
    4.33 @@ -105,7 +105,7 @@
    4.34  size_t CompressedClassSpaceCounters::calculate_capacity() {
    4.35      return MetaspaceAux::allocated_capacity_bytes(_class_type) +
    4.36             MetaspaceAux::free_bytes(_class_type) +
    4.37 -           MetaspaceAux::free_chunks_total_in_bytes(_class_type);
    4.38 +           MetaspaceAux::free_chunks_total_bytes(_class_type);
    4.39  }
    4.40  
    4.41  void CompressedClassSpaceCounters::update_performance_counters() {
    4.42 @@ -113,7 +113,7 @@
    4.43      assert(_perf_counters != NULL, "Should be initialized");
    4.44  
    4.45      size_t capacity = calculate_capacity();
    4.46 -    size_t max_capacity = MetaspaceAux::reserved_in_bytes(_class_type);
    4.47 +    size_t max_capacity = MetaspaceAux::reserved_bytes(_class_type);
    4.48      size_t used = MetaspaceAux::allocated_used_bytes(_class_type);
    4.49  
    4.50      _perf_counters->update(capacity, max_capacity, used);
    4.51 @@ -126,9 +126,9 @@
    4.52      const char* ns = "compressedclassspace";
    4.53  
    4.54      if (UseCompressedClassPointers) {
    4.55 -      size_t min_capacity = MetaspaceAux::min_chunk_size();
    4.56 +      size_t min_capacity = MetaspaceAux::min_chunk_size_bytes();
    4.57        size_t capacity = calculate_capacity();
    4.58 -      size_t max_capacity = MetaspaceAux::reserved_in_bytes(_class_type);
    4.59 +      size_t max_capacity = MetaspaceAux::reserved_bytes(_class_type);
    4.60        size_t used = MetaspaceAux::allocated_used_bytes(_class_type);
    4.61  
    4.62        _perf_counters = new MetaspacePerfCounters(ns, min_capacity, capacity, max_capacity, used);

mercurial