Mercurial > hg > graal-jvmci-8
annotate src/share/vm/services/memTracker.hpp @ 10096:35f8765422b9
8010151: nsk/regression/b6653214 fails "assert(snapshot != NULL) failed: Worker should not be started"
Summary: Fixed a racing condition when shutting down NMT while worker thread is being started, also fixed a few mis-declared volatile pointers.
Reviewed-by: dholmes, dlong
author | zgu |
---|---|
date | Wed, 10 Apr 2013 08:55:50 -0400 |
parents | b5bae74160b7 |
children | 1f4355cee9a2 |
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 |
8810
06db4c0afbf3
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
7971
diff
changeset
|
87 static inline void set_autoShutdown(bool value) { } |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
88 static void shutdown(ShutdownReason reason) { } |
8842
b5bae74160b7
8010474: [parfait] Undefined return value of the functions in hotspot/src/share/vm/services/memTracker.hpp
zgu
parents:
8810
diff
changeset
|
89 static inline bool shutdown_in_progress() { return false; } |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
90 static bool print_memory_usage(BaselineOutputer& out, size_t unit, |
8842
b5bae74160b7
8010474: [parfait] Undefined return value of the functions in hotspot/src/share/vm/services/memTracker.hpp
zgu
parents:
8810
diff
changeset
|
91 bool summary_only = true) { return false; } |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
92 static bool compare_memory_usage(BaselineOutputer& out, size_t unit, |
8842
b5bae74160b7
8010474: [parfait] Undefined return value of the functions in hotspot/src/share/vm/services/memTracker.hpp
zgu
parents:
8810
diff
changeset
|
93 bool summary_only = true) { return false; } |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
94 |
8842
b5bae74160b7
8010474: [parfait] Undefined return value of the functions in hotspot/src/share/vm/services/memTracker.hpp
zgu
parents:
8810
diff
changeset
|
95 static bool wbtest_wait_for_data_merge() { return false; } |
7971
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
96 |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
97 static inline void sync() { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
98 static inline void thread_exiting(JavaThread* thread) { } |
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 |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
101 |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
102 #else // !INCLUDE_NMT |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
103 |
6197 | 104 #include "memory/allocation.hpp" |
105 #include "runtime/globals.hpp" | |
106 #include "runtime/mutex.hpp" | |
107 #include "runtime/os.hpp" | |
108 #include "runtime/thread.hpp" | |
109 #include "services/memPtr.hpp" | |
110 #include "services/memRecorder.hpp" | |
111 #include "services/memSnapshot.hpp" | |
112 #include "services/memTrackWorker.hpp" | |
113 | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6854
diff
changeset
|
114 extern bool NMT_track_callsite; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6854
diff
changeset
|
115 |
7971
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
116 #ifndef MAX_UNSIGNED_LONG |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
117 #define MAX_UNSIGNED_LONG (unsigned long)(-1) |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
118 #endif |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
119 |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6854
diff
changeset
|
120 #ifdef ASSERT |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6854
diff
changeset
|
121 #define DEBUG_CALLER_PC (NMT_track_callsite ? os::get_caller_pc(2) : 0) |
6197 | 122 #else |
123 #define DEBUG_CALLER_PC 0 | |
124 #endif | |
125 | |
126 // The thread closure walks threads to collect per-thread | |
127 // memory recorders at NMT sync point | |
128 class SyncThreadRecorderClosure : public ThreadClosure { | |
129 private: | |
130 int _thread_count; | |
131 | |
132 public: | |
133 SyncThreadRecorderClosure() { | |
134 _thread_count =0; | |
135 } | |
136 | |
137 void do_thread(Thread* thread); | |
138 int get_thread_count() const { | |
139 return _thread_count; | |
140 } | |
141 }; | |
142 | |
143 class BaselineOutputer; | |
144 class MemSnapshot; | |
145 class MemTrackWorker; | |
146 class Thread; | |
147 /* | |
148 * MemTracker is the 'gate' class to native memory tracking runtime. | |
149 */ | |
150 class MemTracker : AllStatic { | |
7464
ecd24264898b
8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents:
7180
diff
changeset
|
151 friend class GenerationData; |
6197 | 152 friend class MemTrackWorker; |
153 friend class MemSnapshot; | |
154 friend class SyncThreadRecorderClosure; | |
155 | |
156 // NMT state | |
157 enum NMTStates { | |
158 NMT_uninited, // not yet initialized | |
159 NMT_bootstrapping_single_thread, // bootstrapping, VM is in single thread mode | |
160 NMT_bootstrapping_multi_thread, // bootstrapping, VM is about to enter multi-thread mode | |
161 NMT_started, // NMT fully started | |
162 NMT_shutdown_pending, // shutdown pending | |
163 NMT_final_shutdown, // in final phase of shutdown | |
164 NMT_shutdown // shutdown | |
165 }; | |
166 | |
6770
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6768
diff
changeset
|
167 public: |
6197 | 168 // native memory tracking level |
169 enum NMTLevel { | |
170 NMT_off, // native memory tracking is off | |
171 NMT_summary, // don't track callsite | |
172 NMT_detail // track callsite also | |
173 }; | |
174 | |
175 enum ShutdownReason { | |
176 NMT_shutdown_none, // no shutdown requested | |
177 NMT_shutdown_user, // user requested shutdown | |
178 NMT_normal, // normal shutdown, process exit | |
179 NMT_out_of_memory, // shutdown due to out of memory | |
180 NMT_initialization, // shutdown due to initialization failure | |
181 NMT_use_malloc_only, // can not combine NMT with UseMallocOnly flag | |
182 NMT_error_reporting, // shutdown by vmError::report_and_die() | |
183 NMT_out_of_generation, // running out of generation queue | |
184 NMT_sequence_overflow // overflow the sequence number | |
185 }; | |
186 | |
187 public: | |
188 // initialize NMT tracking level from command line options, called | |
189 // from VM command line parsing code | |
190 static void init_tracking_options(const char* option_line); | |
191 | |
192 // if NMT is enabled to record memory activities | |
193 static inline bool is_on() { | |
194 return (_tracking_level >= NMT_summary && | |
195 _state >= NMT_bootstrapping_single_thread); | |
196 } | |
197 | |
6770
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6768
diff
changeset
|
198 static inline enum NMTLevel tracking_level() { |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6768
diff
changeset
|
199 return _tracking_level; |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6768
diff
changeset
|
200 } |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6768
diff
changeset
|
201 |
6197 | 202 // user readable reason for shutting down NMT |
203 static const char* reason() { | |
204 switch(_reason) { | |
205 case NMT_shutdown_none: | |
206 return "Native memory tracking is not enabled"; | |
207 case NMT_shutdown_user: | |
208 return "Native memory tracking has been shutdown by user"; | |
209 case NMT_normal: | |
210 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
|
211 case NMT_out_of_memory: |
f1f45dddb0bd
7181986: NMT ON: Assertion failure when running jdi ExpiredRequestDeletionTest
zgu
parents:
6197
diff
changeset
|
212 return "Native memory tracking has been shutdown due to out of native memory"; |
6197 | 213 case NMT_initialization: |
214 return "Native memory tracking failed to initialize"; | |
215 case NMT_error_reporting: | |
216 return "Native memory tracking has been shutdown due to error reporting"; | |
217 case NMT_out_of_generation: | |
218 return "Native memory tracking has been shutdown due to running out of generation buffer"; | |
219 case NMT_sequence_overflow: | |
220 return "Native memory tracking has been shutdown due to overflow the sequence number"; | |
221 case NMT_use_malloc_only: | |
222 return "Native memory tracking is not supported when UseMallocOnly is on"; | |
223 default: | |
224 ShouldNotReachHere(); | |
225 return NULL; | |
226 } | |
227 } | |
228 | |
229 // test if we can walk native stack | |
230 static bool can_walk_stack() { | |
231 // native stack is not walkable during bootstrapping on sparc | |
232 #if defined(SPARC) | |
233 return (_state == NMT_started); | |
234 #else | |
235 return (_state >= NMT_bootstrapping_single_thread && _state <= NMT_started); | |
236 #endif | |
237 } | |
238 | |
239 // if native memory tracking tracks callsite | |
240 static inline bool track_callsite() { return _tracking_level == NMT_detail; } | |
241 | |
8810
06db4c0afbf3
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
7971
diff
changeset
|
242 // NMT automatically shuts itself down under extreme situation by default. |
06db4c0afbf3
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
7971
diff
changeset
|
243 // When the value is set to false, NMT will try its best to stay alive, |
06db4c0afbf3
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
7971
diff
changeset
|
244 // even it has to slow down VM. |
06db4c0afbf3
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
7971
diff
changeset
|
245 static inline void set_autoShutdown(bool value) { |
06db4c0afbf3
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
7971
diff
changeset
|
246 AutoShutdownNMT = value; |
06db4c0afbf3
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
7971
diff
changeset
|
247 if (AutoShutdownNMT && _slowdown_calling_thread) { |
06db4c0afbf3
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
7971
diff
changeset
|
248 _slowdown_calling_thread = false; |
06db4c0afbf3
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
7971
diff
changeset
|
249 } |
06db4c0afbf3
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
7971
diff
changeset
|
250 } |
06db4c0afbf3
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
7971
diff
changeset
|
251 |
6197 | 252 // shutdown native memory tracking capability. Native memory tracking |
253 // can be shutdown by VM when it encounters low memory scenarios. | |
254 // Memory tracker should gracefully shutdown itself, and preserve the | |
255 // latest memory statistics for post morten diagnosis. | |
256 static void shutdown(ShutdownReason reason); | |
257 | |
258 // if there is shutdown requested | |
259 static inline bool shutdown_in_progress() { | |
260 return (_state >= NMT_shutdown_pending); | |
261 } | |
262 | |
263 // bootstrap native memory tracking, so it can start to collect raw data | |
264 // before worker thread can start | |
265 | |
266 // the first phase of bootstrapping, when VM still in single-threaded mode | |
267 static void bootstrap_single_thread(); | |
268 // the second phase of bootstrapping, VM is about or already in multi-threaded mode | |
269 static void bootstrap_multi_thread(); | |
270 | |
271 | |
272 // start() has to be called when VM still in single thread mode, but after | |
273 // command line option parsing is done. | |
274 static void start(); | |
275 | |
276 // record a 'malloc' call | |
277 static inline void record_malloc(address addr, size_t size, MEMFLAGS flags, | |
278 address pc = 0, Thread* thread = NULL) { | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6854
diff
changeset
|
279 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
|
280 assert(size > 0, "Sanity check"); |
6197 | 281 create_memory_record(addr, (flags|MemPointerRecord::malloc_tag()), size, pc, thread); |
282 } | |
283 } | |
284 // record a 'free' call | |
285 static inline void record_free(address addr, MEMFLAGS flags, Thread* thread = NULL) { | |
286 if (is_on() && NMT_CAN_TRACK(flags)) { | |
287 create_memory_record(addr, MemPointerRecord::free_tag(), 0, 0, thread); | |
288 } | |
289 } | |
290 // record a 'realloc' call | |
291 static inline void record_realloc(address old_addr, address new_addr, size_t size, | |
292 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
|
293 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
|
294 assert(size > 0, "Sanity check"); |
6197 | 295 record_free(old_addr, flags, thread); |
296 record_malloc(new_addr, size, flags, pc, thread); | |
297 } | |
298 } | |
299 | |
6979
fb3190e77d3c
8001592: NMT: assertion failed: assert(_amount >= amt) failed: Just check: memBaseline.hpp:180
zgu
parents:
6882
diff
changeset
|
300 // record arena memory size |
6197 | 301 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
|
302 // we add a positive offset to arena address, so we can have arena memory record |
6197 | 303 // sorted after arena record |
304 if (is_on() && !UseMallocOnly) { | |
6768
716e6ef4482a
7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents:
6741
diff
changeset
|
305 assert(addr != NULL, "Sanity check"); |
6197 | 306 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
|
307 DEBUG_CALLER_PC, NULL); |
6197 | 308 } |
309 } | |
310 | |
311 // record a virtual memory 'reserve' call | |
312 static inline void record_virtual_memory_reserve(address addr, size_t size, | |
313 address pc = 0, Thread* thread = NULL) { | |
314 if (is_on()) { | |
6768
716e6ef4482a
7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents:
6741
diff
changeset
|
315 assert(size > 0, "Sanity check"); |
6197 | 316 create_memory_record(addr, MemPointerRecord::virtual_memory_reserve_tag(), |
317 size, pc, thread); | |
318 } | |
319 } | |
320 | |
6741
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
321 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
|
322 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
|
323 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
|
324 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
|
325 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
|
326 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
|
327 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
|
328 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
|
329 } |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
330 } |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
331 |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
332 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
|
333 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
|
334 assert(size > 0 && thr != NULL, "Sanity check"); |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6854
diff
changeset
|
335 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
|
336 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
|
337 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
|
338 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
|
339 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
|
340 } |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
341 } |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
342 |
6197 | 343 // record a virtual memory 'commit' call |
344 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
|
345 address pc, Thread* thread = NULL) { |
6197 | 346 if (is_on()) { |
6768
716e6ef4482a
7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents:
6741
diff
changeset
|
347 assert(size > 0, "Sanity check"); |
6197 | 348 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
|
349 size, pc, thread); |
6197 | 350 } |
351 } | |
352 | |
353 // record a virtual memory 'uncommit' call | |
354 static inline void record_virtual_memory_uncommit(address addr, size_t size, | |
355 Thread* thread = NULL) { | |
356 if (is_on()) { | |
6768
716e6ef4482a
7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents:
6741
diff
changeset
|
357 assert(size > 0, "Sanity check"); |
6197 | 358 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
|
359 size, DEBUG_CALLER_PC, thread); |
6197 | 360 } |
361 } | |
362 | |
363 // record a virtual memory 'release' call | |
364 static inline void record_virtual_memory_release(address addr, size_t size, | |
365 Thread* thread = NULL) { | |
366 if (is_on()) { | |
6768
716e6ef4482a
7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents:
6741
diff
changeset
|
367 assert(size > 0, "Sanity check"); |
6197 | 368 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
|
369 size, DEBUG_CALLER_PC, thread); |
6197 | 370 } |
371 } | |
372 | |
373 // record memory type on virtual memory base address | |
374 static inline void record_virtual_memory_type(address base, MEMFLAGS flags, | |
375 Thread* thread = NULL) { | |
376 if (is_on()) { | |
377 assert(base > 0, "wrong base address"); | |
378 assert((flags & (~mt_masks)) == 0, "memory type only"); | |
379 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
|
380 0, DEBUG_CALLER_PC, thread); |
6197 | 381 } |
382 } | |
383 | |
384 | |
385 // create memory baseline of current memory snapshot | |
386 static bool baseline(); | |
387 // is there a memory baseline | |
388 static bool has_baseline() { | |
389 return _baseline.baselined(); | |
390 } | |
391 | |
392 // print memory usage from current snapshot | |
393 static bool print_memory_usage(BaselineOutputer& out, size_t unit, | |
394 bool summary_only = true); | |
395 // compare memory usage between current snapshot and baseline | |
396 static bool compare_memory_usage(BaselineOutputer& out, size_t unit, | |
397 bool summary_only = true); | |
398 | |
7971
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
399 // the version for whitebox testing support, it ensures that all memory |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
400 // activities before this method call, are reflected in the snapshot |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
401 // database. |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
402 static bool wbtest_wait_for_data_merge(); |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
403 |
6197 | 404 // sync is called within global safepoint to synchronize nmt data |
405 static void sync(); | |
406 | |
407 // called when a thread is about to exit | |
408 static void thread_exiting(JavaThread* thread); | |
409 | |
410 // retrieve global snapshot | |
411 static MemSnapshot* get_snapshot() { | |
412 if (shutdown_in_progress()) { | |
413 return NULL; | |
414 } | |
415 return _snapshot; | |
416 } | |
417 | |
418 // print tracker stats | |
419 NOT_PRODUCT(static void print_tracker_stats(outputStream* st);) | |
420 NOT_PRODUCT(static void walk_stack(int toSkip, char* buf, int len);) | |
421 | |
422 private: | |
423 // start native memory tracking worker thread | |
10096
35f8765422b9
8010151: nsk/regression/b6653214 fails "assert(snapshot != NULL) failed: Worker should not be started"
zgu
parents:
8842
diff
changeset
|
424 static bool start_worker(MemSnapshot* snapshot); |
6197 | 425 |
426 // called by worker thread to complete shutdown process | |
427 static void final_shutdown(); | |
428 | |
429 protected: | |
430 // retrieve per-thread recorder of the specified thread. | |
431 // if the recorder is full, it will be enqueued to overflow | |
432 // queue, a new recorder is acquired from recorder pool or a | |
433 // new instance is created. | |
434 // when thread == NULL, it means global recorder | |
435 static MemRecorder* get_thread_recorder(JavaThread* thread); | |
436 | |
437 // per-thread recorder pool | |
438 static void release_thread_recorder(MemRecorder* rec); | |
439 static void delete_all_pooled_recorders(); | |
440 | |
441 // pending recorder queue. Recorders are queued to pending queue | |
442 // when they are overflowed or collected at nmt sync point. | |
443 static void enqueue_pending_recorder(MemRecorder* rec); | |
444 static MemRecorder* get_pending_recorders(); | |
445 static void delete_all_pending_recorders(); | |
446 | |
447 private: | |
448 // retrieve a pooled memory record or create new one if there is not | |
449 // one available | |
450 static MemRecorder* get_new_or_pooled_instance(); | |
451 static void create_memory_record(address addr, MEMFLAGS type, | |
452 size_t size, address pc, Thread* thread); | |
453 static void create_record_in_recorder(address addr, MEMFLAGS type, | |
6231 | 454 size_t size, address pc, JavaThread* thread); |
6197 | 455 |
7971
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
456 static void set_current_processing_generation(unsigned long generation) { |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
457 _worker_thread_idle = false; |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
458 _processing_generation = generation; |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
459 } |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
460 |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
461 static void report_worker_idle() { |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
462 _worker_thread_idle = true; |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
463 } |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
464 |
6197 | 465 private: |
466 // global memory snapshot | |
467 static MemSnapshot* _snapshot; | |
468 | |
469 // a memory baseline of snapshot | |
470 static MemBaseline _baseline; | |
471 | |
472 // query lock | |
6232
f1f45dddb0bd
7181986: NMT ON: Assertion failure when running jdi ExpiredRequestDeletionTest
zgu
parents:
6197
diff
changeset
|
473 static Mutex* _query_lock; |
6197 | 474 |
475 // a thread can start to allocate memory before it is attached | |
476 // to VM 'Thread', those memory activities are recorded here. | |
477 // ThreadCritical is required to guard this global recorder. | |
10096
35f8765422b9
8010151: nsk/regression/b6653214 fails "assert(snapshot != NULL) failed: Worker should not be started"
zgu
parents:
8842
diff
changeset
|
478 static MemRecorder* volatile _global_recorder; |
6197 | 479 |
480 // main thread id | |
481 debug_only(static intx _main_thread_tid;) | |
482 | |
483 // pending recorders to be merged | |
10096
35f8765422b9
8010151: nsk/regression/b6653214 fails "assert(snapshot != NULL) failed: Worker should not be started"
zgu
parents:
8842
diff
changeset
|
484 static MemRecorder* volatile _merge_pending_queue; |
6197 | 485 |
486 NOT_PRODUCT(static volatile jint _pending_recorder_count;) | |
487 | |
488 // pooled memory recorders | |
10096
35f8765422b9
8010151: nsk/regression/b6653214 fails "assert(snapshot != NULL) failed: Worker should not be started"
zgu
parents:
8842
diff
changeset
|
489 static MemRecorder* volatile _pooled_recorders; |
6197 | 490 |
491 // memory recorder pool management, uses following | |
492 // counter to determine if a released memory recorder | |
493 // should be pooled | |
494 | |
495 // latest thread count | |
496 static int _thread_count; | |
497 // pooled recorder count | |
498 static volatile jint _pooled_recorder_count; | |
499 | |
500 | |
501 // worker thread to merge pending recorders into snapshot | |
502 static MemTrackWorker* _worker_thread; | |
503 | |
504 // how many safepoints we skipped without entering sync point | |
505 static int _sync_point_skip_count; | |
506 | |
507 // if the tracker is properly intialized | |
508 static bool _is_tracker_ready; | |
509 // tracking level (off, summary and detail) | |
510 static enum NMTLevel _tracking_level; | |
511 | |
512 // current nmt state | |
513 static volatile enum NMTStates _state; | |
514 // the reason for shutting down nmt | |
515 static enum ShutdownReason _reason; | |
7971
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
516 // the generation that NMT is processing |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
517 static volatile unsigned long _processing_generation; |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
518 // although NMT is still procesing current generation, but |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
519 // there is not more recorder to process, set idle state |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
520 static volatile bool _worker_thread_idle; |
8810
06db4c0afbf3
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
7971
diff
changeset
|
521 |
06db4c0afbf3
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
7971
diff
changeset
|
522 // if NMT should slow down calling thread to allow |
06db4c0afbf3
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
7971
diff
changeset
|
523 // worker thread to catch up |
06db4c0afbf3
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
7971
diff
changeset
|
524 static volatile bool _slowdown_calling_thread; |
6197 | 525 }; |
526 | |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
527 #endif // !INCLUDE_NMT |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
528 |
6197 | 529 #endif // SHARE_VM_SERVICES_MEM_TRACKER_HPP |