author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 30149 | hotspot/src/share/vm/services/memoryManager.hpp@c0f930abe5ed |
child 48114 | e6b643827037 |
child 55767 | 8e22715afabc |
permissions | -rw-r--r-- |
1 | 1 |
/* |
22234
da823d78ad65
8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents:
18444
diff
changeset
|
2 |
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4459
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4459
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4459
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_SERVICES_MEMORYMANAGER_HPP |
26 |
#define SHARE_VM_SERVICES_MEMORYMANAGER_HPP |
|
27 |
||
28 |
#include "memory/allocation.hpp" |
|
29 |
#include "runtime/timer.hpp" |
|
30 |
#include "services/memoryUsage.hpp" |
|
31 |
||
1 | 32 |
// A memory manager is responsible for managing one or more memory pools. |
33 |
// The garbage collector is one type of memory managers responsible |
|
34 |
// for reclaiming memory occupied by unreachable objects. A Java virtual |
|
35 |
// machine may have one or more memory managers. It may |
|
36 |
// add or remove memory managers during execution. |
|
37 |
// A memory pool can be managed by more than one memory managers. |
|
38 |
||
39 |
class MemoryPool; |
|
40 |
class GCMemoryManager; |
|
41 |
class OopClosure; |
|
42 |
||
13195 | 43 |
class MemoryManager : public CHeapObj<mtInternal> { |
1 | 44 |
private: |
45 |
enum { |
|
46 |
max_num_pools = 10 |
|
47 |
}; |
|
48 |
||
49 |
MemoryPool* _pools[max_num_pools]; |
|
50 |
int _num_pools; |
|
51 |
||
52 |
protected: |
|
53 |
volatile instanceOop _memory_mgr_obj; |
|
54 |
||
55 |
public: |
|
56 |
MemoryManager(); |
|
57 |
||
58 |
int num_memory_pools() const { return _num_pools; } |
|
59 |
MemoryPool* get_memory_pool(int index) { |
|
60 |
assert(index >= 0 && index < _num_pools, "Invalid index"); |
|
61 |
return _pools[index]; |
|
62 |
} |
|
63 |
||
64 |
void add_pool(MemoryPool* pool); |
|
65 |
||
66 |
bool is_manager(instanceHandle mh) { return mh() == _memory_mgr_obj; } |
|
67 |
||
68 |
virtual instanceOop get_memory_manager_instance(TRAPS); |
|
69 |
virtual bool is_gc_memory_manager() { return false; } |
|
70 |
virtual const char* name() = 0; |
|
71 |
||
72 |
// GC support |
|
73 |
void oops_do(OopClosure* f); |
|
74 |
||
75 |
// Static factory methods to get a memory manager of a specific type |
|
76 |
static MemoryManager* get_code_cache_memory_manager(); |
|
18444
8adb4bc92f18
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
16453
diff
changeset
|
77 |
static MemoryManager* get_metaspace_memory_manager(); |
1 | 78 |
static GCMemoryManager* get_copy_memory_manager(); |
79 |
static GCMemoryManager* get_msc_memory_manager(); |
|
80 |
static GCMemoryManager* get_parnew_memory_manager(); |
|
81 |
static GCMemoryManager* get_cms_memory_manager(); |
|
82 |
static GCMemoryManager* get_psScavenge_memory_manager(); |
|
83 |
static GCMemoryManager* get_psMarkSweep_memory_manager(); |
|
4459
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
84 |
static GCMemoryManager* get_g1YoungGen_memory_manager(); |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
85 |
static GCMemoryManager* get_g1OldGen_memory_manager(); |
1 | 86 |
}; |
87 |
||
88 |
class CodeCacheMemoryManager : public MemoryManager { |
|
89 |
private: |
|
90 |
public: |
|
91 |
CodeCacheMemoryManager() : MemoryManager() {} |
|
92 |
||
30149 | 93 |
const char* name() { return "CodeCacheManager"; } |
1 | 94 |
}; |
95 |
||
18444
8adb4bc92f18
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
16453
diff
changeset
|
96 |
class MetaspaceMemoryManager : public MemoryManager { |
8adb4bc92f18
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
16453
diff
changeset
|
97 |
public: |
8adb4bc92f18
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
16453
diff
changeset
|
98 |
MetaspaceMemoryManager() : MemoryManager() {} |
8adb4bc92f18
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
16453
diff
changeset
|
99 |
|
30149 | 100 |
const char* name() { return "Metaspace Manager"; } |
18444
8adb4bc92f18
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
16453
diff
changeset
|
101 |
}; |
8adb4bc92f18
8013590: NPG: Add a memory pool MXBean for Metaspace
ehelin
parents:
16453
diff
changeset
|
102 |
|
11591
854c0dff3844
7066129: GarbageCollectorMXBean#getLastGcInfo leaks native memory
dsamersoff
parents:
9623
diff
changeset
|
103 |
class GCStatInfo : public ResourceObj { |
1 | 104 |
private: |
105 |
size_t _index; |
|
106 |
jlong _start_time; |
|
107 |
jlong _end_time; |
|
108 |
||
109 |
// We keep memory usage of all memory pools |
|
110 |
MemoryUsage* _before_gc_usage_array; |
|
111 |
MemoryUsage* _after_gc_usage_array; |
|
112 |
int _usage_array_size; |
|
113 |
||
114 |
void set_gc_usage(int pool_index, MemoryUsage, bool before_gc); |
|
115 |
||
116 |
public: |
|
117 |
GCStatInfo(int num_pools); |
|
118 |
~GCStatInfo(); |
|
119 |
||
120 |
size_t gc_index() { return _index; } |
|
121 |
jlong start_time() { return _start_time; } |
|
122 |
jlong end_time() { return _end_time; } |
|
123 |
int usage_array_size() { return _usage_array_size; } |
|
124 |
MemoryUsage before_gc_usage_for_pool(int pool_index) { |
|
125 |
assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking"); |
|
126 |
return _before_gc_usage_array[pool_index]; |
|
127 |
} |
|
128 |
MemoryUsage after_gc_usage_for_pool(int pool_index) { |
|
129 |
assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking"); |
|
130 |
return _after_gc_usage_array[pool_index]; |
|
131 |
} |
|
132 |
||
6245
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
133 |
MemoryUsage* before_gc_usage_array() { return _before_gc_usage_array; } |
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
134 |
MemoryUsage* after_gc_usage_array() { return _after_gc_usage_array; } |
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
135 |
|
1 | 136 |
void set_index(size_t index) { _index = index; } |
137 |
void set_start_time(jlong time) { _start_time = time; } |
|
138 |
void set_end_time(jlong time) { _end_time = time; } |
|
139 |
void set_before_gc_usage(int pool_index, MemoryUsage usage) { |
|
140 |
assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking"); |
|
141 |
set_gc_usage(pool_index, usage, true /* before gc */); |
|
142 |
} |
|
143 |
void set_after_gc_usage(int pool_index, MemoryUsage usage) { |
|
144 |
assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking"); |
|
145 |
set_gc_usage(pool_index, usage, false /* after gc */); |
|
146 |
} |
|
147 |
||
6245
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
148 |
void clear(); |
1 | 149 |
}; |
150 |
||
151 |
class GCMemoryManager : public MemoryManager { |
|
152 |
private: |
|
153 |
// TODO: We should unify the GCCounter and GCMemoryManager statistic |
|
154 |
size_t _num_collections; |
|
155 |
elapsedTimer _accumulated_timer; |
|
156 |
elapsedTimer _gc_timer; // for measuring every GC duration |
|
157 |
GCStatInfo* _last_gc_stat; |
|
6245
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
158 |
Mutex* _last_gc_lock; |
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
159 |
GCStatInfo* _current_gc_stat; |
1 | 160 |
int _num_gc_threads; |
9623
151c0b638488
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
7397
diff
changeset
|
161 |
volatile bool _notification_enabled; |
1 | 162 |
public: |
163 |
GCMemoryManager(); |
|
164 |
~GCMemoryManager(); |
|
165 |
||
166 |
void initialize_gc_stat_info(); |
|
167 |
||
168 |
bool is_gc_memory_manager() { return true; } |
|
169 |
jlong gc_time_ms() { return _accumulated_timer.milliseconds(); } |
|
170 |
size_t gc_count() { return _num_collections; } |
|
171 |
int num_gc_threads() { return _num_gc_threads; } |
|
172 |
void set_num_gc_threads(int count) { _num_gc_threads = count; } |
|
173 |
||
6245
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
174 |
void gc_begin(bool recordGCBeginTime, bool recordPreGCUsage, |
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
175 |
bool recordAccumulatedGCTime); |
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
176 |
void gc_end(bool recordPostGCUsage, bool recordAccumulatedGCTime, |
9623
151c0b638488
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
7397
diff
changeset
|
177 |
bool recordGCEndTime, bool countCollection, GCCause::Cause cause); |
1 | 178 |
|
179 |
void reset_gc_stat() { _num_collections = 0; _accumulated_timer.reset(); } |
|
6245
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
180 |
|
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
181 |
// Copy out _last_gc_stat to the given destination, returning |
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
182 |
// the collection count. Zero signifies no gc has taken place. |
c37d2cf6de1a
6581734: CMS Old Gen's collection usage is zero after GC which is incorrect
kevinw
parents:
5547
diff
changeset
|
183 |
size_t get_last_gc_stat(GCStatInfo* dest); |
1 | 184 |
|
9623
151c0b638488
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
7397
diff
changeset
|
185 |
void set_notification_enabled(bool enabled) { _notification_enabled = enabled; } |
151c0b638488
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents:
7397
diff
changeset
|
186 |
bool is_notification_enabled() { return _notification_enabled; } |
1 | 187 |
}; |
188 |
||
189 |
// These subclasses of GCMemoryManager are defined to include |
|
190 |
// GC-specific information. |
|
191 |
// TODO: Add GC-specific information |
|
192 |
class CopyMemoryManager : public GCMemoryManager { |
|
193 |
private: |
|
194 |
public: |
|
195 |
CopyMemoryManager() : GCMemoryManager() {} |
|
196 |
||
30149 | 197 |
const char* name() { return "Copy"; } |
1 | 198 |
}; |
199 |
||
200 |
class MSCMemoryManager : public GCMemoryManager { |
|
201 |
private: |
|
202 |
public: |
|
203 |
MSCMemoryManager() : GCMemoryManager() {} |
|
204 |
||
30149 | 205 |
const char* name() { return "MarkSweepCompact"; } |
1 | 206 |
}; |
207 |
||
208 |
class ParNewMemoryManager : public GCMemoryManager { |
|
209 |
private: |
|
210 |
public: |
|
211 |
ParNewMemoryManager() : GCMemoryManager() {} |
|
212 |
||
30149 | 213 |
const char* name() { return "ParNew"; } |
1 | 214 |
}; |
215 |
||
216 |
class CMSMemoryManager : public GCMemoryManager { |
|
217 |
private: |
|
218 |
public: |
|
219 |
CMSMemoryManager() : GCMemoryManager() {} |
|
220 |
||
30149 | 221 |
const char* name() { return "ConcurrentMarkSweep";} |
1 | 222 |
}; |
223 |
||
224 |
class PSScavengeMemoryManager : public GCMemoryManager { |
|
225 |
private: |
|
226 |
public: |
|
227 |
PSScavengeMemoryManager() : GCMemoryManager() {} |
|
228 |
||
30149 | 229 |
const char* name() { return "PS Scavenge"; } |
1 | 230 |
}; |
231 |
||
232 |
class PSMarkSweepMemoryManager : public GCMemoryManager { |
|
233 |
private: |
|
234 |
public: |
|
235 |
PSMarkSweepMemoryManager() : GCMemoryManager() {} |
|
236 |
||
30149 | 237 |
const char* name() { return "PS MarkSweep"; } |
1 | 238 |
}; |
4459
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
239 |
|
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
240 |
class G1YoungGenMemoryManager : public GCMemoryManager { |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
241 |
private: |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
242 |
public: |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
243 |
G1YoungGenMemoryManager() : GCMemoryManager() {} |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
244 |
|
30149 | 245 |
const char* name() { return "G1 Young Generation"; } |
4459
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
246 |
}; |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
247 |
|
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
248 |
class G1OldGenMemoryManager : public GCMemoryManager { |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
249 |
private: |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
250 |
public: |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
251 |
G1OldGenMemoryManager() : GCMemoryManager() {} |
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
252 |
|
30149 | 253 |
const char* name() { return "G1 Old Generation"; } |
4459
eb506d590394
6815790: G1: Missing MemoryPoolMXBeans with -XX:+UseG1GC
tonyp
parents:
1
diff
changeset
|
254 |
}; |
7397 | 255 |
|
256 |
#endif // SHARE_VM_SERVICES_MEMORYMANAGER_HPP |