--- old/src/share/vm/memory/metaspace.cpp 2014-03-06 11:45:16.741837222 +0100 +++ new/src/share/vm/memory/metaspace.cpp 2014-03-06 11:45:16.641837218 +0100 @@ -185,6 +185,38 @@ // Remove from a list by size. Selects list based on size of chunk. Metachunk* free_chunks_get(size_t chunk_word_size); + void index_bounds_check(ChunkIndex index) const { + assert(index == SpecializedIndex || + index == SmallIndex || + index == MediumIndex || + index == HumongousIndex, err_msg("Bad index: " INT32_FORMAT, (int) index)); + } + + size_t num_free_chunks(ChunkIndex index) const { + index_bounds_check(index); + + if (index == HumongousIndex) { + return _humongous_dictionary.total_free_blocks(); + } + + ssize_t count = _free_chunks[index].count(); + return count == -1 ? 0 : (size_t) count; + } + + size_t size_free_chunks_in_bytes(ChunkIndex index) const { + index_bounds_check(index); + + size_t word_size = 0; + if (index == HumongousIndex) { + word_size = _humongous_dictionary.total_size(); + } else { + const size_t size_per_chunk_in_words = _free_chunks[index].size(); + word_size = size_per_chunk_in_words * num_free_chunks(index); + } + + return word_size * BytesPerWord; + } + // Debug support void verify(); void slow_verify() { @@ -2637,6 +2669,26 @@ return free_chunks_total_words() * BytesPerWord; } +bool MetaspaceAux::has_chunk_free_list(Metaspace::MetadataType mdtype) { + return Metaspace::get_chunk_manager(mdtype) != NULL; +} + +MetaspaceChunkFreeListSummary MetaspaceAux::chunk_free_list_summary(Metaspace::MetadataType mdtype) { + if (!has_chunk_free_list(mdtype)) { + return MetaspaceChunkFreeListSummary(); + } + + ChunkManager *cm = Metaspace::get_chunk_manager(mdtype); + return MetaspaceChunkFreeListSummary(cm->num_free_chunks(SpecializedIndex), + cm->num_free_chunks(SmallIndex), + cm->num_free_chunks(MediumIndex), + cm->num_free_chunks(HumongousIndex), + cm->size_free_chunks_in_bytes(SpecializedIndex), + cm->size_free_chunks_in_bytes(SmallIndex), + cm->size_free_chunks_in_bytes(MediumIndex), + cm->size_free_chunks_in_bytes(HumongousIndex)); +} + void MetaspaceAux::print_metaspace_change(size_t prev_metadata_used) { gclog_or_tty->print(", [Metaspace:"); if (PrintGCDetails && Verbose) {