hotspot/src/share/vm/memory/metaspace.cpp
changeset 37267 ad8c0e8de29f
parent 36829 dd6004c32d75
parent 37242 91e5f98fff6f
child 39229 8bfc00dd44b6
equal deleted inserted replaced
36848:33688f44fb2a 37267:ad8c0e8de29f
   757   void print_on(outputStream* st) const;
   757   void print_on(outputStream* st) const;
   758   void locked_print_chunks_in_use_on(outputStream* st) const;
   758   void locked_print_chunks_in_use_on(outputStream* st) const;
   759 
   759 
   760   void verify();
   760   void verify();
   761   void verify_chunk_size(Metachunk* chunk);
   761   void verify_chunk_size(Metachunk* chunk);
   762   NOT_PRODUCT(void mangle_freed_chunks();)
       
   763 #ifdef ASSERT
   762 #ifdef ASSERT
   764   void verify_allocated_blocks_words();
   763   void verify_allocated_blocks_words();
   765 #endif
   764 #endif
   766 
   765 
   767   size_t get_raw_word_size(size_t word_size) {
   766   size_t get_raw_word_size(size_t word_size) {
   887   // Without this the is_available check will not work correctly.
   886   // Without this the is_available check will not work correctly.
   888   assert(_virtual_space.committed_size() == _virtual_space.actual_committed_size(),
   887   assert(_virtual_space.committed_size() == _virtual_space.actual_committed_size(),
   889       "The committed memory doesn't match the expanded memory.");
   888       "The committed memory doesn't match the expanded memory.");
   890 
   889 
   891   if (!is_available(chunk_word_size)) {
   890   if (!is_available(chunk_word_size)) {
   892     LogHandle(gc, metaspace, freelist) log;
   891     Log(gc, metaspace, freelist) log;
   893     log.debug("VirtualSpaceNode::take_from_committed() not available " SIZE_FORMAT " words ", chunk_word_size);
   892     log.debug("VirtualSpaceNode::take_from_committed() not available " SIZE_FORMAT " words ", chunk_word_size);
   894     // Dump some information about the virtual space that is nearly full
   893     // Dump some information about the virtual space that is nearly full
   895     ResourceMark rm;
   894     ResourceMark rm;
   896     print_on(log.debug_stream());
   895     print_on(log.debug_stream());
   897     return NULL;
   896     return NULL;
  1228   inc_virtual_space_count();
  1227   inc_virtual_space_count();
  1229 #ifdef ASSERT
  1228 #ifdef ASSERT
  1230   new_entry->mangle();
  1229   new_entry->mangle();
  1231 #endif
  1230 #endif
  1232   if (log_is_enabled(Trace, gc, metaspace)) {
  1231   if (log_is_enabled(Trace, gc, metaspace)) {
  1233     LogHandle(gc, metaspace) log;
  1232     Log(gc, metaspace) log;
  1234     VirtualSpaceNode* vsl = current_virtual_space();
  1233     VirtualSpaceNode* vsl = current_virtual_space();
  1235     ResourceMark rm;
  1234     ResourceMark rm;
  1236     vsl->print_on(log.trace_stream());
  1235     vsl->print_on(log.trace_stream());
  1237   }
  1236   }
  1238 }
  1237 }
  1567       if (current_shrink_factor == 0) {
  1566       if (current_shrink_factor == 0) {
  1568         _shrink_factor = 10;
  1567         _shrink_factor = 10;
  1569       } else {
  1568       } else {
  1570         _shrink_factor = MIN2(current_shrink_factor * 4, (uint) 100);
  1569         _shrink_factor = MIN2(current_shrink_factor * 4, (uint) 100);
  1571       }
  1570       }
  1572       log_trace(gc, metaspace)("    shrinking:  initSize: %.1fK  maximum_desired_capacity: %.1fK",
  1571       log_trace(gc, metaspace)("    shrinking:  initThreshold: %.1fK  maximum_desired_capacity: %.1fK",
  1573                                MetaspaceSize / (double) K, maximum_desired_capacity / (double) K);
  1572                                MetaspaceSize / (double) K, maximum_desired_capacity / (double) K);
  1574       log_trace(gc, metaspace)("    shrink_bytes: %.1fK  current_shrink_factor: %d  new shrink factor: %d  MinMetaspaceExpansion: %.1fK",
  1573       log_trace(gc, metaspace)("    shrink_bytes: %.1fK  current_shrink_factor: %d  new shrink factor: %d  MinMetaspaceExpansion: %.1fK",
  1575                                shrink_bytes / (double) K, current_shrink_factor, _shrink_factor, MinMetaspaceExpansion / (double) K);
  1574                                shrink_bytes / (double) K, current_shrink_factor, _shrink_factor, MinMetaspaceExpansion / (double) K);
  1576     }
  1575     }
  1577   }
  1576   }
  1790   }
  1789   }
  1791 
  1790 
  1792   assert((word_size <= chunk->word_size()) ||
  1791   assert((word_size <= chunk->word_size()) ||
  1793          list_index(chunk->word_size() == HumongousIndex),
  1792          list_index(chunk->word_size() == HumongousIndex),
  1794          "Non-humongous variable sized chunk");
  1793          "Non-humongous variable sized chunk");
  1795   LogHandle(gc, metaspace, freelist) log;
  1794   Log(gc, metaspace, freelist) log;
  1796   if (log.is_debug()) {
  1795   if (log.is_debug()) {
  1797     size_t list_count;
  1796     size_t list_count;
  1798     if (list_index(word_size) < HumongousIndex) {
  1797     if (list_index(word_size) < HumongousIndex) {
  1799       ChunkList* list = find_free_chunks_list(word_size);
  1798       ChunkList* list = find_free_chunks_list(word_size);
  1800       list_count = list->count();
  1799       list_count = list->count();
  1989   assert(!SpaceManager::is_humongous(word_size) ||
  1988   assert(!SpaceManager::is_humongous(word_size) ||
  1990          chunk_word_size == if_humongous_sized_chunk,
  1989          chunk_word_size == if_humongous_sized_chunk,
  1991          "Size calculation is wrong, word_size " SIZE_FORMAT
  1990          "Size calculation is wrong, word_size " SIZE_FORMAT
  1992          " chunk_word_size " SIZE_FORMAT,
  1991          " chunk_word_size " SIZE_FORMAT,
  1993          word_size, chunk_word_size);
  1992          word_size, chunk_word_size);
  1994   LogHandle(gc, metaspace, alloc) log;
  1993   Log(gc, metaspace, alloc) log;
  1995   if (log.is_debug() && SpaceManager::is_humongous(word_size)) {
  1994   if (log.is_debug() && SpaceManager::is_humongous(word_size)) {
  1996     log.debug("Metadata humongous allocation:");
  1995     log.debug("Metadata humongous allocation:");
  1997     log.debug("  word_size " PTR_FORMAT, word_size);
  1996     log.debug("  word_size " PTR_FORMAT, word_size);
  1998     log.debug("  chunk_word_size " PTR_FORMAT, chunk_word_size);
  1997     log.debug("  chunk_word_size " PTR_FORMAT, chunk_word_size);
  1999     log.debug("    chunk overhead " PTR_FORMAT, Metachunk::overhead());
  1998     log.debug("    chunk overhead " PTR_FORMAT, Metachunk::overhead());
  2158 
  2157 
  2159   chunk_manager()->slow_locked_verify();
  2158   chunk_manager()->slow_locked_verify();
  2160 
  2159 
  2161   dec_total_from_size_metrics();
  2160   dec_total_from_size_metrics();
  2162 
  2161 
  2163   LogHandle(gc, metaspace, freelist) log;
  2162   Log(gc, metaspace, freelist) log;
  2164   if (log.is_trace()) {
  2163   if (log.is_trace()) {
  2165     log.trace("~SpaceManager(): " PTR_FORMAT, p2i(this));
  2164     log.trace("~SpaceManager(): " PTR_FORMAT, p2i(this));
  2166     ResourceMark rm;
  2165     ResourceMark rm;
  2167     locked_print_chunks_in_use_on(log.trace_stream());
  2166     locked_print_chunks_in_use_on(log.trace_stream());
  2168     block_freelists()->print_on(log.trace_stream());
  2167     block_freelists()->print_on(log.trace_stream());
  2298 
  2297 
  2299   // Add to the running sum of capacity
  2298   // Add to the running sum of capacity
  2300   inc_size_metrics(new_chunk->word_size());
  2299   inc_size_metrics(new_chunk->word_size());
  2301 
  2300 
  2302   assert(new_chunk->is_empty(), "Not ready for reuse");
  2301   assert(new_chunk->is_empty(), "Not ready for reuse");
  2303   LogHandle(gc, metaspace, freelist) log;
  2302   Log(gc, metaspace, freelist) log;
  2304   if (log.is_trace()) {
  2303   if (log.is_trace()) {
  2305     log.trace("SpaceManager::add_chunk: " SIZE_FORMAT ") ", sum_count_in_chunks_in_use());
  2304     log.trace("SpaceManager::add_chunk: " SIZE_FORMAT ") ", sum_count_in_chunks_in_use());
  2306     ResourceMark rm;
  2305     ResourceMark rm;
  2307     outputStream* out = log.trace_stream();
  2306     outputStream* out = log.trace_stream();
  2308     new_chunk->print_on(out);
  2307     new_chunk->print_on(out);
  2329     next = vs_list()->get_new_chunk(word_size,
  2328     next = vs_list()->get_new_chunk(word_size,
  2330                                     grow_chunks_by_words,
  2329                                     grow_chunks_by_words,
  2331                                     medium_chunk_bunch());
  2330                                     medium_chunk_bunch());
  2332   }
  2331   }
  2333 
  2332 
  2334   LogHandle(gc, metaspace, alloc) log;
  2333   Log(gc, metaspace, alloc) log;
  2335   if (log.is_debug() && next != NULL &&
  2334   if (log.is_debug() && next != NULL &&
  2336       SpaceManager::is_humongous(next->word_size())) {
  2335       SpaceManager::is_humongous(next->word_size())) {
  2337     log.debug("  new humongous chunk word size " PTR_FORMAT, next->word_size());
  2336     log.debug("  new humongous chunk word size " PTR_FORMAT, next->word_size());
  2338   }
  2337   }
  2339 
  2338 
  2509 
  2508 
  2510   out->print_cr("total of all chunks "  SIZE_FORMAT " used " SIZE_FORMAT
  2509   out->print_cr("total of all chunks "  SIZE_FORMAT " used " SIZE_FORMAT
  2511                 " free " SIZE_FORMAT " capacity " SIZE_FORMAT
  2510                 " free " SIZE_FORMAT " capacity " SIZE_FORMAT
  2512                 " waste " SIZE_FORMAT, curr_total, used, free, capacity, waste);
  2511                 " waste " SIZE_FORMAT, curr_total, used, free, capacity, waste);
  2513 }
  2512 }
  2514 
       
  2515 #ifndef PRODUCT
       
  2516 void SpaceManager::mangle_freed_chunks() {
       
  2517   for (ChunkIndex index = ZeroIndex;
       
  2518        index < NumberOfInUseLists;
       
  2519        index = next_chunk_index(index)) {
       
  2520     for (Metachunk* curr = chunks_in_use(index);
       
  2521          curr != NULL;
       
  2522          curr = curr->next()) {
       
  2523       curr->mangle(uninitMetaWordVal);
       
  2524     }
       
  2525   }
       
  2526 }
       
  2527 #endif // PRODUCT
       
  2528 
  2513 
  2529 // MetaspaceAux
  2514 // MetaspaceAux
  2530 
  2515 
  2531 
  2516 
  2532 size_t MetaspaceAux::_capacity_words[] = {0, 0};
  2517 size_t MetaspaceAux::_capacity_words[] = {0, 0};
  3043                                   UseSharedSpaces ? (address)cds_base : 0);
  3028                                   UseSharedSpaces ? (address)cds_base : 0);
  3044 
  3029 
  3045   initialize_class_space(metaspace_rs);
  3030   initialize_class_space(metaspace_rs);
  3046 
  3031 
  3047   if (log_is_enabled(Trace, gc, metaspace)) {
  3032   if (log_is_enabled(Trace, gc, metaspace)) {
  3048     LogHandle(gc, metaspace) log;
  3033     Log(gc, metaspace) log;
  3049     ResourceMark rm;
  3034     ResourceMark rm;
  3050     print_compressed_class_space(log.trace_stream(), requested_addr);
  3035     print_compressed_class_space(log.trace_stream(), requested_addr);
  3051   }
  3036   }
  3052 }
  3037 }
  3053 
  3038 
  3518 
  3503 
  3519 void Metaspace::report_metadata_oome(ClassLoaderData* loader_data, size_t word_size, MetaspaceObj::Type type, MetadataType mdtype, TRAPS) {
  3504 void Metaspace::report_metadata_oome(ClassLoaderData* loader_data, size_t word_size, MetaspaceObj::Type type, MetadataType mdtype, TRAPS) {
  3520   tracer()->report_metadata_oom(loader_data, word_size, type, mdtype);
  3505   tracer()->report_metadata_oom(loader_data, word_size, type, mdtype);
  3521 
  3506 
  3522   // If result is still null, we are out of memory.
  3507   // If result is still null, we are out of memory.
  3523   LogHandle(gc, metaspace, freelist) log;
  3508   Log(gc, metaspace, freelist) log;
  3524   if (log.is_trace()) {
  3509   if (log.is_trace()) {
  3525     log.trace("Metaspace allocation failed for size " SIZE_FORMAT, word_size);
  3510     log.trace("Metaspace allocation failed for size " SIZE_FORMAT, word_size);
  3526     ResourceMark rm;
  3511     ResourceMark rm;
  3527     outputStream* out = log.trace_stream();
  3512     outputStream* out = log.trace_stream();
  3528     if (loader_data->metaspace_or_null() != NULL) {
  3513     if (loader_data->metaspace_or_null() != NULL) {