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