src/share/vm/services/memoryManager.hpp

changeset 435
a61af66fc99e
child 1524
db0d5eba9d20
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/services/memoryManager.hpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,233 @@
     1.4 +/*
     1.5 + * Copyright 2003-2005 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +// A memory manager is responsible for managing one or more memory pools.
    1.29 +// The garbage collector is one type of memory managers responsible
    1.30 +// for reclaiming memory occupied by unreachable objects.  A Java virtual
    1.31 +// machine may have one or more memory managers.   It may
    1.32 +// add or remove memory managers during execution.
    1.33 +// A memory pool can be managed by more than one memory managers.
    1.34 +
    1.35 +class MemoryPool;
    1.36 +class GCMemoryManager;
    1.37 +class OopClosure;
    1.38 +
    1.39 +class MemoryManager : public CHeapObj {
    1.40 +private:
    1.41 +  enum {
    1.42 +    max_num_pools = 10
    1.43 +  };
    1.44 +
    1.45 +  MemoryPool* _pools[max_num_pools];
    1.46 +  int         _num_pools;
    1.47 +
    1.48 +protected:
    1.49 +  volatile instanceOop _memory_mgr_obj;
    1.50 +
    1.51 +public:
    1.52 +  enum Name {
    1.53 +    Abstract,
    1.54 +    CodeCache,
    1.55 +    Copy,
    1.56 +    MarkSweepCompact,
    1.57 +    ParNew,
    1.58 +    ConcurrentMarkSweep,
    1.59 +    PSScavenge,
    1.60 +    PSMarkSweep
    1.61 +  };
    1.62 +
    1.63 +  MemoryManager();
    1.64 +
    1.65 +  int num_memory_pools() const           { return _num_pools; }
    1.66 +  MemoryPool* get_memory_pool(int index) {
    1.67 +    assert(index >= 0 && index < _num_pools, "Invalid index");
    1.68 +    return _pools[index];
    1.69 +  }
    1.70 +
    1.71 +  void add_pool(MemoryPool* pool);
    1.72 +
    1.73 +  bool is_manager(instanceHandle mh)     { return mh() == _memory_mgr_obj; }
    1.74 +
    1.75 +  virtual instanceOop get_memory_manager_instance(TRAPS);
    1.76 +  virtual MemoryManager::Name kind()     { return MemoryManager::Abstract; }
    1.77 +  virtual bool is_gc_memory_manager()    { return false; }
    1.78 +  virtual const char* name() = 0;
    1.79 +
    1.80 +  // GC support
    1.81 +  void oops_do(OopClosure* f);
    1.82 +
    1.83 +  // Static factory methods to get a memory manager of a specific type
    1.84 +  static MemoryManager*   get_code_cache_memory_manager();
    1.85 +  static GCMemoryManager* get_copy_memory_manager();
    1.86 +  static GCMemoryManager* get_msc_memory_manager();
    1.87 +  static GCMemoryManager* get_parnew_memory_manager();
    1.88 +  static GCMemoryManager* get_cms_memory_manager();
    1.89 +  static GCMemoryManager* get_psScavenge_memory_manager();
    1.90 +  static GCMemoryManager* get_psMarkSweep_memory_manager();
    1.91 +
    1.92 +};
    1.93 +
    1.94 +class CodeCacheMemoryManager : public MemoryManager {
    1.95 +private:
    1.96 +public:
    1.97 +  CodeCacheMemoryManager() : MemoryManager() {}
    1.98 +
    1.99 +  MemoryManager::Name kind() { return MemoryManager::CodeCache; }
   1.100 +  const char* name()         { return "CodeCacheManager"; }
   1.101 +};
   1.102 +
   1.103 +class GCStatInfo : public CHeapObj {
   1.104 +private:
   1.105 +  size_t _index;
   1.106 +  jlong  _start_time;
   1.107 +  jlong  _end_time;
   1.108 +
   1.109 +  // We keep memory usage of all memory pools
   1.110 +  MemoryUsage* _before_gc_usage_array;
   1.111 +  MemoryUsage* _after_gc_usage_array;
   1.112 +  int          _usage_array_size;
   1.113 +
   1.114 +  void set_gc_usage(int pool_index, MemoryUsage, bool before_gc);
   1.115 +
   1.116 +public:
   1.117 +  GCStatInfo(int num_pools);
   1.118 +  ~GCStatInfo();
   1.119 +
   1.120 +  size_t gc_index()               { return _index; }
   1.121 +  jlong  start_time()             { return _start_time; }
   1.122 +  jlong  end_time()               { return _end_time; }
   1.123 +  int    usage_array_size()       { return _usage_array_size; }
   1.124 +  MemoryUsage before_gc_usage_for_pool(int pool_index) {
   1.125 +    assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking");
   1.126 +    return _before_gc_usage_array[pool_index];
   1.127 +  }
   1.128 +  MemoryUsage after_gc_usage_for_pool(int pool_index) {
   1.129 +    assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking");
   1.130 +    return _after_gc_usage_array[pool_index];
   1.131 +  }
   1.132 +
   1.133 +  void set_index(size_t index)    { _index = index; }
   1.134 +  void set_start_time(jlong time) { _start_time = time; }
   1.135 +  void set_end_time(jlong time)   { _end_time = time; }
   1.136 +  void set_before_gc_usage(int pool_index, MemoryUsage usage) {
   1.137 +    assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking");
   1.138 +    set_gc_usage(pool_index, usage, true /* before gc */);
   1.139 +  }
   1.140 +  void set_after_gc_usage(int pool_index, MemoryUsage usage) {
   1.141 +    assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking");
   1.142 +    set_gc_usage(pool_index, usage, false /* after gc */);
   1.143 +  }
   1.144 +
   1.145 +  void copy_stat(GCStatInfo* stat);
   1.146 +};
   1.147 +
   1.148 +class GCMemoryManager : public MemoryManager {
   1.149 +private:
   1.150 +  // TODO: We should unify the GCCounter and GCMemoryManager statistic
   1.151 +  size_t       _num_collections;
   1.152 +  elapsedTimer _accumulated_timer;
   1.153 +  elapsedTimer _gc_timer;         // for measuring every GC duration
   1.154 +  GCStatInfo*  _last_gc_stat;
   1.155 +  int          _num_gc_threads;
   1.156 +public:
   1.157 +  GCMemoryManager();
   1.158 +  ~GCMemoryManager();
   1.159 +
   1.160 +  void   initialize_gc_stat_info();
   1.161 +
   1.162 +  bool   is_gc_memory_manager()         { return true; }
   1.163 +  jlong  gc_time_ms()                   { return _accumulated_timer.milliseconds(); }
   1.164 +  size_t gc_count()                     { return _num_collections; }
   1.165 +  int    num_gc_threads()               { return _num_gc_threads; }
   1.166 +  void   set_num_gc_threads(int count)  { _num_gc_threads = count; }
   1.167 +
   1.168 +  void   gc_begin();
   1.169 +  void   gc_end();
   1.170 +
   1.171 +  void        reset_gc_stat()   { _num_collections = 0; _accumulated_timer.reset(); }
   1.172 +  GCStatInfo* last_gc_stat()    { return _last_gc_stat; }
   1.173 +
   1.174 +  virtual MemoryManager::Name kind() = 0;
   1.175 +};
   1.176 +
   1.177 +// These subclasses of GCMemoryManager are defined to include
   1.178 +// GC-specific information.
   1.179 +// TODO: Add GC-specific information
   1.180 +class CopyMemoryManager : public GCMemoryManager {
   1.181 +private:
   1.182 +public:
   1.183 +  CopyMemoryManager() : GCMemoryManager() {}
   1.184 +
   1.185 +  MemoryManager::Name kind() { return MemoryManager::Copy; }
   1.186 +  const char* name()         { return "Copy"; }
   1.187 +};
   1.188 +
   1.189 +class MSCMemoryManager : public GCMemoryManager {
   1.190 +private:
   1.191 +public:
   1.192 +  MSCMemoryManager() : GCMemoryManager() {}
   1.193 +
   1.194 +  MemoryManager::Name kind() { return MemoryManager::MarkSweepCompact; }
   1.195 +  const char* name()         { return "MarkSweepCompact"; }
   1.196 +
   1.197 +};
   1.198 +
   1.199 +class ParNewMemoryManager : public GCMemoryManager {
   1.200 +private:
   1.201 +public:
   1.202 +  ParNewMemoryManager() : GCMemoryManager() {}
   1.203 +
   1.204 +  MemoryManager::Name kind() { return MemoryManager::ParNew; }
   1.205 +  const char* name()         { return "ParNew"; }
   1.206 +
   1.207 +};
   1.208 +
   1.209 +class CMSMemoryManager : public GCMemoryManager {
   1.210 +private:
   1.211 +public:
   1.212 +  CMSMemoryManager() : GCMemoryManager() {}
   1.213 +
   1.214 +  MemoryManager::Name kind() { return MemoryManager::ConcurrentMarkSweep; }
   1.215 +  const char* name()         { return "ConcurrentMarkSweep";}
   1.216 +
   1.217 +};
   1.218 +
   1.219 +class PSScavengeMemoryManager : public GCMemoryManager {
   1.220 +private:
   1.221 +public:
   1.222 +  PSScavengeMemoryManager() : GCMemoryManager() {}
   1.223 +
   1.224 +  MemoryManager::Name kind() { return MemoryManager::PSScavenge; }
   1.225 +  const char* name()         { return "PS Scavenge"; }
   1.226 +
   1.227 +};
   1.228 +
   1.229 +class PSMarkSweepMemoryManager : public GCMemoryManager {
   1.230 +private:
   1.231 +public:
   1.232 +  PSMarkSweepMemoryManager() : GCMemoryManager() {}
   1.233 +
   1.234 +  MemoryManager::Name kind() { return MemoryManager::PSMarkSweep; }
   1.235 +  const char* name()         { return "PS MarkSweep"; }
   1.236 +};

mercurial