src/hotspot/share/memory/metaspace/spaceManager.cpp
changeset 51444 3e5d28e6de32
parent 51334 cc2c79d22508
child 53970 1ad7c590a6e7
equal deleted inserted replaced
51443:cdffba164671 51444:3e5d28e6de32
    72 size_t SpaceManager::get_initial_chunk_size(Metaspace::MetaspaceType type) const {
    72 size_t SpaceManager::get_initial_chunk_size(Metaspace::MetaspaceType type) const {
    73   size_t requested;
    73   size_t requested;
    74 
    74 
    75   if (is_class()) {
    75   if (is_class()) {
    76     switch (type) {
    76     switch (type) {
    77     case Metaspace::BootMetaspaceType:       requested = Metaspace::first_class_chunk_word_size(); break;
    77     case Metaspace::BootMetaspaceType:              requested = Metaspace::first_class_chunk_word_size(); break;
    78     case Metaspace::AnonymousMetaspaceType:  requested = ClassSpecializedChunk; break;
    78     case Metaspace::UnsafeAnonymousMetaspaceType:   requested = ClassSpecializedChunk; break;
    79     case Metaspace::ReflectionMetaspaceType: requested = ClassSpecializedChunk; break;
    79     case Metaspace::ReflectionMetaspaceType:        requested = ClassSpecializedChunk; break;
    80     default:                                 requested = ClassSmallChunk; break;
    80     default:                                        requested = ClassSmallChunk; break;
    81     }
    81     }
    82   } else {
    82   } else {
    83     switch (type) {
    83     switch (type) {
    84     case Metaspace::BootMetaspaceType:       requested = Metaspace::first_chunk_word_size(); break;
    84     case Metaspace::BootMetaspaceType:              requested = Metaspace::first_chunk_word_size(); break;
    85     case Metaspace::AnonymousMetaspaceType:  requested = SpecializedChunk; break;
    85     case Metaspace::UnsafeAnonymousMetaspaceType:   requested = SpecializedChunk; break;
    86     case Metaspace::ReflectionMetaspaceType: requested = SpecializedChunk; break;
    86     case Metaspace::ReflectionMetaspaceType:        requested = SpecializedChunk; break;
    87     default:                                 requested = SmallChunk; break;
    87     default:                                        requested = SmallChunk; break;
    88     }
    88     }
    89   }
    89   }
    90 
    90 
    91   // Adjust to one of the fixed chunk sizes (unless humongous)
    91   // Adjust to one of the fixed chunk sizes (unless humongous)
    92   const size_t adjusted = adjust_initial_chunk_size(requested);
    92   const size_t adjusted = adjust_initial_chunk_size(requested);
   112   // Decide between a small chunk and a medium chunk.  Up to
   112   // Decide between a small chunk and a medium chunk.  Up to
   113   // _small_chunk_limit small chunks can be allocated.
   113   // _small_chunk_limit small chunks can be allocated.
   114   // After that a medium chunk is preferred.
   114   // After that a medium chunk is preferred.
   115   size_t chunk_word_size;
   115   size_t chunk_word_size;
   116 
   116 
   117   // Special case for anonymous metadata space.
   117   // Special case for unsafe anonymous metadata space.
   118   // Anonymous metadata space is usually small, with majority within 1K - 2K range and
   118   // UnsafeAnonymous metadata space is usually small since it is used for
       
   119   // class loader data's whose life cycle is governed by one class such as an
       
   120   // unsafe anonymous class.  The majority within 1K - 2K range and
   119   // rarely about 4K (64-bits JVM).
   121   // rarely about 4K (64-bits JVM).
   120   // Instead of jumping to SmallChunk after initial chunk exhausted, keeping allocation
   122   // Instead of jumping to SmallChunk after initial chunk exhausted, keeping allocation
   121   // from SpecializeChunk up to _anon_or_delegating_metadata_specialize_chunk_limit (4)
   123   // from SpecializeChunk up to _anon_or_delegating_metadata_specialize_chunk_limit (4)
   122   // reduces space waste from 60+% to around 30%.
   124   // reduces space waste from 60+% to around 30%.
   123   if ((_space_type == Metaspace::AnonymousMetaspaceType || _space_type == Metaspace::ReflectionMetaspaceType) &&
   125   if ((_space_type == Metaspace::UnsafeAnonymousMetaspaceType || _space_type == Metaspace::ReflectionMetaspaceType) &&
   124       _mdtype == Metaspace::NonClassType &&
   126       _mdtype == Metaspace::NonClassType &&
   125       num_chunks_by_type(SpecializedIndex) < anon_and_delegating_metadata_specialize_chunk_limit &&
   127       num_chunks_by_type(SpecializedIndex) < anon_and_delegating_metadata_specialize_chunk_limit &&
   126       word_size + Metachunk::overhead() <= SpecializedChunk) {
   128       word_size + Metachunk::overhead() <= SpecializedChunk) {
   127     return SpecializedChunk;
   129     return SpecializedChunk;
   128   }
   130   }