src/share/vm/memory/metaspace.cpp

Print this page
rev 4168 : 8005602: NPG: classunloading does not happen while CMS GC with -XX:+CMSClassUnloadingEnabled is used
Summary: Call purge() on CLDG after sweep(), reorder purge() call in GenCollectedHeap and enable some additional logging
Reviewed-by:


1292                       _shrink_factor,
1293                       MinMetaspaceExpansion / (double) K);
1294       }
1295     }
1296   }
1297 
1298 
1299   // Don't shrink unless it's significant
1300   if (shrink_words >= MinMetaspaceExpansion) {
1301     VirtualSpaceNode* csp = vsl->current_virtual_space();
1302     size_t available_to_shrink = csp->capacity_words_in_vs() -
1303       csp->used_words_in_vs();
1304     shrink_words = MIN2(shrink_words, available_to_shrink);
1305     csp->shrink_by(shrink_words);
1306     MetaspaceGC::dec_capacity_until_GC(shrink_words);
1307     if (PrintGCDetails && Verbose) {
1308       size_t new_capacity_until_GC = MetaspaceGC::capacity_until_GC_in_bytes();
1309       gclog_or_tty->print_cr("  metaspace HWM: %.1fK", new_capacity_until_GC / (double) K);
1310     }
1311   }
1312   assert(vsl->used_bytes_sum() == used_after_gc &&
1313          used_after_gc <= vsl->capacity_bytes_sum(),
1314          "sanity check");
1315 
1316 }
1317 
1318 // Metadebug methods
1319 
1320 void Metadebug::deallocate_chunk_a_lot(SpaceManager* sm,
1321                                        size_t chunk_word_size){
1322 #ifdef ASSERT
1323   VirtualSpaceList* vsl = sm->vs_list();
1324   if (MetaDataDeallocateALot &&
1325       Metadebug::deallocate_chunk_a_lot_count() % MetaDataDeallocateALotInterval == 0 ) {
1326     Metadebug::reset_deallocate_chunk_a_lot_count();
1327     for (uint i = 0; i < metadata_deallocate_a_lock_chunk; i++) {
1328       Metachunk* dummy_chunk = vsl->current_virtual_space()->take_from_committed(chunk_word_size);
1329       if (dummy_chunk == NULL) {
1330         break;
1331       }
1332       vsl->chunk_manager()->chunk_freelist_deallocate(dummy_chunk);
1333 


1953                            VirtualSpaceList* vs_list) :
1954   _vs_list(vs_list),
1955   _allocation_total(0),
1956   _lock(lock)
1957 {
1958   initialize();
1959 }
1960 
1961 void SpaceManager::initialize() {
1962   Metadebug::init_allocation_fail_alot_count();
1963   for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
1964     _chunks_in_use[i] = NULL;
1965   }
1966   _current_chunk = NULL;
1967   if (TraceMetadataChunkAllocation && Verbose) {
1968     gclog_or_tty->print_cr("SpaceManager(): " PTR_FORMAT, this);
1969   }
1970 }
1971 
1972 SpaceManager::~SpaceManager() {

1973   MutexLockerEx fcl(SpaceManager::expand_lock(),
1974                     Mutex::_no_safepoint_check_flag);
1975 
1976   ChunkManager* chunk_manager = vs_list()->chunk_manager();
1977 
1978   chunk_manager->slow_locked_verify();
1979 
1980   if (TraceMetadataChunkAllocation && Verbose) {
1981     gclog_or_tty->print_cr("~SpaceManager(): " PTR_FORMAT, this);
1982     locked_print_chunks_in_use_on(gclog_or_tty);
1983   }
1984 
1985   // Mangle freed memory.
1986   NOT_PRODUCT(mangle_freed_chunks();)
1987 
1988   // Have to update before the chunks_in_use lists are emptied
1989   // below.
1990   chunk_manager->inc_free_chunks_total(sum_capacity_in_chunks_in_use(),
1991                                        sum_count_in_chunks_in_use());
1992 
1993   // Add all the chunks in use by this space manager
1994   // to the global list of free chunks.
1995 
1996   // Follow each list of chunks-in-use and add them to the
1997   // free lists.  Each list is NULL terminated.
1998 
1999   for (ChunkIndex i = ZeroIndex; i < HumongousIndex; i = next_chunk_index(i)) {
2000     if (TraceMetadataChunkAllocation && Verbose) {
2001       gclog_or_tty->print_cr("returned %d %s chunks to freelist",
2002                              sum_count_in_chunks_in_use(i),
2003                              chunk_size_name(i));
2004     }
2005     Metachunk* chunks = chunks_in_use(i);
2006     chunk_manager->free_chunks(i)->add_at_head(chunks);
2007     set_chunks_in_use(i, NULL);
2008     if (TraceMetadataChunkAllocation && Verbose) {
2009       gclog_or_tty->print_cr("updated freelist count %d %s",
2010                              chunk_manager->free_chunks(i)->sum_list_count(),




1292                       _shrink_factor,
1293                       MinMetaspaceExpansion / (double) K);
1294       }
1295     }
1296   }
1297 
1298 
1299   // Don't shrink unless it's significant
1300   if (shrink_words >= MinMetaspaceExpansion) {
1301     VirtualSpaceNode* csp = vsl->current_virtual_space();
1302     size_t available_to_shrink = csp->capacity_words_in_vs() -
1303       csp->used_words_in_vs();
1304     shrink_words = MIN2(shrink_words, available_to_shrink);
1305     csp->shrink_by(shrink_words);
1306     MetaspaceGC::dec_capacity_until_GC(shrink_words);
1307     if (PrintGCDetails && Verbose) {
1308       size_t new_capacity_until_GC = MetaspaceGC::capacity_until_GC_in_bytes();
1309       gclog_or_tty->print_cr("  metaspace HWM: %.1fK", new_capacity_until_GC / (double) K);
1310     }
1311   }
1312   assert(used_after_gc <= vsl->capacity_bytes_sum(),

1313          "sanity check");
1314 
1315 }
1316 
1317 // Metadebug methods
1318 
1319 void Metadebug::deallocate_chunk_a_lot(SpaceManager* sm,
1320                                        size_t chunk_word_size){
1321 #ifdef ASSERT
1322   VirtualSpaceList* vsl = sm->vs_list();
1323   if (MetaDataDeallocateALot &&
1324       Metadebug::deallocate_chunk_a_lot_count() % MetaDataDeallocateALotInterval == 0 ) {
1325     Metadebug::reset_deallocate_chunk_a_lot_count();
1326     for (uint i = 0; i < metadata_deallocate_a_lock_chunk; i++) {
1327       Metachunk* dummy_chunk = vsl->current_virtual_space()->take_from_committed(chunk_word_size);
1328       if (dummy_chunk == NULL) {
1329         break;
1330       }
1331       vsl->chunk_manager()->chunk_freelist_deallocate(dummy_chunk);
1332 


1952                            VirtualSpaceList* vs_list) :
1953   _vs_list(vs_list),
1954   _allocation_total(0),
1955   _lock(lock)
1956 {
1957   initialize();
1958 }
1959 
1960 void SpaceManager::initialize() {
1961   Metadebug::init_allocation_fail_alot_count();
1962   for (ChunkIndex i = ZeroIndex; i < NumberOfInUseLists; i = next_chunk_index(i)) {
1963     _chunks_in_use[i] = NULL;
1964   }
1965   _current_chunk = NULL;
1966   if (TraceMetadataChunkAllocation && Verbose) {
1967     gclog_or_tty->print_cr("SpaceManager(): " PTR_FORMAT, this);
1968   }
1969 }
1970 
1971 SpaceManager::~SpaceManager() {
1972   const size_t in_use_before = sum_capacity_in_chunks_in_use();
1973   MutexLockerEx fcl(SpaceManager::expand_lock(),
1974                     Mutex::_no_safepoint_check_flag);
1975 
1976   ChunkManager* chunk_manager = vs_list()->chunk_manager();
1977 
1978   chunk_manager->slow_locked_verify();
1979 
1980   if (TraceMetadataChunkAllocation && Verbose) {
1981     gclog_or_tty->print_cr("~SpaceManager(): " PTR_FORMAT, this);
1982     locked_print_chunks_in_use_on(gclog_or_tty);
1983   }
1984 
1985   // Mangle freed memory.
1986   NOT_PRODUCT(mangle_freed_chunks();)
1987 
1988   // Have to update before the chunks_in_use lists are emptied
1989   // below.
1990   chunk_manager->inc_free_chunks_total(in_use_before,
1991                                        sum_count_in_chunks_in_use());
1992 
1993   // Add all the chunks in use by this space manager
1994   // to the global list of free chunks.
1995 
1996   // Follow each list of chunks-in-use and add them to the
1997   // free lists.  Each list is NULL terminated.
1998 
1999   for (ChunkIndex i = ZeroIndex; i < HumongousIndex; i = next_chunk_index(i)) {
2000     if (TraceMetadataChunkAllocation && Verbose) {
2001       gclog_or_tty->print_cr("returned %d %s chunks to freelist",
2002                              sum_count_in_chunks_in_use(i),
2003                              chunk_size_name(i));
2004     }
2005     Metachunk* chunks = chunks_in_use(i);
2006     chunk_manager->free_chunks(i)->add_at_head(chunks);
2007     set_chunks_in_use(i, NULL);
2008     if (TraceMetadataChunkAllocation && Verbose) {
2009       gclog_or_tty->print_cr("updated freelist count %d %s",
2010                              chunk_manager->free_chunks(i)->sum_list_count(),