hotspot/src/share/vm/services/memBaseline.hpp
author zgu
Thu, 07 Aug 2014 12:18:58 -0700
changeset 25946 1572c9f03fb9
parent 17074 d660347efb98
child 26288 631bf42cf7c2
permissions -rw-r--r--
8046598: Scalable Native memory tracking development Summary: Enhance scalability of native memory tracking Reviewed-by: coleenp, ctornqvi, gtriantafill
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     1
/*
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
     2
 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     4
 *
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     7
 * published by the Free Software Foundation.
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     8
 *
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    13
 * accompanied this code).
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    14
 *
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    18
 *
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    21
 * questions.
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    22
 *
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    23
 */
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    24
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    25
#ifndef SHARE_VM_SERVICES_MEM_BASELINE_HPP
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    26
#define SHARE_VM_SERVICES_MEM_BASELINE_HPP
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    27
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    28
#if INCLUDE_NMT
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    29
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    30
#include "memory/allocation.hpp"
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    31
#include "runtime/mutex.hpp"
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    32
#include "services/mallocSiteTable.hpp"
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    33
#include "services/mallocTracker.hpp"
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    34
#include "services/nmtCommon.hpp"
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    35
#include "services/virtualMemoryTracker.hpp"
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    36
#include "utilities/linkedlist.hpp"
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    37
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    38
typedef LinkedListIterator<MallocSite>                   MallocSiteIterator;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    39
typedef LinkedListIterator<VirtualMemoryAllocationSite>  VirtualMemorySiteIterator;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    40
typedef LinkedListIterator<ReservedMemoryRegion>         VirtualMemoryAllocationIterator;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    41
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    42
/*
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    43
 * Baseline a memory snapshot
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    44
 */
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    45
class MemBaseline VALUE_OBJ_CLASS_SPEC {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    46
 public:
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    47
  enum BaselineThreshold {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    48
    SIZE_THRESHOLD = K        // Only allocation size over this threshold will be baselined.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    49
  };
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    50
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    51
  enum BaselineType {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    52
    Not_baselined,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    53
    Summary_baselined,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    54
    Detail_baselined
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    55
  };
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    56
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    57
  enum SortingOrder {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    58
    by_address,   // by memory address
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    59
    by_size,      // by memory size
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    60
    by_site       // by call site where the memory is allocated from
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    61
  };
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    62
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    63
 private:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    64
  // All baseline data is stored in this arena
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    65
  Arena*                  _arena;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    66
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    67
  // Summary information
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    68
  MallocMemorySnapshot*   _malloc_memory_snapshot;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    69
  VirtualMemorySnapshot*  _virtual_memory_snapshot;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    70
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    71
  size_t               _class_count;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    72
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    73
  // Allocation sites information
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    74
  // Malloc allocation sites
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    75
  LinkedListImpl<MallocSite, ResourceObj::ARENA>
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    76
                       _malloc_sites;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    77
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    78
  // All virtual memory allocations
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    79
  LinkedListImpl<ReservedMemoryRegion, ResourceObj::ARENA>
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    80
                       _virtual_memory_allocations;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    81
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    82
  // Virtual memory allocations by allocation sites, always in by_address
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    83
  // order
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    84
  LinkedListImpl<VirtualMemoryAllocationSite, ResourceObj::ARENA>
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    85
                       _virtual_memory_sites;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    86
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    87
  SortingOrder         _malloc_sites_order;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    88
  SortingOrder         _virtual_memory_sites_order;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    89
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    90
  BaselineType         _baseline_type;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    91
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
    92
 public:
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    93
  // create a memory baseline
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    94
  MemBaseline():
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    95
    _baseline_type(Not_baselined),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    96
    _class_count(0),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    97
    _arena(NULL),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    98
    _malloc_memory_snapshot(NULL),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
    99
    _virtual_memory_snapshot(NULL),
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   100
    _malloc_sites(NULL) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   101
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   102
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   103
  ~MemBaseline() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   104
    reset();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   105
    if (_arena != NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   106
      delete _arena;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   107
    }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   108
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   109
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   110
  bool baseline(bool summaryOnly = true);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   111
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   112
  BaselineType baseline_type() const { return _baseline_type; }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   113
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   114
  MallocMemorySnapshot* malloc_memory_snapshot() const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   115
    return _malloc_memory_snapshot;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   116
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   117
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   118
  VirtualMemorySnapshot* virtual_memory_snapshot() const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   119
    return _virtual_memory_snapshot;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   120
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   121
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   122
  MallocSiteIterator malloc_sites(SortingOrder order);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   123
  VirtualMemorySiteIterator virtual_memory_sites(SortingOrder order);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   124
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   125
  // Virtual memory allocation iterator always returns in virtual memory
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   126
  // base address order.
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   127
  VirtualMemoryAllocationIterator virtual_memory_allocations() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   128
    assert(!_virtual_memory_allocations.is_empty(), "Not detail baseline");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   129
    return VirtualMemoryAllocationIterator(_virtual_memory_allocations.head());
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   130
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   131
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   132
  // Total reserved memory = total malloc'd memory + total reserved virtual
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   133
  // memory
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   134
  size_t total_reserved_memory() const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   135
    assert(baseline_type() != Not_baselined, "Not yet baselined");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   136
    assert(_virtual_memory_snapshot != NULL, "No virtual memory snapshot");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   137
    assert(_malloc_memory_snapshot != NULL,  "No malloc memory snapshot");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   138
    size_t amount = _malloc_memory_snapshot->total() +
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   139
           _virtual_memory_snapshot->total_reserved();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   140
    return amount;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   141
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   142
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   143
  // Total committed memory = total malloc'd memory + total committed
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   144
  // virtual memory
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   145
  size_t total_committed_memory() const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   146
    assert(baseline_type() != Not_baselined, "Not yet baselined");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   147
    assert(_virtual_memory_snapshot != NULL,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   148
      "Not a snapshot");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   149
    size_t amount = _malloc_memory_snapshot->total() +
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   150
           _virtual_memory_snapshot->total_committed();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   151
    return amount;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   152
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   153
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   154
  size_t total_arena_memory() const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   155
    assert(baseline_type() != Not_baselined, "Not yet baselined");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   156
    assert(_malloc_memory_snapshot != NULL, "Not yet baselined");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   157
    return _malloc_memory_snapshot->total_arena();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   158
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   159
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   160
  size_t malloc_tracking_overhead() const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   161
    assert(baseline_type() != Not_baselined, "Not yet baselined");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   162
    return _malloc_memory_snapshot->malloc_overhead()->size();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   163
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   164
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   165
  const MallocMemory* malloc_memory(MEMFLAGS flag) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   166
    assert(_malloc_memory_snapshot != NULL, "Not a snapshot");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   167
    return _malloc_memory_snapshot->by_type(flag);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   168
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   169
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   170
  const VirtualMemory* virtual_memory(MEMFLAGS flag) const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   171
    assert(_virtual_memory_snapshot != NULL, "Not a snapshot");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   172
    return _virtual_memory_snapshot->by_type(flag);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   173
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   174
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   175
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   176
  size_t class_count() const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   177
    assert(baseline_type() != Not_baselined, "Not yet baselined");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   178
    return _class_count;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   179
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   180
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   181
  size_t thread_count() const {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   182
    assert(baseline_type() != Not_baselined, "Not yet baselined");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   183
    assert(_malloc_memory_snapshot != NULL, "Baselined?");
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   184
    return _malloc_memory_snapshot->thread_count();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   185
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   186
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   187
  // reset the baseline for reuse
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   188
  void reset() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   189
    _baseline_type = Not_baselined;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   190
    _malloc_memory_snapshot = NULL;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   191
    _virtual_memory_snapshot = NULL;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   192
    _class_count  = 0;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   193
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   194
    _malloc_sites = NULL;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   195
    _virtual_memory_sites = NULL;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   196
    _virtual_memory_allocations = NULL;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   197
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   198
    if (_arena != NULL) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   199
      _arena->destruct_contents();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   200
    }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   201
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   202
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   203
 private:
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   204
  // Baseline summary information
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   205
  bool baseline_summary();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   206
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   207
  // Baseline allocation sites (detail tracking only)
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   208
  bool baseline_allocation_sites();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   209
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   210
  // Aggregate virtual memory allocation by allocation sites
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   211
  bool aggregate_virtual_memory_allocation_sites();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   212
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   213
  Arena* arena() { return _arena; }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   214
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   215
  // Sorting allocation sites in different orders
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   216
  // Sort allocation sites in size order
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   217
  void malloc_sites_to_size_order();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   218
  // Sort allocation sites in call site address order
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   219
  void malloc_sites_to_allocation_site_order();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   220
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   221
  // Sort allocation sites in reserved size order
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   222
  void virtual_memory_sites_to_size_order();
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   223
  // Sort allocation sites in call site address order
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   224
  void virtual_memory_sites_to_reservation_site_order();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   225
};
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   226
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 17074
diff changeset
   227
#endif // INCLUDE_NMT
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   228
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents:
diff changeset
   229
#endif // SHARE_VM_SERVICES_MEM_BASELINE_HPP