Path: blob/master/src/hotspot/share/services/memBaseline.hpp
41144 views
/*1* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_SERVICES_MEMBASELINE_HPP25#define SHARE_SERVICES_MEMBASELINE_HPP2627#if INCLUDE_NMT2829#include "memory/metaspaceStats.hpp"30#include "runtime/mutex.hpp"31#include "services/mallocSiteTable.hpp"32#include "services/mallocTracker.hpp"33#include "services/nmtCommon.hpp"34#include "services/virtualMemoryTracker.hpp"35#include "utilities/linkedlist.hpp"3637typedef LinkedListIterator<MallocSite> MallocSiteIterator;38typedef LinkedListIterator<VirtualMemoryAllocationSite> VirtualMemorySiteIterator;39typedef LinkedListIterator<ReservedMemoryRegion> VirtualMemoryAllocationIterator;4041/*42* Baseline a memory snapshot43*/44class MemBaseline {45public:4647enum BaselineType {48Not_baselined,49Summary_baselined,50Detail_baselined51};5253enum SortingOrder {54by_address, // by memory address55by_size, // by memory size56by_site, // by call site where the memory is allocated from57by_site_and_type // by call site and memory type58};5960private:61// Summary information62MallocMemorySnapshot _malloc_memory_snapshot;63VirtualMemorySnapshot _virtual_memory_snapshot;64MetaspaceCombinedStats _metaspace_stats;6566size_t _instance_class_count;67size_t _array_class_count;6869// Allocation sites information70// Malloc allocation sites71LinkedListImpl<MallocSite> _malloc_sites;7273// All virtual memory allocations74LinkedListImpl<ReservedMemoryRegion> _virtual_memory_allocations;7576// Virtual memory allocations by allocation sites, always in by_address77// order78LinkedListImpl<VirtualMemoryAllocationSite> _virtual_memory_sites;7980SortingOrder _malloc_sites_order;81SortingOrder _virtual_memory_sites_order;8283BaselineType _baseline_type;8485public:86// create a memory baseline87MemBaseline():88_instance_class_count(0), _array_class_count(0),89_baseline_type(Not_baselined) {90}9192bool baseline(bool summaryOnly = true);9394BaselineType baseline_type() const { return _baseline_type; }9596MallocMemorySnapshot* malloc_memory_snapshot() {97return &_malloc_memory_snapshot;98}99100VirtualMemorySnapshot* virtual_memory_snapshot() {101return &_virtual_memory_snapshot;102}103104const MetaspaceCombinedStats& metaspace_stats() const {105return _metaspace_stats;106}107108MallocSiteIterator malloc_sites(SortingOrder order);109VirtualMemorySiteIterator virtual_memory_sites(SortingOrder order);110111// Virtual memory allocation iterator always returns in virtual memory112// base address order.113VirtualMemoryAllocationIterator virtual_memory_allocations() {114assert(!_virtual_memory_allocations.is_empty(), "Not detail baseline");115return VirtualMemoryAllocationIterator(_virtual_memory_allocations.head());116}117118// Total reserved memory = total malloc'd memory + total reserved virtual119// memory120size_t total_reserved_memory() const {121assert(baseline_type() != Not_baselined, "Not yet baselined");122size_t amount = _malloc_memory_snapshot.total() +123_virtual_memory_snapshot.total_reserved();124return amount;125}126127// Total committed memory = total malloc'd memory + total committed128// virtual memory129size_t total_committed_memory() const {130assert(baseline_type() != Not_baselined, "Not yet baselined");131size_t amount = _malloc_memory_snapshot.total() +132_virtual_memory_snapshot.total_committed();133return amount;134}135136size_t total_arena_memory() const {137assert(baseline_type() != Not_baselined, "Not yet baselined");138return _malloc_memory_snapshot.total_arena();139}140141size_t malloc_tracking_overhead() const {142assert(baseline_type() != Not_baselined, "Not yet baselined");143MemBaseline* bl = const_cast<MemBaseline*>(this);144return bl->_malloc_memory_snapshot.malloc_overhead()->size();145}146147MallocMemory* malloc_memory(MEMFLAGS flag) {148assert(baseline_type() != Not_baselined, "Not yet baselined");149return _malloc_memory_snapshot.by_type(flag);150}151152VirtualMemory* virtual_memory(MEMFLAGS flag) {153assert(baseline_type() != Not_baselined, "Not yet baselined");154return _virtual_memory_snapshot.by_type(flag);155}156157158size_t class_count() const {159assert(baseline_type() != Not_baselined, "Not yet baselined");160return _instance_class_count + _array_class_count;161}162163size_t instance_class_count() const {164assert(baseline_type() != Not_baselined, "Not yet baselined");165return _instance_class_count;166}167168size_t array_class_count() const {169assert(baseline_type() != Not_baselined, "Not yet baselined");170return _array_class_count;171}172173size_t thread_count() const {174assert(baseline_type() != Not_baselined, "Not yet baselined");175return _malloc_memory_snapshot.thread_count();176}177178// reset the baseline for reuse179void reset() {180_baseline_type = Not_baselined;181// _malloc_memory_snapshot and _virtual_memory_snapshot are copied over.182_instance_class_count = 0;183_array_class_count = 0;184185_malloc_sites.clear();186_virtual_memory_sites.clear();187_virtual_memory_allocations.clear();188}189190private:191// Baseline summary information192bool baseline_summary();193194// Baseline allocation sites (detail tracking only)195bool baseline_allocation_sites();196197// Aggregate virtual memory allocation by allocation sites198bool aggregate_virtual_memory_allocation_sites();199200// Sorting allocation sites in different orders201// Sort allocation sites in size order202void malloc_sites_to_size_order();203// Sort allocation sites in call site address order204void malloc_sites_to_allocation_site_order();205// Sort allocation sites in call site address and memory type order206void malloc_sites_to_allocation_site_and_type_order();207208// Sort allocation sites in reserved size order209void virtual_memory_sites_to_size_order();210// Sort allocation sites in call site address order211void virtual_memory_sites_to_reservation_site_order();212};213214#endif // INCLUDE_NMT215216#endif // SHARE_SERVICES_MEMBASELINE_HPP217218219