memoryService.hpp 8.0 KB
Newer Older
D
duke 已提交
1
/*
2
 * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
19 20 21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
22 23 24
 *
 */

25 26 27 28 29 30 31
#ifndef SHARE_VM_SERVICES_MEMORYSERVICE_HPP
#define SHARE_VM_SERVICES_MEMORYSERVICE_HPP

#include "memory/allocation.hpp"
#include "memory/generation.hpp"
#include "runtime/handles.hpp"
#include "services/memoryUsage.hpp"
32
#include "gc_interface/gcCause.hpp"
33

D
duke 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47
// Forward declaration
class MemoryPool;
class MemoryManager;
class GCMemoryManager;
class CollectedHeap;
class Generation;
class DefNewGeneration;
class PSYoungGen;
class PSOldGen;
class CodeHeap;
class ContiguousSpace;
class CompactibleFreeListSpace;
class GenCollectedHeap;
class ParallelScavengeHeap;
48
class G1CollectedHeap;
D
duke 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75

// VM Monitoring and Management Support

class MemoryService : public AllStatic {
private:
  enum {
    init_pools_list_size = 10,
    init_managers_list_size = 5
  };

  // index for minor and major generations
  enum {
    minor = 0,
    major = 1,
    n_gens = 2
  };

  static GrowableArray<MemoryPool*>*    _pools_list;
  static GrowableArray<MemoryManager*>* _managers_list;

  // memory managers for minor and major GC statistics
  static GCMemoryManager*               _major_gc_manager;
  static GCMemoryManager*               _minor_gc_manager;

  // Code heap memory pool
  static MemoryPool*                    _code_heap_pool;

76 77 78
  static MemoryPool*                    _metaspace_pool;
  static MemoryPool*                    _compressed_class_pool;

D
duke 已提交
79
  static void add_generation_memory_pool(Generation* gen,
80 81
                                         GCMemoryManager* major_mgr,
                                         GCMemoryManager* minor_mgr);
D
duke 已提交
82
  static void add_generation_memory_pool(Generation* gen,
83
                                         GCMemoryManager* major_mgr) {
D
duke 已提交
84 85 86 87 88
    add_generation_memory_pool(gen, major_mgr, NULL);
  }


  static void add_psYoung_memory_pool(PSYoungGen* gen,
89 90
                                      GCMemoryManager* major_mgr,
                                      GCMemoryManager* minor_mgr);
D
duke 已提交
91
  static void add_psOld_memory_pool(PSOldGen* gen,
92
                                    GCMemoryManager* mgr);
D
duke 已提交
93

94
  static void add_g1YoungGen_memory_pool(G1CollectedHeap* g1h,
95 96
                                         GCMemoryManager* major_mgr,
                                         GCMemoryManager* minor_mgr);
97
  static void add_g1OldGen_memory_pool(G1CollectedHeap* g1h,
98 99
                                       GCMemoryManager* major_mgr,
                                       GCMemoryManager* minor_mgr);
D
duke 已提交
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122

  static MemoryPool* add_space(ContiguousSpace* space,
                               const char* name,
                               bool is_heap,
                               size_t max_size,
                               bool support_usage_threshold);
  static MemoryPool* add_survivor_spaces(DefNewGeneration* gen,
                                         const char* name,
                                         bool is_heap,
                                         size_t max_size,
                                         bool support_usage_threshold);
  static MemoryPool* add_gen(Generation* gen,
                             const char* name,
                             bool is_heap,
                             bool support_usage_threshold);
  static MemoryPool* add_cms_space(CompactibleFreeListSpace* space,
                                   const char* name,
                                   bool is_heap,
                                   size_t max_size,
                                   bool support_usage_threshold);

  static void add_gen_collected_heap_info(GenCollectedHeap* heap);
  static void add_parallel_scavenge_heap_info(ParallelScavengeHeap* heap);
123
  static void add_g1_heap_info(G1CollectedHeap* g1h);
D
duke 已提交
124 125 126 127

public:
  static void set_universe_heap(CollectedHeap* heap);
  static void add_code_heap_memory_pool(CodeHeap* heap);
128
  static void add_metaspace_memory_pools();
D
duke 已提交
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151

