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