Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/services/memBaseline.hpp
32285 views
/*1* Copyright (c) 2012, 2017, 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_VM_SERVICES_MEM_BASELINE_HPP25#define SHARE_VM_SERVICES_MEM_BASELINE_HPP2627#if INCLUDE_NMT2829#include "memory/allocation.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 VALUE_OBJ_CLASS_SPEC {45public:46enum BaselineThreshold {47SIZE_THRESHOLD = K // Only allocation size over this threshold will be baselined.48};4950enum BaselineType {51Not_baselined,52Summary_baselined,53Detail_baselined54};5556enum SortingOrder {57by_address, // by memory address58by_size, // by memory size59by_site, // by call site where the memory is allocated from60by_site_and_type // by call site and memory type61};6263private:64// Summary information65MallocMemorySnapshot _malloc_memory_snapshot;66VirtualMemorySnapshot _virtual_memory_snapshot;6768size_t _class_count;6970// Allocation sites information71// Malloc allocation sites72LinkedListImpl<MallocSite> _malloc_sites;7374// All virtual memory allocations75LinkedListImpl<ReservedMemoryRegion> _virtual_memory_allocations;7677// Virtual memory allocations by allocation sites, always in by_address78// order79LinkedListImpl<VirtualMemoryAllocationSite> _virtual_memory_sites;8081SortingOrder _malloc_sites_order;82SortingOrder _virtual_memory_sites_order;8384BaselineType _baseline_type;8586public:87// create a memory baseline88MemBaseline():89_baseline_type(Not_baselined),90_class_count(0) {91}9293bool baseline(bool summaryOnly = true);9495BaselineType baseline_type() const { return _baseline_type; }9697MallocMemorySnapshot* malloc_memory_snapshot() {98return &_malloc_memory_snapshot;99}100101VirtualMemorySnapshot* virtual_memory_snapshot() {102return &_virtual_memory_snapshot;103}104105MallocSiteIterator malloc_sites(SortingOrder order);106VirtualMemorySiteIterator virtual_memory_sites(SortingOrder order);107108// Virtual memory allocation iterator always returns in virtual memory109// base address order.110VirtualMemoryAllocationIterator virtual_memory_allocations() {111assert(!_virtual_memory_allocations.is_empty(), "Not detail baseline");112return VirtualMemoryAllocationIterator(_virtual_memory_allocations.head());113}114115// Total reserved memory = total malloc'd memory + total reserved virtual116// memory117size_t total_reserved_memory() const {118assert(baseline_type() != Not_baselined, "Not yet baselined");119size_t amount = _malloc_memory_snapshot.total() +120_virtual_memory_snapshot.total_reserved();121return amount;122}123124// Total committed memory = total malloc'd memory + total committed125// virtual memory126size_t total_committed_memory() const {127assert(baseline_type() != Not_baselined, "Not yet baselined");128size_t amount = _malloc_memory_snapshot.total() +129_virtual_memory_snapshot.total_committed();130return amount;131}132133size_t total_arena_memory() const {134assert(baseline_type() != Not_baselined, "Not yet baselined");135return _malloc_memory_snapshot.total_arena();136}137138size_t malloc_tracking_overhead() const {139assert(baseline_type() != Not_baselined, "Not yet baselined");140MemBaseline* bl = const_cast<MemBaseline*>(this);141return bl->_malloc_memory_snapshot.malloc_overhead()->size();142}143144MallocMemory* malloc_memory(MEMFLAGS flag) {145assert(baseline_type() != Not_baselined, "Not yet baselined");146return _malloc_memory_snapshot.by_type(flag);147}148149VirtualMemory* virtual_memory(MEMFLAGS flag) {150assert(baseline_type() != Not_baselined, "Not yet baselined");151return _virtual_memory_snapshot.by_type(flag);152}153154155size_t class_count() const {156assert(baseline_type() != Not_baselined, "Not yet baselined");157return _class_count;158}159160size_t thread_count() const {161assert(baseline_type() != Not_baselined, "Not yet baselined");162return _malloc_memory_snapshot.thread_count();163}164165// reset the baseline for reuse166void reset() {167_baseline_type = Not_baselined;168// _malloc_memory_snapshot and _virtual_memory_snapshot are copied over.169_class_count = 0;170171_malloc_sites.clear();172_virtual_memory_sites.clear();173_virtual_memory_allocations.clear();174}175176private:177// Baseline summary information178bool baseline_summary();179180// Baseline allocation sites (detail tracking only)181bool baseline_allocation_sites();182183// Aggregate virtual memory allocation by allocation sites184bool aggregate_virtual_memory_allocation_sites();185186// Sorting allocation sites in different orders187// Sort allocation sites in size order188void malloc_sites_to_size_order();189// Sort allocation sites in call site address order190void malloc_sites_to_allocation_site_order();191// Sort allocation sites in call site address and memory type order192void malloc_sites_to_allocation_site_and_type_order();193194// Sort allocation sites in reserved size order195void virtual_memory_sites_to_size_order();196// Sort allocation sites in call site address order197void virtual_memory_sites_to_reservation_site_order();198};199200#endif // INCLUDE_NMT201202#endif // SHARE_VM_SERVICES_MEM_BASELINE_HPP203204205