  static MemoryPool*    get_memory_pool(instanceHandle pool);
  static MemoryManager* get_memory_manager(instanceHandle mgr);

  static const int num_memory_pools() {
    return _pools_list->length();
  }
  static const int num_memory_managers() {
    return _managers_list->length();
  }

  static MemoryPool* get_memory_pool(int index) {
    return _pools_list->at(index);
  }

  static MemoryManager* get_memory_manager(int index) {
    return _managers_list->at(index);
  }

  static void track_memory_usage();
  static void track_code_cache_memory_usage() {
    track_memory_pool_usage(_code_heap_pool);
  }
152 153 154 155 156 157
  static void track_metaspace_memory_usage() {
    track_memory_pool_usage(_metaspace_pool);
  }
  static void track_compressed_class_memory_usage() {
    track_memory_pool_usage(_compressed_class_pool);
  }
D
duke 已提交
158 159
  static void track_memory_pool_usage(MemoryPool* pool);

160 161 162 163 164
  static void gc_begin(bool fullGC, bool recordGCBeginTime,
                       bool recordAccumulatedGCTime,
                       bool recordPreGCUsage, bool recordPeakUsage);
  static void gc_end(bool fullGC, bool recordPostGCUsage,
                     bool recordAccumulatedGCTime,
165
                     bool recordGCEndTime, bool countCollection,
166 167
                     GCCause::Cause cause,
                     bool allMemoryPoolsAffected);
168

D
duke 已提交
169 170 171 172 173 174 175 176

  static void oops_do(OopClosure* f);

  static bool get_verbose() { return PrintGC; }
  static bool set_verbose(bool verbose);

  // Create an instance of java/lang/management/MemoryUsage
  static Handle create_MemoryUsage_obj(MemoryUsage usage, TRAPS);
177 178 179 180 181 182 183 184

  static const GCMemoryManager* get_minor_gc_manager() {
      return _minor_gc_manager;
  }

  static const GCMemoryManager* get_major_gc_manager() {
      return _major_gc_manager;
  }
D
duke 已提交
185 186 187 188 189
};

class TraceMemoryManagerStats : public StackObj {
private:
  bool         _fullGC;
190
  bool         _allMemoryPoolsAffected;
191 192 193 194 195 196 197
  bool         _recordGCBeginTime;
  bool         _recordPreGCUsage;
  bool         _recordPeakUsage;
  bool         _recordPostGCUsage;
  bool         _recordAccumulatedGCTime;
  bool         _recordGCEndTime;
  bool         _countCollection;
198
  GCCause::Cause _cause;
D
duke 已提交
199
public:
200 201
  TraceMemoryManagerStats() {}
  TraceMemoryManagerStats(bool fullGC,
202
                          GCCause::Cause cause,
203
                          bool allMemoryPoolsAffected = true,
204 205 206 207 208 209 210 211 212
                          bool recordGCBeginTime = true,
                          bool recordPreGCUsage = true,
                          bool recordPeakUsage = true,
                          bool recordPostGCUsage = true,
                          bool recordAccumulatedGCTime = true,
                          bool recordGCEndTime = true,
                          bool countCollection = true);

  void initialize(bool fullGC,
213
                  GCCause::Cause cause,
214
                  bool allMemoryPoolsAffected,
215 216 217 218 219 220 221 222
                  bool recordGCBeginTime,
                  bool recordPreGCUsage,
                  bool recordPeakUsage,
                  bool recordPostGCUsage,
                  bool recordAccumulatedGCTime,
                  bool recordGCEndTime,
                  bool countCollection);

223
  TraceMemoryManagerStats(Generation::Name kind, GCCause::Cause cause);
D
duke 已提交
224 225
  ~TraceMemoryManagerStats();
};
226 227

#endif // SHARE_VM_SERVICES_MEMORYSERVICE_HPP