Mercurial > hg > truffle
annotate src/share/vm/services/memTracker.hpp @ 14702:d4dd5204c0aa
Merge
author | ehelin |
---|---|
date | Fri, 14 Mar 2014 13:27:18 +0100 |
parents | 4c84d351cca9 |
children | 833b0f92429a |
rev | line source |
---|---|
6197 | 1 /* |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
6197 | 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 |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
57 class Tracker { |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
58 public: |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
59 void discard() { } |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
60 |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
61 void record(address addr, size_t size = 0, MEMFLAGS flags = mtNone, address pc = NULL) { } |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
62 void record(address old_addr, address new_addr, size_t size, |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
63 MEMFLAGS flags, address pc = NULL) { } |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
64 }; |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
65 |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
66 private: |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
67 static Tracker _tkr; |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
68 |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
69 |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
70 public: |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
71 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
|
72 static inline bool is_on() { return false; } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
73 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
|
74 static inline bool can_walk_stack() { return false; } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
75 |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
76 static inline void bootstrap_single_thread() { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
77 static inline void bootstrap_multi_thread() { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
78 static inline void start() { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
79 |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
80 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
|
81 address pc = 0, Thread* thread = NULL) { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
82 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
|
83 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
|
84 static inline void record_virtual_memory_reserve(address addr, size_t size, |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
85 MEMFLAGS flags, address pc = 0, Thread* thread = NULL) { } |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
86 static inline void record_virtual_memory_reserve_and_commit(address addr, size_t size, |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
87 MEMFLAGS flags, address pc = 0, Thread* thread = NULL) { } |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
88 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
|
89 address pc = 0, Thread* thread = NULL) { } |
12110
4c84d351cca9
8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents:
11090
diff
changeset
|
90 static inline void record_virtual_memory_release(address addr, size_t size, |
4c84d351cca9
8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents:
11090
diff
changeset
|
91 Thread* thread = NULL) { } |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
92 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
|
93 Thread* thread = NULL) { } |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
94 static inline Tracker get_realloc_tracker() { return _tkr; } |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
95 static inline Tracker get_virtual_memory_uncommit_tracker() { return _tkr; } |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
96 static inline Tracker get_virtual_memory_release_tracker() { return _tkr; } |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
97 static inline bool baseline() { return false; } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
98 static inline bool has_baseline() { return false; } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
99 |
8810
06db4c0afbf3
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
7971
diff
changeset
|
100 static inline void set_autoShutdown(bool value) { } |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
101 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
|
102 static inline bool shutdown_in_progress() { return false; } |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
103 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
|
104 bool summary_only = true) { return false; } |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
105 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
|
106 bool summary_only = true) { return false; } |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
107 |
8842
b5bae74160b7
8010474: [parfait] Undefined return value of the functions in hotspot/src/share/vm/services/memTracker.hpp
zgu
parents:
8810
diff
changeset
|
108 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
|
109 |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
110 static inline void sync() { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
111 static inline void thread_exiting(JavaThread* thread) { } |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
112 }; |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
113 |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
114 |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
115 #else // !INCLUDE_NMT |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
116 |
6197 | 117 #include "memory/allocation.hpp" |
118 #include "runtime/globals.hpp" | |
119 #include "runtime/mutex.hpp" | |
120 #include "runtime/os.hpp" | |
121 #include "runtime/thread.hpp" | |
122 #include "services/memPtr.hpp" | |
123 #include "services/memRecorder.hpp" | |
124 #include "services/memSnapshot.hpp" | |
125 #include "services/memTrackWorker.hpp" | |
126 | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6854
diff
changeset
|
127 extern bool NMT_track_callsite; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6854
diff
changeset
|
128 |
7971
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
129 #ifndef MAX_UNSIGNED_LONG |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
130 #define MAX_UNSIGNED_LONG (unsigned long)(-1) |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
131 #endif |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
132 |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6854
diff
changeset
|
133 #ifdef ASSERT |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6854
diff
changeset
|
134 #define DEBUG_CALLER_PC (NMT_track_callsite ? os::get_caller_pc(2) : 0) |
6197 | 135 #else |
136 #define DEBUG_CALLER_PC 0 | |
137 #endif | |
138 | |
139 // The thread closure walks threads to collect per-thread | |
140 // memory recorders at NMT sync point | |
141 class SyncThreadRecorderClosure : public ThreadClosure { | |
142 private: | |
143 int _thread_count; | |
144 | |
145 public: | |
146 SyncThreadRecorderClosure() { | |
147 _thread_count =0; | |
148 } | |
149 | |
150 void do_thread(Thread* thread); | |
151 int get_thread_count() const { | |
152 return _thread_count; | |
153 } | |
154 }; | |
155 | |
156 class BaselineOutputer; | |
157 class MemSnapshot; | |
158 class MemTrackWorker; | |
159 class Thread; | |
160 /* | |
161 * MemTracker is the 'gate' class to native memory tracking runtime. | |
162 */ | |
163 class MemTracker : AllStatic { | |
7464
ecd24264898b
8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents:
7180
diff
changeset
|
164 friend class GenerationData; |
6197 | 165 friend class MemTrackWorker; |
166 friend class MemSnapshot; | |
167 friend class SyncThreadRecorderClosure; | |
168 | |
169 // NMT state | |
170 enum NMTStates { | |
171 NMT_uninited, // not yet initialized | |
172 NMT_bootstrapping_single_thread, // bootstrapping, VM is in single thread mode | |
173 NMT_bootstrapping_multi_thread, // bootstrapping, VM is about to enter multi-thread mode | |
174 NMT_started, // NMT fully started | |
175 NMT_shutdown_pending, // shutdown pending | |
176 NMT_final_shutdown, // in final phase of shutdown | |
177 NMT_shutdown // shutdown | |
178 }; | |
179 | |
6770
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6768
diff
changeset
|
180 public: |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
181 class Tracker : public StackObj { |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
182 friend class MemTracker; |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
183 public: |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
184 enum MemoryOperation { |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
185 NoOp, // no op |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
186 Malloc, // malloc |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
187 Realloc, // realloc |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
188 Free, // free |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
189 Reserve, // virtual memory reserve |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
190 Commit, // virtual memory commit |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
191 ReserveAndCommit, // virtual memory reserve and commit |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
192 StackAlloc = ReserveAndCommit, // allocate thread stack |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
193 Type, // assign virtual memory type |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
194 Uncommit, // virtual memory uncommit |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
195 Release, // virtual memory release |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
196 ArenaSize, // set arena size |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
197 StackRelease // release thread stack |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
198 }; |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
199 |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
200 |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
201 protected: |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
202 Tracker(MemoryOperation op, Thread* thr = NULL); |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
203 |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
204 public: |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
205 void discard(); |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
206 |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
207 void record(address addr, size_t size = 0, MEMFLAGS flags = mtNone, address pc = NULL); |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
208 void record(address old_addr, address new_addr, size_t size, |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
209 MEMFLAGS flags, address pc = NULL); |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
210 |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
211 private: |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
212 bool _need_thread_critical_lock; |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
213 JavaThread* _java_thread; |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
214 MemoryOperation _op; // memory operation |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
215 jint _seq; // reserved sequence number |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
216 }; |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
217 |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
218 |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
219 public: |
6197 | 220 // native memory tracking level |
221 enum NMTLevel { | |
222 NMT_off, // native memory tracking is off | |
223 NMT_summary, // don't track callsite | |
224 NMT_detail // track callsite also | |
225 }; | |
226 | |
227 enum ShutdownReason { | |
228 NMT_shutdown_none, // no shutdown requested | |
229 NMT_shutdown_user, // user requested shutdown | |
230 NMT_normal, // normal shutdown, process exit | |
231 NMT_out_of_memory, // shutdown due to out of memory | |
232 NMT_initialization, // shutdown due to initialization failure | |
233 NMT_use_malloc_only, // can not combine NMT with UseMallocOnly flag | |
234 NMT_error_reporting, // shutdown by vmError::report_and_die() | |
235 NMT_out_of_generation, // running out of generation queue | |
236 NMT_sequence_overflow // overflow the sequence number | |
237 }; | |
238 | |
239 public: | |
240 // initialize NMT tracking level from command line options, called | |
241 // from VM command line parsing code | |
242 static void init_tracking_options(const char* option_line); | |
243 | |
244 // if NMT is enabled to record memory activities | |
245 static inline bool is_on() { | |
246 return (_tracking_level >= NMT_summary && | |
247 _state >= NMT_bootstrapping_single_thread); | |
248 } | |
249 | |
6770
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6768
diff
changeset
|
250 static inline enum NMTLevel tracking_level() { |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6768
diff
changeset
|
251 return _tracking_level; |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6768
diff
changeset
|
252 } |
9a86ddfc6c8f
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
6768
diff
changeset
|
253 |
6197 | 254 // user readable reason for shutting down NMT |
255 static const char* reason() { | |
256 switch(_reason) { | |
257 case NMT_shutdown_none: | |
258 return "Native memory tracking is not enabled"; | |
259 case NMT_shutdown_user: | |
260 return "Native memory tracking has been shutdown by user"; | |
261 case NMT_normal: | |
262 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
|
263 case NMT_out_of_memory: |
f1f45dddb0bd
7181986: NMT ON: Assertion failure when running jdi ExpiredRequestDeletionTest
zgu
parents:
6197
diff
changeset
|
264 return "Native memory tracking has been shutdown due to out of native memory"; |
6197 | 265 case NMT_initialization: |
266 return "Native memory tracking failed to initialize"; | |
267 case NMT_error_reporting: | |
268 return "Native memory tracking has been shutdown due to error reporting"; | |
269 case NMT_out_of_generation: | |
270 return "Native memory tracking has been shutdown due to running out of generation buffer"; | |
271 case NMT_sequence_overflow: | |
272 return "Native memory tracking has been shutdown due to overflow the sequence number"; | |
273 case NMT_use_malloc_only: | |
274 return "Native memory tracking is not supported when UseMallocOnly is on"; | |
275 default: | |
276 ShouldNotReachHere(); | |
277 return NULL; | |
278 } | |
279 } | |
280 | |
281 // test if we can walk native stack | |
282 static bool can_walk_stack() { | |
283 // native stack is not walkable during bootstrapping on sparc | |
284 #if defined(SPARC) | |
285 return (_state == NMT_started); | |
286 #else | |
287 return (_state >= NMT_bootstrapping_single_thread && _state <= NMT_started); | |
288 #endif | |
289 } | |
290 | |
291 // if native memory tracking tracks callsite | |
292 static inline bool track_callsite() { return _tracking_level == NMT_detail; } | |
293 | |
8810
06db4c0afbf3
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
7971
diff
changeset
|
294 // 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
|
295 // 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
|
296 // 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
|
297 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
|
298 AutoShutdownNMT = value; |
06db4c0afbf3
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
7971
diff
changeset
|
299 if (AutoShutdownNMT && _slowdown_calling_thread) { |
06db4c0afbf3
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
7971
diff
changeset
|
300 _slowdown_calling_thread = false; |
06db4c0afbf3
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
7971
diff
changeset
|
301 } |
06db4c0afbf3
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
7971
diff
changeset
|
302 } |
06db4c0afbf3
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
7971
diff
changeset
|
303 |
6197 | 304 // shutdown native memory tracking capability. Native memory tracking |
305 // can be shutdown by VM when it encounters low memory scenarios. | |
306 // Memory tracker should gracefully shutdown itself, and preserve the | |
307 // latest memory statistics for post morten diagnosis. | |
308 static void shutdown(ShutdownReason reason); | |
309 | |
310 // if there is shutdown requested | |
311 static inline bool shutdown_in_progress() { | |
312 return (_state >= NMT_shutdown_pending); | |
313 } | |
314 | |
315 // bootstrap native memory tracking, so it can start to collect raw data | |
316 // before worker thread can start | |
317 | |
318 // the first phase of bootstrapping, when VM still in single-threaded mode | |
319 static void bootstrap_single_thread(); | |
320 // the second phase of bootstrapping, VM is about or already in multi-threaded mode | |
321 static void bootstrap_multi_thread(); | |
322 | |
323 | |
324 // start() has to be called when VM still in single thread mode, but after | |
325 // command line option parsing is done. | |
326 static void start(); | |
327 | |
328 // record a 'malloc' call | |
329 static inline void record_malloc(address addr, size_t size, MEMFLAGS flags, | |
330 address pc = 0, Thread* thread = NULL) { | |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
331 Tracker tkr(Tracker::Malloc, thread); |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
332 tkr.record(addr, size, flags, pc); |
6197 | 333 } |
334 // record a 'free' call | |
335 static inline void record_free(address addr, MEMFLAGS flags, Thread* thread = NULL) { | |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
336 Tracker tkr(Tracker::Free, thread); |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
337 tkr.record(addr, 0, flags, DEBUG_CALLER_PC); |
6197 | 338 } |
339 | |
340 static inline void record_arena_size(address addr, size_t size) { | |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
341 Tracker tkr(Tracker::ArenaSize); |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
342 tkr.record(addr, size); |
6197 | 343 } |
344 | |
345 // record a virtual memory 'reserve' call | |
346 static inline void record_virtual_memory_reserve(address addr, size_t size, | |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
347 MEMFLAGS flags, address pc = 0, Thread* thread = NULL) { |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
348 assert(size > 0, "Sanity check"); |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
349 Tracker tkr(Tracker::Reserve, thread); |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
350 tkr.record(addr, size, flags, pc); |
6197 | 351 } |
352 | |
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 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
|
354 address pc = 0) { |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
355 Tracker tkr(Tracker::StackAlloc, thr); |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
356 tkr.record(addr, size, mtThreadStack, pc); |
6741
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
357 } |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
358 |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
359 static inline void release_thread_stack(address addr, size_t size, Thread* thr) { |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
360 Tracker tkr(Tracker::StackRelease, thr); |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
361 tkr.record(addr, size, mtThreadStack, DEBUG_CALLER_PC); |
6741
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
362 } |
33143ee07800
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
6599
diff
changeset
|
363 |
6197 | 364 // record a virtual memory 'commit' call |
365 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
|
366 address pc, Thread* thread = NULL) { |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
367 Tracker tkr(Tracker::Commit, thread); |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
368 tkr.record(addr, size, mtNone, pc); |
6197 | 369 } |
370 | |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
371 static inline void record_virtual_memory_reserve_and_commit(address addr, size_t size, |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
372 MEMFLAGS flags, address pc, Thread* thread = NULL) { |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
373 Tracker tkr(Tracker::ReserveAndCommit, thread); |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
374 tkr.record(addr, size, flags, pc); |
6197 | 375 } |
376 | |
12110
4c84d351cca9
8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents:
11090
diff
changeset
|
377 static inline void record_virtual_memory_release(address addr, size_t size, |
4c84d351cca9
8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents:
11090
diff
changeset
|
378 Thread* thread = NULL) { |
4c84d351cca9
8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents:
11090
diff
changeset
|
379 if (is_on()) { |
4c84d351cca9
8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents:
11090
diff
changeset
|
380 Tracker tkr(Tracker::Release, thread); |
4c84d351cca9
8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents:
11090
diff
changeset
|
381 tkr.record(addr, size); |
4c84d351cca9
8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents:
11090
diff
changeset
|
382 } |
4c84d351cca9
8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents:
11090
diff
changeset
|
383 } |
6197 | 384 |
385 // record memory type on virtual memory base address | |
386 static inline void record_virtual_memory_type(address base, MEMFLAGS flags, | |
387 Thread* thread = NULL) { | |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
388 Tracker tkr(Tracker::Type); |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
389 tkr.record(base, 0, flags); |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
390 } |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
391 |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
392 // Get memory trackers for memory operations that can result race conditions. |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
393 // The memory tracker has to be obtained before realloc, virtual memory uncommit |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
394 // and virtual memory release, and call tracker.record() method if operation |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
395 // succeeded, or tracker.discard() to abort the tracking. |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
396 static inline Tracker get_realloc_tracker() { |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
397 return Tracker(Tracker::Realloc); |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
398 } |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
399 |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
400 static inline Tracker get_virtual_memory_uncommit_tracker() { |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
401 return Tracker(Tracker::Uncommit); |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
402 } |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
403 |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
404 static inline Tracker get_virtual_memory_release_tracker() { |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
405 return Tracker(Tracker::Release); |
6197 | 406 } |
407 | |
408 | |
409 // create memory baseline of current memory snapshot | |
410 static bool baseline(); | |
411 // is there a memory baseline | |
412 static bool has_baseline() { | |
413 return _baseline.baselined(); | |
414 } | |
415 | |
416 // print memory usage from current snapshot | |
417 static bool print_memory_usage(BaselineOutputer& out, size_t unit, | |
418 bool summary_only = true); | |
419 // compare memory usage between current snapshot and baseline | |
420 static bool compare_memory_usage(BaselineOutputer& out, size_t unit, | |
421 bool summary_only = true); | |
422 | |
7971
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
423 // 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
|
424 // 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
|
425 // database. |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
426 static bool wbtest_wait_for_data_merge(); |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
427 |
6197 | 428 // sync is called within global safepoint to synchronize nmt data |
429 static void sync(); | |
430 | |
431 // called when a thread is about to exit | |
432 static void thread_exiting(JavaThread* thread); | |
433 | |
434 // retrieve global snapshot | |
435 static MemSnapshot* get_snapshot() { | |
436 if (shutdown_in_progress()) { | |
437 return NULL; | |
438 } | |
439 return _snapshot; | |
440 } | |
441 | |
442 // print tracker stats | |
443 NOT_PRODUCT(static void print_tracker_stats(outputStream* st);) | |
444 NOT_PRODUCT(static void walk_stack(int toSkip, char* buf, int len);) | |
445 | |
446 private: | |
447 // 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
|
448 static bool start_worker(MemSnapshot* snapshot); |
6197 | 449 |
450 // called by worker thread to complete shutdown process | |
451 static void final_shutdown(); | |
452 | |
453 protected: | |
454 // retrieve per-thread recorder of the specified thread. | |
455 // if the recorder is full, it will be enqueued to overflow | |
456 // queue, a new recorder is acquired from recorder pool or a | |
457 // new instance is created. | |
458 // when thread == NULL, it means global recorder | |
459 static MemRecorder* get_thread_recorder(JavaThread* thread); | |
460 | |
461 // per-thread recorder pool | |
462 static void release_thread_recorder(MemRecorder* rec); | |
463 static void delete_all_pooled_recorders(); | |
464 | |
465 // pending recorder queue. Recorders are queued to pending queue | |
466 // when they are overflowed or collected at nmt sync point. | |
467 static void enqueue_pending_recorder(MemRecorder* rec); | |
468 static MemRecorder* get_pending_recorders(); | |
469 static void delete_all_pending_recorders(); | |
470 | |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
471 // write a memory tracking record in recorder |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
472 static void write_tracking_record(address addr, MEMFLAGS type, |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
473 size_t size, jint seq, address pc, JavaThread* thread); |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
474 |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
475 static bool is_single_threaded_bootstrap() { |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
476 return _state == NMT_bootstrapping_single_thread; |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
477 } |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
478 |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
479 static void check_NMT_load(Thread* thr) { |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
480 assert(thr != NULL, "Sanity check"); |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
481 if (_slowdown_calling_thread && thr != _worker_thread) { |
11090
5f7a4367c787
8016074: NMT: assertion failed: assert(thread->thread_state() == from) failed: coming from wrong thread state
zgu
parents:
10986
diff
changeset
|
482 #ifdef _WINDOWS |
5f7a4367c787
8016074: NMT: assertion failed: assert(thread->thread_state() == from) failed: coming from wrong thread state
zgu
parents:
10986
diff
changeset
|
483 // On Windows, os::NakedYield() does not work as well |
5f7a4367c787
8016074: NMT: assertion failed: assert(thread->thread_state() == from) failed: coming from wrong thread state
zgu
parents:
10986
diff
changeset
|
484 // as os::yield_all() |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
485 os::yield_all(); |
11090
5f7a4367c787
8016074: NMT: assertion failed: assert(thread->thread_state() == from) failed: coming from wrong thread state
zgu
parents:
10986
diff
changeset
|
486 #else |
5f7a4367c787
8016074: NMT: assertion failed: assert(thread->thread_state() == from) failed: coming from wrong thread state
zgu
parents:
10986
diff
changeset
|
487 // On Solaris, os::yield_all() depends on os::sleep() |
5f7a4367c787
8016074: NMT: assertion failed: assert(thread->thread_state() == from) failed: coming from wrong thread state
zgu
parents:
10986
diff
changeset
|
488 // which requires JavaTherad in _thread_in_vm state. |
5f7a4367c787
8016074: NMT: assertion failed: assert(thread->thread_state() == from) failed: coming from wrong thread state
zgu
parents:
10986
diff
changeset
|
489 // Transits thread to _thread_in_vm state can be dangerous |
5f7a4367c787
8016074: NMT: assertion failed: assert(thread->thread_state() == from) failed: coming from wrong thread state
zgu
parents:
10986
diff
changeset
|
490 // if caller holds lock, as it may deadlock with Threads_lock. |
5f7a4367c787
8016074: NMT: assertion failed: assert(thread->thread_state() == from) failed: coming from wrong thread state
zgu
parents:
10986
diff
changeset
|
491 // So use NaKedYield instead. |
5f7a4367c787
8016074: NMT: assertion failed: assert(thread->thread_state() == from) failed: coming from wrong thread state
zgu
parents:
10986
diff
changeset
|
492 // |
5f7a4367c787
8016074: NMT: assertion failed: assert(thread->thread_state() == from) failed: coming from wrong thread state
zgu
parents:
10986
diff
changeset
|
493 // Linux and BSD, NakedYield() and yield_all() implementations |
5f7a4367c787
8016074: NMT: assertion failed: assert(thread->thread_state() == from) failed: coming from wrong thread state
zgu
parents:
10986
diff
changeset
|
494 // are the same. |
5f7a4367c787
8016074: NMT: assertion failed: assert(thread->thread_state() == from) failed: coming from wrong thread state
zgu
parents:
10986
diff
changeset
|
495 os::NakedYield(); |
5f7a4367c787
8016074: NMT: assertion failed: assert(thread->thread_state() == from) failed: coming from wrong thread state
zgu
parents:
10986
diff
changeset
|
496 #endif |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
497 } |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
498 } |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
499 |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
500 static void inc_pending_op_count() { |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
501 Atomic::inc(&_pending_op_count); |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
502 } |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
503 |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
504 static void dec_pending_op_count() { |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
505 Atomic::dec(&_pending_op_count); |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
506 assert(_pending_op_count >= 0, "Sanity check"); |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
507 } |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
508 |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
509 |
6197 | 510 private: |
511 // retrieve a pooled memory record or create new one if there is not | |
512 // one available | |
513 static MemRecorder* get_new_or_pooled_instance(); | |
514 static void create_memory_record(address addr, MEMFLAGS type, | |
515 size_t size, address pc, Thread* thread); | |
516 static void create_record_in_recorder(address addr, MEMFLAGS type, | |
6231 | 517 size_t size, address pc, JavaThread* thread); |
6197 | 518 |
7971
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
519 static void set_current_processing_generation(unsigned long generation) { |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
520 _worker_thread_idle = false; |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
521 _processing_generation = generation; |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
522 } |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
523 |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
524 static void report_worker_idle() { |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
525 _worker_thread_idle = true; |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
526 } |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
527 |
6197 | 528 private: |
529 // global memory snapshot | |
530 static MemSnapshot* _snapshot; | |
531 | |
532 // a memory baseline of snapshot | |
533 static MemBaseline _baseline; | |
534 | |
535 // query lock | |
6232
f1f45dddb0bd
7181986: NMT ON: Assertion failure when running jdi ExpiredRequestDeletionTest
zgu
parents:
6197
diff
changeset
|
536 static Mutex* _query_lock; |
6197 | 537 |
538 // a thread can start to allocate memory before it is attached | |
539 // to VM 'Thread', those memory activities are recorded here. | |
540 // 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
|
541 static MemRecorder* volatile _global_recorder; |
6197 | 542 |
543 // main thread id | |
544 debug_only(static intx _main_thread_tid;) | |
545 | |
546 // 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
|
547 static MemRecorder* volatile _merge_pending_queue; |
6197 | 548 |
549 NOT_PRODUCT(static volatile jint _pending_recorder_count;) | |
550 | |
551 // pooled memory recorders | |
10096
35f8765422b9
8010151: nsk/regression/b6653214 fails "assert(snapshot != NULL) failed: Worker should not be started"
zgu
parents:
8842
diff
changeset
|
552 static MemRecorder* volatile _pooled_recorders; |
6197 | 553 |
554 // memory recorder pool management, uses following | |
555 // counter to determine if a released memory recorder | |
556 // should be pooled | |
557 | |
558 // latest thread count | |
559 static int _thread_count; | |
560 // pooled recorder count | |
561 static volatile jint _pooled_recorder_count; | |
562 | |
563 | |
564 // worker thread to merge pending recorders into snapshot | |
565 static MemTrackWorker* _worker_thread; | |
566 | |
567 // how many safepoints we skipped without entering sync point | |
568 static int _sync_point_skip_count; | |
569 | |
570 // if the tracker is properly intialized | |
571 static bool _is_tracker_ready; | |
572 // tracking level (off, summary and detail) | |
573 static enum NMTLevel _tracking_level; | |
574 | |
575 // current nmt state | |
576 static volatile enum NMTStates _state; | |
577 // the reason for shutting down nmt | |
578 static enum ShutdownReason _reason; | |
7971
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
579 // the generation that NMT is processing |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
580 static volatile unsigned long _processing_generation; |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
581 // although NMT is still procesing current generation, but |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
582 // 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
|
583 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
|
584 |
06db4c0afbf3
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
7971
diff
changeset
|
585 // 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
|
586 // worker thread to catch up |
06db4c0afbf3
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
7971
diff
changeset
|
587 static volatile bool _slowdown_calling_thread; |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
588 |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
589 // pending memory op count. |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
590 // Certain memory ops need to pre-reserve sequence number |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
591 // before memory operation can happen to avoid race condition. |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
592 // See MemTracker::Tracker for detail |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10096
diff
changeset
|
593 static volatile jint _pending_op_count; |
6197 | 594 }; |
595 | |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
596 #endif // !INCLUDE_NMT |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6770
diff
changeset
|
597 |
6197 | 598 #endif // SHARE_VM_SERVICES_MEM_TRACKER_HPP |