Mercurial > hg > truffle
annotate src/share/vm/services/memTracker.hpp @ 7788:dbbe8ce3bfa5
commands: accept 'server0' as a vm, accept version number which have '-...' suffix (-internal, -ea...)
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Wed, 13 Feb 2013 18:33:54 +0100 |
parents | ecd24264898b |
children | 4102b59539ce |
rev | line source |
---|---|
6197 | 1 /* |
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. | |
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 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 * | |
23 */ | |
24 | |
25 #ifndef SHARE_VM_SERVICES_MEM_TRACKER_HPP | |
26 #define SHARE_VM_SERVICES_MEM_TRACKER_HPP | |
27 | |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
28 #include "utilities/macros.hpp" |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
29 |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
30 #if !INCLUDE_NMT |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
31 |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
32 #include "utilities/ostream.hpp" |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
33 |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
34 class BaselineOutputer : public StackObj { |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
35 |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
36 }; |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
37 |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
38 class BaselineTTYOutputer : public BaselineOutputer { |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
39 public: |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
40 BaselineTTYOutputer(outputStream* st) { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
41 }; |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
42 |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
43 class MemTracker : AllStatic { |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
44 public: |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
45 enum ShutdownReason { |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
46 NMT_shutdown_none, // no shutdown requested |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
47 NMT_shutdown_user, // user requested shutdown |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
48 NMT_normal, // normal shutdown, process exit |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
49 NMT_out_of_memory, // shutdown due to out of memory |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
50 NMT_initialization, // shutdown due to initialization failure |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
51 NMT_use_malloc_only, // can not combine NMT with UseMallocOnly flag |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
52 NMT_error_reporting, // shutdown by vmError::report_and_die() |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
53 NMT_out_of_generation, // running out of generation queue |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
54 NMT_sequence_overflow // overflow the sequence number |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
55 }; |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
56 |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
57 |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
58 public: |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
59 static inline void init_tracking_options(const char* option_line) { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
60 static inline bool is_on() { return false; } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
61 static const char* reason() { return "Native memory tracking is not implemented"; } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
62 static inline bool can_walk_stack() { return false; } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
63 |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
64 static inline void bootstrap_single_thread() { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
65 static inline void bootstrap_multi_thread() { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
66 static inline void start() { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
67 |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
68 static inline void record_malloc(address addr, size_t size, MEMFLAGS flags, |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
69 address pc = 0, Thread* thread = NULL) { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
70 static inline void record_free(address addr, MEMFLAGS flags, Thread* thread = NULL) { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
71 static inline void record_realloc(address old_addr, address new_addr, size_t size, |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
72 MEMFLAGS flags, address pc = 0, Thread* thread = NULL) { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
73 static inline void record_arena_size(address addr, size_t size) { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
74 static inline void record_virtual_memory_reserve(address addr, size_t size, |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
75 address pc = 0, Thread* thread = NULL) { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
76 static inline void record_virtual_memory_commit(address addr, size_t size, |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
77 address pc = 0, Thread* thread = NULL) { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
78 static inline void record_virtual_memory_uncommit(address addr, size_t size, |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
79 Thread* thread = NULL) { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
80 static inline void record_virtual_memory_release(address addr, size_t size, |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
81 Thread* thread = NULL) { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
82 static inline void record_virtual_memory_type(address base, MEMFLAGS flags, |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
83 Thread* thread = NULL) { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
84 static inline bool baseline() { return false; } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
85 static inline bool has_baseline() { return false; } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
86 |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
87 static void shutdown(ShutdownReason reason) { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
88 static inline bool shutdown_in_progress() { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
89 static bool print_memory_usage(BaselineOutputer& out, size_t unit, |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
90 bool summary_only = true) { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
91 static bool compare_memory_usage(BaselineOutputer& out, size_t unit, |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
92 bool summary_only = true) { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
93 |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
94 static inline void sync() { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
95 static inline void thread_exiting(JavaThread* thread) { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
96 |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
97 }; |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
98 |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
99 |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
100 #else // !INCLUDE_NMT |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
101 |
6197 | 102 #include "memory/allocation.hpp" |
103 #include "runtime/globals.hpp" | |
104 #include "runtime/mutex.hpp" | |
105 #include "runtime/os.hpp" | |
106 #include "runtime/thread.hpp" | |
107 #include "services/memPtr.hpp" | |
108 #include "services/memRecorder.hpp" | |
109 #include "services/memSnapshot.hpp" | |
110 #include "services/memTrackWorker.hpp" | |
111 | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6854
diff
changeset
|
112 extern bool NMT_track_callsite; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6854
diff
changeset
|
113 |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6854
diff
changeset
|
114 #ifdef ASSERT |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6854
diff
changeset
|
115 #define DEBUG_CALLER_PC (NMT_track_callsite ? os::get_caller_pc(2) : 0) |
6197 | 116 #else |
117 #define DEBUG_CALLER_PC 0 | |
118 #endif | |
119 | |
120 // The thread closure walks threads to collect per-thread | |
121 // memory recorders at NMT sync point | |
122 class SyncThreadRecorderClosure : public ThreadClosure { | |
123 private: | |
124 int _thread_count; | |
125 | |
126 public: | |
127 SyncThreadRecorderClosure() { | |
128 _thread_count =0; | |
129 } | |
130 | |
131 void do_thread(Thread* thread); | |
132 int get_thread_count() const { | |
133 return _thread_count; | |
134 } | |
135 }; | |
136 | |
137 class BaselineOutputer; | |
138 class MemSnapshot; | |
139 class MemTrackWorker; | |
140 class Thread; | |
141 /* | |
142 * MemTracker is the 'gate' class to native memory tracking runtime. | |
143 */ | |
144 class MemTracker : AllStatic { | |
7464
ecd24264898b
8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents:
7180
diff
changeset
|
145 friend class GenerationData; |
6197 | 146 friend class MemTrackWorker; |
147 friend class MemSnapshot; | |
148 friend class SyncThreadRecorderClosure; | |
149 | |
150 // NMT state | |
151 enum NMTStates { | |
152 NMT_uninited, // not yet initialized | |
153 NMT_bootstrapping_single_thread, // bootstrapping, VM is in single thread mode | |
154 NMT_bootstrapping_multi_thread, // bootstrapping, VM is about to enter multi-thread mode | |
155 NMT_started, // NMT fully started | |
156 NMT_shutdown_pending, // shutdown pending | |
157 NMT_final_shutdown, // in final phase of shutdown | |
158 NMT_shutdown // shutdown | |
159 }; | |
160 | |
6770
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6768
diff
changeset
|
161 public: |
6197 | 162 // native memory tracking level |
163 enum NMTLevel { | |
164 NMT_off, // native memory tracking is off | |
165 NMT_summary, // don't track callsite | |
166 NMT_detail // track callsite also | |
167 }; | |
168 | |
169 enum ShutdownReason { | |
170 NMT_shutdown_none, // no shutdown requested | |
171 NMT_shutdown_user, // user requested shutdown | |
172 NMT_normal, // normal shutdown, process exit | |
173 NMT_out_of_memory, // shutdown due to out of memory | |
174 NMT_initialization, // shutdown due to initialization failure | |
175 NMT_use_malloc_only, // can not combine NMT with UseMallocOnly flag | |
176 NMT_error_reporting, // shutdown by vmError::report_and_die() | |
177 NMT_out_of_generation, // running out of generation queue | |
178 NMT_sequence_overflow // overflow the sequence number | |
179 }; | |
180 | |
181 public: | |
182 // initialize NMT tracking level from command line options, called | |
183 // from VM command line parsing code | |
184 static void init_tracking_options(const char* option_line); | |
185 | |
186 // if NMT is enabled to record memory activities | |
187 static inline bool is_on() { | |
188 return (_tracking_level >= NMT_summary && | |
189 _state >= NMT_bootstrapping_single_thread); | |
190 } | |
191 | |
6770
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6768
diff
changeset
|
192 static inline enum NMTLevel tracking_level() { |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6768
diff
changeset
|
193 return _tracking_level; |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6768
diff
changeset
|
194 } |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6768
diff
changeset
|
195 |
6197 | 196 // user readable reason for shutting down NMT |
197 static const char* reason() { | |
198 switch(_reason) { | |
199 case NMT_shutdown_none: | |
200 return "Native memory tracking is not enabled"; | |
201 case NMT_shutdown_user: | |
202 return "Native memory tracking has been shutdown by user"; | |
203 case NMT_normal: | |
204 return "Native memory tracking has been shutdown due to process exiting"; | |
6232
f1f45dddb0bd
7181986: NMT ON: Assertion failure when running jdi ExpiredRequestDeletionTest
zgu
parents:
6197
diff
changeset
|
205 case NMT_out_of_memory: |
f1f45dddb0bd
7181986: NMT ON: Assertion failure when running jdi ExpiredRequestDeletionTest
zgu
parents:
6197
diff
changeset
|
206 return "Native memory tracking has been shutdown due to out of native memory"; |
6197 | 207 case NMT_initialization: |
208 return "Native memory tracking failed to initialize"; | |
209 case NMT_error_reporting: | |
210 return "Native memory tracking has been shutdown due to error reporting"; | |
211 case NMT_out_of_generation: | |
212 return "Native memory tracking has been shutdown due to running out of generation buffer"; | |
213 case NMT_sequence_overflow: | |
214 return "Native memory tracking has been shutdown due to overflow the sequence number"; | |
215 case NMT_use_malloc_only: | |
216 return "Native memory tracking is not supported when UseMallocOnly is on"; | |
217 default: | |
218 ShouldNotReachHere(); | |
219 return NULL; | |
220 } | |
221 } | |
222 | |
223 // test if we can walk native stack | |
224 static bool can_walk_stack() { | |
225 // native stack is not walkable during bootstrapping on sparc | |
226 #if defined(SPARC) | |
227 return (_state == NMT_started); | |
228 #else | |
229 return (_state >= NMT_bootstrapping_single_thread && _state <= NMT_started); | |
230 #endif | |
231 } | |
232 | |
233 // if native memory tracking tracks callsite | |
234 static inline bool track_callsite() { return _tracking_level == NMT_detail; } | |
235 | |
236 // shutdown native memory tracking capability. Native memory tracking | |
237 // can be shutdown by VM when it encounters low memory scenarios. | |
238 // Memory tracker should gracefully shutdown itself, and preserve the | |
239 // latest memory statistics for post morten diagnosis. | |
240 static void shutdown(ShutdownReason reason); | |
241 | |
242 // if there is shutdown requested | |
243 static inline bool shutdown_in_progress() { | |
244 return (_state >= NMT_shutdown_pending); | |
245 } | |
246 | |
247 // bootstrap native memory tracking, so it can start to collect raw data | |
248 // before worker thread can start | |
249 | |
250 // the first phase of bootstrapping, when VM still in single-threaded mode | |
251 static void bootstrap_single_thread(); | |
252 // the second phase of bootstrapping, VM is about or already in multi-threaded mode | |
253 static void bootstrap_multi_thread(); | |
254 | |
255 | |
256 // start() has to be called when VM still in single thread mode, but after | |
257 // command line option parsing is done. | |
258 static void start(); | |
259 | |
260 // record a 'malloc' call | |
261 static inline void record_malloc(address addr, size_t size, MEMFLAGS flags, | |
262 address pc = 0, Thread* thread = NULL) { | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6854
diff
changeset
|
263 if (is_on() && NMT_CAN_TRACK(flags)) { |
6768
716e6ef4482a
7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents:
6741
diff
changeset
|
264 assert(size > 0, "Sanity check"); |
6197 | 265 create_memory_record(addr, (flags|MemPointerRecord::malloc_tag()), size, pc, thread); |
266 } | |
267 } | |
268 // record a 'free' call | |
269 static inline void record_free(address addr, MEMFLAGS flags, Thread* thread = NULL) { | |
270 if (is_on() && NMT_CAN_TRACK(flags)) { | |
271 create_memory_record(addr, MemPointerRecord::free_tag(), 0, 0, thread); | |
272 } | |
273 } | |
274 // record a 'realloc' call | |
275 static inline void record_realloc(address old_addr, address new_addr, size_t size, | |
276 MEMFLAGS flags, address pc = 0, Thread* thread = NULL) { | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6854
diff
changeset
|
277 if (is_on() && NMT_CAN_TRACK(flags)) { |
6768
716e6ef4482a
7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents:
6741
diff
changeset
|
278 assert(size > 0, "Sanity check"); |
6197 | 279 record_free(old_addr, flags, thread); |
280 record_malloc(new_addr, size, flags, pc, thread); | |
281 } | |
282 } | |
283 | |
6979
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
284 // record arena memory size |
6197 | 285 static inline void record_arena_size(address addr, size_t size) { |
6979
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
286 // we add a positive offset to arena address, so we can have arena memory record |
6197 | 287 // sorted after arena record |
288 if (is_on() && !UseMallocOnly) { | |
6768
716e6ef4482a
7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents:
6741
diff
changeset
|
289 assert(addr != NULL, "Sanity check"); |
6197 | 290 create_memory_record((addr + sizeof(void*)), MemPointerRecord::arena_size_tag(), size, |
6979
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
291 DEBUG_CALLER_PC, NULL); |
6197 | 292 } |
293 } | |
294 | |
295 // record a virtual memory 'reserve' call | |
296 static inline void record_virtual_memory_reserve(address addr, size_t size, | |
297 address pc = 0, Thread* thread = NULL) { | |
298 if (is_on()) { | |
6768
716e6ef4482a
7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents:
6741
diff
changeset
|
299 assert(size > 0, "Sanity check"); |
6197 | 300 create_memory_record(addr, MemPointerRecord::virtual_memory_reserve_tag(), |
301 size, pc, thread); | |
302 } | |
303 } | |
304 | |
6741
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
305 static inline void record_thread_stack(address addr, size_t size, Thread* thr, |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
306 address pc = 0) { |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
307 if (is_on()) { |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
308 assert(size > 0 && thr != NULL, "Sanity check"); |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
309 create_memory_record(addr, MemPointerRecord::virtual_memory_reserve_tag() | mtThreadStack, |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
310 size, pc, thr); |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
311 create_memory_record(addr, MemPointerRecord::virtual_memory_commit_tag() | mtThreadStack, |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
312 size, pc, thr); |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
313 } |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
314 } |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
315 |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
316 static inline void release_thread_stack(address addr, size_t size, Thread* thr) { |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
317 if (is_on()) { |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
318 assert(size > 0 && thr != NULL, "Sanity check"); |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6854
diff
changeset
|
319 assert(!thr->is_Java_thread(), "too early"); |
6741
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
320 create_memory_record(addr, MemPointerRecord::virtual_memory_uncommit_tag() | mtThreadStack, |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
321 size, DEBUG_CALLER_PC, thr); |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
322 create_memory_record(addr, MemPointerRecord::virtual_memory_release_tag() | mtThreadStack, |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
323 size, DEBUG_CALLER_PC, thr); |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
324 } |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
325 } |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
326 |
6197 | 327 // record a virtual memory 'commit' call |
328 static inline void record_virtual_memory_commit(address addr, size_t size, | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6854
diff
changeset
|
329 address pc, Thread* thread = NULL) { |
6197 | 330 if (is_on()) { |
6768
716e6ef4482a
7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents:
6741
diff
changeset
|
331 assert(size > 0, "Sanity check"); |
6197 | 332 create_memory_record(addr, MemPointerRecord::virtual_memory_commit_tag(), |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6854
diff
changeset
|
333 size, pc, thread); |
6197 | 334 } |
335 } | |
336 | |
337 // record a virtual memory 'uncommit' call | |
338 static inline void record_virtual_memory_uncommit(address addr, size_t size, | |
339 Thread* thread = NULL) { | |
340 if (is_on()) { | |
6768
716e6ef4482a
7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents:
6741
diff
changeset
|
341 assert(size > 0, "Sanity check"); |
6197 | 342 create_memory_record(addr, MemPointerRecord::virtual_memory_uncommit_tag(), |
6741
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
343 size, DEBUG_CALLER_PC, thread); |
6197 | 344 } |
345 } | |
346 | |
347 // record a virtual memory 'release' call | |
348 static inline void record_virtual_memory_release(address addr, size_t size, | |
349 Thread* thread = NULL) { | |
350 if (is_on()) { | |
6768
716e6ef4482a
7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents:
6741
diff
changeset
|
351 assert(size > 0, "Sanity check"); |
6197 | 352 create_memory_record(addr, MemPointerRecord::virtual_memory_release_tag(), |
6741
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
353 size, DEBUG_CALLER_PC, thread); |
6197 | 354 } |
355 } | |
356 | |
357 // record memory type on virtual memory base address | |
358 static inline void record_virtual_memory_type(address base, MEMFLAGS flags, | |
359 Thread* thread = NULL) { | |
360 if (is_on()) { | |
361 assert(base > 0, "wrong base address"); | |
362 assert((flags & (~mt_masks)) == 0, "memory type only"); | |
363 create_memory_record(base, (flags | MemPointerRecord::virtual_memory_type_tag()), | |
6741
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
364 0, DEBUG_CALLER_PC, thread); |
6197 | 365 } |
366 } | |
367 | |
368 | |
369 // create memory baseline of current memory snapshot | |
370 static bool baseline(); | |
371 // is there a memory baseline | |
372 static bool has_baseline() { | |
373 return _baseline.baselined(); | |
374 } | |
375 | |
376 // print memory usage from current snapshot | |
377 static bool print_memory_usage(BaselineOutputer& out, size_t unit, | |
378 bool summary_only = true); | |
379 // compare memory usage between current snapshot and baseline | |
380 static bool compare_memory_usage(BaselineOutputer& out, size_t unit, | |
381 bool summary_only = true); | |
382 | |
383 // sync is called within global safepoint to synchronize nmt data | |
384 static void sync(); | |
385 | |
386 // called when a thread is about to exit | |
387 static void thread_exiting(JavaThread* thread); | |
388 | |
389 // retrieve global snapshot | |
390 static MemSnapshot* get_snapshot() { | |
391 if (shutdown_in_progress()) { | |
392 return NULL; | |
393 } | |
394 return _snapshot; | |
395 } | |
396 | |
397 // print tracker stats | |
398 NOT_PRODUCT(static void print_tracker_stats(outputStream* st);) | |
399 NOT_PRODUCT(static void walk_stack(int toSkip, char* buf, int len);) | |
400 | |
401 private: | |
402 // start native memory tracking worker thread | |
403 static bool start_worker(); | |
404 | |
405 // called by worker thread to complete shutdown process | |
406 static void final_shutdown(); | |
407 | |
408 protected: | |
409 // retrieve per-thread recorder of the specified thread. | |
410 // if the recorder is full, it will be enqueued to overflow | |
411 // queue, a new recorder is acquired from recorder pool or a | |
412 // new instance is created. | |
413 // when thread == NULL, it means global recorder | |
414 static MemRecorder* get_thread_recorder(JavaThread* thread); | |
415 | |
416 // per-thread recorder pool | |
417 static void release_thread_recorder(MemRecorder* rec); | |
418 static void delete_all_pooled_recorders(); | |
419 | |
420 // pending recorder queue. Recorders are queued to pending queue | |
421 // when they are overflowed or collected at nmt sync point. | |
422 static void enqueue_pending_recorder(MemRecorder* rec); | |
423 static MemRecorder* get_pending_recorders(); | |
424 static void delete_all_pending_recorders(); | |
425 | |
426 private: | |
427 // retrieve a pooled memory record or create new one if there is not | |
428 // one available | |
429 static MemRecorder* get_new_or_pooled_instance(); | |
430 static void create_memory_record(address addr, MEMFLAGS type, | |
431 size_t size, address pc, Thread* thread); | |
432 static void create_record_in_recorder(address addr, MEMFLAGS type, | |
6231 | 433 size_t size, address pc, JavaThread* thread); |
6197 | 434 |
435 private: | |
436 // global memory snapshot | |
437 static MemSnapshot* _snapshot; | |
438 | |
439 // a memory baseline of snapshot | |
440 static MemBaseline _baseline; | |
441 | |
442 // query lock | |
6232
f1f45dddb0bd
7181986: NMT ON: Assertion failure when running jdi ExpiredRequestDeletionTest
zgu
parents:
6197
diff
changeset
|
443 static Mutex* _query_lock; |
6197 | 444 |
445 // a thread can start to allocate memory before it is attached | |
446 // to VM 'Thread', those memory activities are recorded here. | |
447 // ThreadCritical is required to guard this global recorder. | |
448 static MemRecorder* _global_recorder; | |
449 | |
450 // main thread id | |
451 debug_only(static intx _main_thread_tid;) | |
452 | |
453 // pending recorders to be merged | |
454 static volatile MemRecorder* _merge_pending_queue; | |
455 | |
456 NOT_PRODUCT(static volatile jint _pending_recorder_count;) | |
457 | |
458 // pooled memory recorders | |
459 static volatile MemRecorder* _pooled_recorders; | |
460 | |
461 // memory recorder pool management, uses following | |
462 // counter to determine if a released memory recorder | |
463 // should be pooled | |
464 | |
465 // latest thread count | |
466 static int _thread_count; | |
467 // pooled recorder count | |
468 static volatile jint _pooled_recorder_count; | |
469 | |
470 | |
471 // worker thread to merge pending recorders into snapshot | |
472 static MemTrackWorker* _worker_thread; | |
473 | |
474 // how many safepoints we skipped without entering sync point | |
475 static int _sync_point_skip_count; | |
476 | |
477 // if the tracker is properly intialized | |
478 static bool _is_tracker_ready; | |
479 // tracking level (off, summary and detail) | |
480 static enum NMTLevel _tracking_level; | |
481 | |
482 // current nmt state | |
483 static volatile enum NMTStates _state; | |
484 // the reason for shutting down nmt | |
485 static enum ShutdownReason _reason; | |
486 }; | |
487 | |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
488 #endif // !INCLUDE_NMT |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
489 |
6197 | 490 #endif // SHARE_VM_SERVICES_MEM_TRACKER_HPP |