hotspot/src/share/vm/memory/metaspace.cpp
changeset 14588 8ec26d2d9339
parent 14474 4154f1817a75
child 14590 7d6b69f12b36
equal deleted inserted replaced
14584:bd4290e6d0a5 14588:8ec26d2d9339
   106     Chunk::aligned_overhead_size(sizeof(Metablock)) / BytesPerWord;
   106     Chunk::aligned_overhead_size(sizeof(Metablock)) / BytesPerWord;
   107 #else
   107 #else
   108   size_t Metablock::_overhead = 0;
   108   size_t Metablock::_overhead = 0;
   109 #endif
   109 #endif
   110 
   110 
   111 
       
   112 // Pointer to list of Metachunks.
   111 // Pointer to list of Metachunks.
   113 class ChunkList VALUE_OBJ_CLASS_SPEC {
   112 class ChunkList VALUE_OBJ_CLASS_SPEC {
   114   // List of free chunks
   113   // List of free chunks
   115   Metachunk* _head;
   114   Metachunk* _head;
   116 
   115 
   323   // Expands/shrinks the committed space in a virtual space.  Delegates
   322   // Expands/shrinks the committed space in a virtual space.  Delegates
   324   // to Virtualspace
   323   // to Virtualspace
   325   bool expand_by(size_t words, bool pre_touch = false);
   324   bool expand_by(size_t words, bool pre_touch = false);
   326   bool shrink_by(size_t words);
   325   bool shrink_by(size_t words);
   327 
   326 
       
   327 #ifdef ASSERT
   328   // Debug support
   328   // Debug support
   329   static void verify_virtual_space_total();
   329   static void verify_virtual_space_total();
   330   static void verify_virtual_space_count();
   330   static void verify_virtual_space_count();
   331   void mangle();
   331   void mangle();
       
   332 #endif
   332 
   333 
   333   void print_on(outputStream* st) const;
   334   void print_on(outputStream* st) const;
   334 };
   335 };
   335 
   336 
   336   // byte_size is the size of the associated virtualspace.
   337   // byte_size is the size of the associated virtualspace.
   619   void dump(outputStream* const out) const;
   620   void dump(outputStream* const out) const;
   620   void print_on(outputStream* st) const;
   621   void print_on(outputStream* st) const;
   621   void locked_print_chunks_in_use_on(outputStream* st) const;
   622   void locked_print_chunks_in_use_on(outputStream* st) const;
   622 
   623 
   623   void verify();
   624   void verify();
       
   625   NOT_PRODUCT(void mangle_freed_chunks();)
   624 #ifdef ASSERT
   626 #ifdef ASSERT
   625   void mangle_freed_chunks();
       
   626   void verify_allocation_total();
   627   void verify_allocation_total();
   627 #endif
   628 #endif
   628 };
   629 };
   629 
   630 
   630 uint const SpaceManager::_small_chunk_limit = 4;
   631 uint const SpaceManager::_small_chunk_limit = 4;
   709                " bottom " PTR_FORMAT " top " PTR_FORMAT
   710                " bottom " PTR_FORMAT " top " PTR_FORMAT
   710                " end " PTR_FORMAT " size " SIZE_FORMAT,
   711                " end " PTR_FORMAT " size " SIZE_FORMAT,
   711                bottom(), top(), end(), word_size());
   712                bottom(), top(), end(), word_size());
   712 }
   713 }
   713 
   714 
   714 #ifdef ASSERT
   715 #ifndef PRODUCT
   715 void Metachunk::mangle() {
   716 void Metachunk::mangle() {
   716   // Mangle the payload of the chunk and not the links that
   717   // Mangle the payload of the chunk and not the links that
   717   // maintain list of chunks.
   718   // maintain list of chunks.
   718   HeapWord* start = (HeapWord*)(bottom() + overhead());
   719   HeapWord* start = (HeapWord*)(bottom() + overhead());
   719   size_t word_size = capacity_word_size() - overhead();
   720   size_t word_size = capacity_word_size() - overhead();
   720   Copy::fill_to_words(start, word_size, metadata_chunk_initialize);
   721   Copy::fill_to_words(start, word_size, metadata_chunk_initialize);
   721 }
   722 }
   722 #endif // ASSERT
   723 #endif // PRODUCT
   723 
   724 
   724 void Metachunk::verify() {
   725 void Metachunk::verify() {
   725 #ifdef ASSERT
   726 #ifdef ASSERT
   726   // Cannot walk through the blocks unless the blocks have
   727   // Cannot walk through the blocks unless the blocks have
   727   // headers with sizes.
   728   // headers with sizes.
   915            vs, capacity / K, used * 100 / capacity,
   916            vs, capacity / K, used * 100 / capacity,
   916            bottom(), top(), end(),
   917            bottom(), top(), end(),
   917            vs->high_boundary());
   918            vs->high_boundary());
   918 }
   919 }
   919 
   920 
       
   921 #ifdef ASSERT
   920 void VirtualSpaceNode::mangle() {
   922 void VirtualSpaceNode::mangle() {
   921   size_t word_size = capacity_words_in_vs();
   923   size_t word_size = capacity_words_in_vs();
   922   Copy::fill_to_words((HeapWord*) low(), word_size, 0xf1f1f1f1);
   924   Copy::fill_to_words((HeapWord*) low(), word_size, 0xf1f1f1f1);
   923 }
   925 }
       
   926 #endif // ASSERT
   924 
   927 
   925 // VirtualSpaceList methods
   928 // VirtualSpaceList methods
   926 // Space allocated from the VirtualSpace
   929 // Space allocated from the VirtualSpace
   927 
   930 
   928 VirtualSpaceList::~VirtualSpaceList() {
   931 VirtualSpaceList::~VirtualSpaceList() {
  1983   if (TraceMetadataChunkAllocation && Verbose) {
  1986   if (TraceMetadataChunkAllocation && Verbose) {
  1984     gclog_or_tty->print_cr("~SpaceManager(): " PTR_FORMAT, this);
  1987     gclog_or_tty->print_cr("~SpaceManager(): " PTR_FORMAT, this);
  1985     locked_print_chunks_in_use_on(gclog_or_tty);
  1988     locked_print_chunks_in_use_on(gclog_or_tty);
  1986   }
  1989   }
  1987 
  1990 
       
  1991   // Mangle freed memory.
       
  1992   NOT_PRODUCT(mangle_freed_chunks();)
       
  1993 
  1988   // Have to update before the chunks_in_use lists are emptied
  1994   // Have to update before the chunks_in_use lists are emptied
  1989   // below.
  1995   // below.
  1990   chunk_manager->inc_free_chunks_total(sum_capacity_in_chunks_in_use(),
  1996   chunk_manager->inc_free_chunks_total(sum_capacity_in_chunks_in_use(),
  1991                                        sum_count_in_chunks_in_use());
  1997                                        sum_count_in_chunks_in_use());
  1992 
       
  1993 #ifdef ASSERT
       
  1994   // Mangle freed memory.
       
  1995   mangle_freed_chunks();
       
  1996 #endif // ASSERT
       
  1997 
  1998 
  1998   // Add all the chunks in use by this space manager
  1999   // Add all the chunks in use by this space manager
  1999   // to the global list of free chunks.
  2000   // to the global list of free chunks.
  2000 
  2001 
  2001   // Small chunks.  There is one _current_chunk for each
  2002   // Small chunks.  There is one _current_chunk for each
  2271   out->print_cr("total of all chunks "  SIZE_FORMAT " used " SIZE_FORMAT
  2272   out->print_cr("total of all chunks "  SIZE_FORMAT " used " SIZE_FORMAT
  2272                 " free " SIZE_FORMAT " capacity " SIZE_FORMAT
  2273                 " free " SIZE_FORMAT " capacity " SIZE_FORMAT
  2273                 " waste " SIZE_FORMAT, curr_total, used, free, capacity, waste);
  2274                 " waste " SIZE_FORMAT, curr_total, used, free, capacity, waste);
  2274 }
  2275 }
  2275 
  2276 
  2276 #ifdef ASSERT
  2277 #ifndef PRODUCT
  2277 void SpaceManager::mangle_freed_chunks() {
  2278 void SpaceManager::mangle_freed_chunks() {
  2278   for (ChunkIndex index = SmallIndex;
  2279   for (ChunkIndex index = SmallIndex;
  2279        index < NumberOfInUseLists;
  2280        index < NumberOfInUseLists;
  2280        index = next_chunk_index(index)) {
  2281        index = next_chunk_index(index)) {
  2281     for (Metachunk* curr = chunks_in_use(index);
  2282     for (Metachunk* curr = chunks_in_use(index);
  2289                      curr, chunks_in_use(MediumIndex)));
  2290                      curr, chunks_in_use(MediumIndex)));
  2290       curr->mangle();
  2291       curr->mangle();
  2291     }
  2292     }
  2292   }
  2293   }
  2293 }
  2294 }
  2294 #endif // ASSERT
  2295 #endif // PRODUCT
  2295 
  2296 
  2296 
  2297 
  2297 // MetaspaceAux
  2298 // MetaspaceAux
       
  2299 
       
  2300 size_t MetaspaceAux::used_in_bytes() {
       
  2301   return (Metaspace::class_space_list()->used_words_sum() +
       
  2302           Metaspace::space_list()->used_words_sum()) * BytesPerWord;
       
  2303 }
  2298 
  2304 
  2299 size_t MetaspaceAux::used_in_bytes(Metaspace::MetadataType mdtype) {
  2305 size_t MetaspaceAux::used_in_bytes(Metaspace::MetadataType mdtype) {
  2300   size_t used = 0;
  2306   size_t used = 0;
  2301   ClassLoaderDataGraphMetaspaceIterator iter;
  2307   ClassLoaderDataGraphMetaspaceIterator iter;
  2302   while (iter.repeat()) {
  2308   while (iter.repeat()) {
  2322 }
  2328 }
  2323 
  2329 
  2324 // The total words available for metadata allocation.  This
  2330 // The total words available for metadata allocation.  This
  2325 // uses Metaspace capacity_words() which is the total words
  2331 // uses Metaspace capacity_words() which is the total words
  2326 // in chunks allocated for a Metaspace.
  2332 // in chunks allocated for a Metaspace.
       
  2333 size_t MetaspaceAux::capacity_in_bytes() {
       
  2334   return (Metaspace::class_space_list()->capacity_words_sum() +
       
  2335           Metaspace::space_list()->capacity_words_sum()) * BytesPerWord;
       
  2336 }
       
  2337 
  2327 size_t MetaspaceAux::capacity_in_bytes(Metaspace::MetadataType mdtype) {
  2338 size_t MetaspaceAux::capacity_in_bytes(Metaspace::MetadataType mdtype) {
  2328   size_t capacity = free_chunks_total(mdtype);
  2339   size_t capacity = free_chunks_total(mdtype);
  2329   ClassLoaderDataGraphMetaspaceIterator iter;
  2340   ClassLoaderDataGraphMetaspaceIterator iter;
  2330   while (iter.repeat()) {
  2341   while (iter.repeat()) {
  2331     Metaspace* msp = iter.get_next();
  2342     Metaspace* msp = iter.get_next();
  2332     if (msp != NULL) {
  2343     if (msp != NULL) {
  2333       capacity += msp->capacity_words(mdtype);
  2344       capacity += msp->capacity_words(mdtype);
  2334     }
  2345     }
  2335   }
  2346   }
  2336   return capacity * BytesPerWord;
  2347   return capacity * BytesPerWord;
       
  2348 }
       
  2349 
       
  2350 size_t MetaspaceAux::reserved_in_bytes() {
       
  2351   return (Metaspace::class_space_list()->virtual_space_total() +
       
  2352           Metaspace::space_list()->virtual_space_total()) * BytesPerWord;
  2337 }
  2353 }
  2338 
  2354 
  2339 size_t MetaspaceAux::reserved_in_bytes(Metaspace::MetadataType mdtype) {
  2355 size_t MetaspaceAux::reserved_in_bytes(Metaspace::MetadataType mdtype) {
  2340   size_t reserved = (mdtype == Metaspace::ClassType) ?
  2356   size_t reserved = (mdtype == Metaspace::ClassType) ?
  2341                        Metaspace::class_space_list()->virtual_space_total() :
  2357                        Metaspace::class_space_list()->virtual_space_total() :