author | jlaskey |
Tue, 23 Jul 2013 12:00:29 -0300 | |
changeset 19089 | 51cfdcf21d35 |
parent 18086 | f44cf213a775 |
child 18681 | c3f1b735c47f |
permissions | -rw-r--r-- |
13195 | 1 |
/* |
18086
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
2 |
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
13195 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
#ifndef SHARE_VM_SERVICES_MEM_TRACKER_HPP |
|
26 |
#define SHARE_VM_SERVICES_MEM_TRACKER_HPP |
|
27 |
||
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
28 |
#include "utilities/macros.hpp" |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
29 |
|
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
30 |
#if !INCLUDE_NMT |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
31 |
|
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
32 |
#include "utilities/ostream.hpp" |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
33 |
|
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
34 |
class BaselineOutputer : public StackObj { |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
35 |
|
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
36 |
}; |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
37 |
|
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
38 |
class BaselineTTYOutputer : public BaselineOutputer { |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
39 |
public: |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
40 |
BaselineTTYOutputer(outputStream* st) { } |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
41 |
}; |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
42 |
|
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
43 |
class MemTracker : AllStatic { |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
44 |
public: |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
45 |
enum ShutdownReason { |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
46 |
NMT_shutdown_none, // no shutdown requested |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
47 |
NMT_shutdown_user, // user requested shutdown |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
48 |
NMT_normal, // normal shutdown, process exit |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
49 |
NMT_out_of_memory, // shutdown due to out of memory |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
50 |
NMT_initialization, // shutdown due to initialization failure |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
51 |
NMT_use_malloc_only, // can not combine NMT with UseMallocOnly flag |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
52 |
NMT_error_reporting, // shutdown by vmError::report_and_die() |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
53 |
NMT_out_of_generation, // running out of generation queue |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
54 |
NMT_sequence_overflow // overflow the sequence number |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
55 |
}; |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
56 |
|
18086
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
57 |
class Tracker { |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
58 |
public: |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
59 |
void discard() { } |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
60 |
|
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
61 |
void record(address addr, size_t size = 0, MEMFLAGS flags = mtNone, address pc = NULL) { } |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
62 |
void record(address old_addr, address new_addr, size_t size, |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
63 |
MEMFLAGS flags, address pc = NULL) { } |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
64 |
}; |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
65 |
|
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
66 |
private: |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
67 |
static Tracker _tkr; |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
68 |
|
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
69 |
|
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
70 |
public: |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
71 |
static inline void init_tracking_options(const char* option_line) { } |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
72 |
static inline bool is_on() { return false; } |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
73 |
static const char* reason() { return "Native memory tracking is not implemented"; } |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
74 |
static inline bool can_walk_stack() { return false; } |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
75 |
|
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
76 |
static inline void bootstrap_single_thread() { } |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
77 |
static inline void bootstrap_multi_thread() { } |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
78 |
static inline void start() { } |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
79 |
|
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
80 |
static inline void record_malloc(address addr, size_t size, MEMFLAGS flags, |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
81 |
address pc = 0, Thread* thread = NULL) { } |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
82 |
static inline void record_free(address addr, MEMFLAGS flags, Thread* thread = NULL) { } |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
83 |
static inline void record_arena_size(address addr, size_t size) { } |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
84 |
static inline void record_virtual_memory_reserve(address addr, size_t size, |
18086
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
85 |
MEMFLAGS flags, address pc = 0, Thread* thread = NULL) { } |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
86 |
static inline void record_virtual_memory_reserve_and_commit(address addr, size_t size, |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
87 |
MEMFLAGS flags, address pc = 0, Thread* thread = NULL) { } |
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
88 |
static inline void record_virtual_memory_commit(address addr, size_t size, |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
89 |
address pc = 0, Thread* thread = NULL) { } |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
90 |
static inline void record_virtual_memory_type(address base, MEMFLAGS flags, |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
91 |
Thread* thread = NULL) { } |
18086
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
92 |
static inline Tracker get_realloc_tracker() { return _tkr; } |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
93 |
static inline Tracker get_virtual_memory_uncommit_tracker() { return _tkr; } |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
94 |
static inline Tracker get_virtual_memory_release_tracker() { return _tkr; } |
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
95 |
static inline bool baseline() { return false; } |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
96 |
static inline bool has_baseline() { return false; } |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
97 |
|
16436
6b67e51e3cfb
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
15452
diff
changeset
|
98 |
static inline void set_autoShutdown(bool value) { } |
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
99 |
static void shutdown(ShutdownReason reason) { } |
16593
b7919ae9ec7d
8010474: [parfait] Undefined return value of the functions in hotspot/src/share/vm/services/memTracker.hpp
zgu
parents:
16436
diff
changeset
|
100 |
static inline bool shutdown_in_progress() { return false; } |
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
101 |
static bool print_memory_usage(BaselineOutputer& out, size_t unit, |
16593
b7919ae9ec7d
8010474: [parfait] Undefined return value of the functions in hotspot/src/share/vm/services/memTracker.hpp
zgu
parents:
16436
diff
changeset
|
102 |
bool summary_only = true) { return false; } |
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
103 |
static bool compare_memory_usage(BaselineOutputer& out, size_t unit, |
16593
b7919ae9ec7d
8010474: [parfait] Undefined return value of the functions in hotspot/src/share/vm/services/memTracker.hpp
zgu
parents:
16436
diff
changeset
|
104 |
bool summary_only = true) { return false; } |
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
105 |
|
16593
b7919ae9ec7d
8010474: [parfait] Undefined return value of the functions in hotspot/src/share/vm/services/memTracker.hpp
zgu
parents:
16436
diff
changeset
|
106 |
static bool wbtest_wait_for_data_merge() { return false; } |
15452
3bfde2dea09d
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
15104
diff
changeset
|
107 |
|
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
108 |
static inline void sync() { } |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
109 |
static inline void thread_exiting(JavaThread* thread) { } |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
110 |
}; |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
111 |
|
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
112 |
|
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
113 |
#else // !INCLUDE_NMT |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
114 |
|
13195 | 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 |
||
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13975
diff
changeset
|
125 |
extern bool NMT_track_callsite; |
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13975
diff
changeset
|
126 |
|
15452
3bfde2dea09d
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
15104
diff
changeset
|
127 |
#ifndef MAX_UNSIGNED_LONG |
3bfde2dea09d
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
15104
diff
changeset
|
128 |
#define MAX_UNSIGNED_LONG (unsigned long)(-1) |
3bfde2dea09d
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
15104
diff
changeset
|
129 |
#endif |
3bfde2dea09d
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
15104
diff
changeset
|
130 |
|
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13975
diff
changeset
|
131 |
#ifdef ASSERT |
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13975
diff
changeset
|
132 |
#define DEBUG_CALLER_PC (NMT_track_callsite ? os::get_caller_pc(2) : 0) |
13195 | 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 { |
|
15104
f5d78994619f
8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents:
14583
diff
changeset
|
162 |
friend class GenerationData; |
13195 | 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 |
||
13861
619cff4bfb8b
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
13859
diff
changeset
|
178 |
public: |
18086
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
179 |
class Tracker : public StackObj { |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
180 |
friend class MemTracker; |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
181 |
public: |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
182 |
enum MemoryOperation { |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
183 |
NoOp, // no op |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
184 |
Malloc, // malloc |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
185 |
Realloc, // realloc |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
186 |
Free, // free |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
187 |
Reserve, // virtual memory reserve |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
188 |
Commit, // virtual memory commit |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
189 |
ReserveAndCommit, // virtual memory reserve and commit |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
190 |
StackAlloc = ReserveAndCommit, // allocate thread stack |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
191 |
Type, // assign virtual memory type |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
192 |
Uncommit, // virtual memory uncommit |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
193 |
Release, // virtual memory release |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
194 |
ArenaSize, // set arena size |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
195 |
StackRelease // release thread stack |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
196 |
}; |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
197 |
|
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
198 |
|
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
199 |
protected: |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
200 |
Tracker(MemoryOperation op, Thread* thr = NULL); |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
201 |
|
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
202 |
public: |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
203 |
void discard(); |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
204 |
|
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
205 |
void record(address addr, size_t size = 0, MEMFLAGS flags = mtNone, address pc = NULL); |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
206 |
void record(address old_addr, address new_addr, size_t size, |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
207 |
MEMFLAGS flags, address pc = NULL); |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
208 |
|
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
209 |
private: |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
210 |
bool _need_thread_critical_lock; |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
211 |
JavaThread* _java_thread; |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
212 |
MemoryOperation _op; // memory operation |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
213 |
jint _seq; // reserved sequence number |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
214 |
}; |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
215 |
|
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
216 |
|
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
217 |
public: |
13195 | 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 |
||
13861
619cff4bfb8b
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
13859
diff
changeset
|
248 |
static inline enum NMTLevel tracking_level() { |
619cff4bfb8b
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
13859
diff
changeset
|
249 |
return _tracking_level; |
619cff4bfb8b
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
13859
diff
changeset
|
250 |
} |
619cff4bfb8b
7188594: Print statistic collected by NMT with VM flag
zgu
parents:
13859
diff
changeset
|
251 |
|
13195 | 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"; |
|
13301
f6dd749390dd
7181986: NMT ON: Assertion failure when running jdi ExpiredRequestDeletionTest
zgu
parents:
13195
diff
changeset
|
261 |
case NMT_out_of_memory: |
f6dd749390dd
7181986: NMT ON: Assertion failure when running jdi ExpiredRequestDeletionTest
zgu
parents:
13195
diff
changeset
|
262 |
return "Native memory tracking has been shutdown due to out of native memory"; |
13195 | 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 |
||
16436
6b67e51e3cfb
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
15452
diff
changeset
|
292 |
// NMT automatically shuts itself down under extreme situation by default. |
6b67e51e3cfb
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
15452
diff
changeset
|
293 |
// When the value is set to false, NMT will try its best to stay alive, |
6b67e51e3cfb
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
15452
diff
changeset
|
294 |
// even it has to slow down VM. |
6b67e51e3cfb
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
15452
diff
changeset
|
295 |
static inline void set_autoShutdown(bool value) { |
6b67e51e3cfb
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
15452
diff
changeset
|
296 |
AutoShutdownNMT = value; |
6b67e51e3cfb
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
15452
diff
changeset
|
297 |
if (AutoShutdownNMT && _slowdown_calling_thread) { |
6b67e51e3cfb
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
15452
diff
changeset
|
298 |
_slowdown_calling_thread = false; |
6b67e51e3cfb
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
15452
diff
changeset
|
299 |
} |
6b67e51e3cfb
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
15452
diff
changeset
|
300 |
} |
6b67e51e3cfb
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
15452
diff
changeset
|
301 |
|
13195 | 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) { |
|
18086
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
329 |
Tracker tkr(Tracker::Malloc, thread); |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
330 |
tkr.record(addr, size, flags, pc); |
13195 | 331 |
} |
332 |
// record a 'free' call |
|
333 |
static inline void record_free(address addr, MEMFLAGS flags, Thread* thread = NULL) { |
|
18086
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
334 |
Tracker tkr(Tracker::Free, thread); |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
335 |
tkr.record(addr, 0, flags, DEBUG_CALLER_PC); |
13195 | 336 |
} |
337 |
||
338 |
static inline void record_arena_size(address addr, size_t size) { |
|
18086
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
339 |
Tracker tkr(Tracker::ArenaSize); |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
340 |
tkr.record(addr, size); |
13195 | 341 |
} |
342 |
||
343 |
// record a virtual memory 'reserve' call |
|
344 |
static inline void record_virtual_memory_reserve(address addr, size_t size, |
|
18086
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
345 |
MEMFLAGS flags, address pc = 0, Thread* thread = NULL) { |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
346 |
assert(size > 0, "Sanity check"); |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
347 |
Tracker tkr(Tracker::Reserve, thread); |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
348 |
tkr.record(addr, size, flags, pc); |
13195 | 349 |
} |
350 |
||
13744
631fe815def5
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
13470
diff
changeset
|
351 |
static inline void record_thread_stack(address addr, size_t size, Thread* thr, |
631fe815def5
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
13470
diff
changeset
|
352 |
address pc = 0) { |
18086
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
353 |
Tracker tkr(Tracker::StackAlloc, thr); |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
354 |
tkr.record(addr, size, mtThreadStack, pc); |
13744
631fe815def5
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
13470
diff
changeset
|
355 |
} |
631fe815def5
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
13470
diff
changeset
|
356 |
|
631fe815def5
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
13470
diff
changeset
|
357 |
static inline void release_thread_stack(address addr, size_t size, Thread* thr) { |
18086
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
358 |
Tracker tkr(Tracker::StackRelease, thr); |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
359 |
tkr.record(addr, size, mtThreadStack, DEBUG_CALLER_PC); |
13744
631fe815def5
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
13470
diff
changeset
|
360 |
} |
631fe815def5
7181995: NMT ON: NMT assertion failure assert(cur_vm->is_uncommit_record() || cur_vm->is_deallocation_record
zgu
parents:
13470
diff
changeset
|
361 |
|
13195 | 362 |
// record a virtual memory 'commit' call |
363 |
static inline void record_virtual_memory_commit(address addr, size_t size, |
|
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
13975
diff
changeset
|
364 |
address pc, Thread* thread = NULL) { |
18086
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
365 |
Tracker tkr(Tracker::Commit, thread); |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
366 |
tkr.record(addr, size, mtNone, pc); |
13195 | 367 |
} |
368 |
||
18086
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
369 |
static inline void record_virtual_memory_reserve_and_commit(address addr, size_t size, |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
370 |
MEMFLAGS flags, address pc, Thread* thread = NULL) { |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
371 |
Tracker tkr(Tracker::ReserveAndCommit, thread); |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
372 |
tkr.record(addr, size, flags, pc); |
13195 | 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) { |
|
18086
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
379 |
Tracker tkr(Tracker::Type); |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
380 |
tkr.record(base, 0, flags); |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
381 |
} |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
382 |
|
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
383 |
// Get memory trackers for memory operations that can result race conditions. |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
384 |
// The memory tracker has to be obtained before realloc, virtual memory uncommit |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
385 |
// and virtual memory release, and call tracker.record() method if operation |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
386 |
// succeeded, or tracker.discard() to abort the tracking. |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
387 |
static inline Tracker get_realloc_tracker() { |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
388 |
return Tracker(Tracker::Realloc); |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
389 |
} |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
390 |
|
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
391 |
static inline Tracker get_virtual_memory_uncommit_tracker() { |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
392 |
return Tracker(Tracker::Uncommit); |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
393 |
} |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
394 |
|
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
395 |
static inline Tracker get_virtual_memory_release_tracker() { |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
396 |
return Tracker(Tracker::Release); |
13195 | 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 |
||
15452
3bfde2dea09d
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
15104
diff
changeset
|
414 |
// the version for whitebox testing support, it ensures that all memory |
3bfde2dea09d
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
15104
diff
changeset
|
415 |
// activities before this method call, are reflected in the snapshot |
3bfde2dea09d
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
15104
diff
changeset
|
416 |
// database. |
3bfde2dea09d
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
15104
diff
changeset
|
417 |
static bool wbtest_wait_for_data_merge(); |
3bfde2dea09d
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
15104
diff
changeset
|
418 |
|
13195 | 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 |
|
16991
aa4978a77e1f
8010151: nsk/regression/b6653214 fails "assert(snapshot != NULL) failed: Worker should not be started"
zgu
parents:
16593
diff
changeset
|
439 |
static bool start_worker(MemSnapshot* snapshot); |
13195 | 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 |
||
18086
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
462 |
// write a memory tracking record in recorder |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
463 |
static void write_tracking_record(address addr, MEMFLAGS type, |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
464 |
size_t size, jint seq, address pc, JavaThread* thread); |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
465 |
|
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
466 |
static bool is_single_threaded_bootstrap() { |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
467 |
return _state == NMT_bootstrapping_single_thread; |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
468 |
} |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
469 |
|
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
470 |
static void check_NMT_load(Thread* thr) { |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
471 |
assert(thr != NULL, "Sanity check"); |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
472 |
if (_slowdown_calling_thread && thr != _worker_thread) { |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
473 |
os::yield_all(); |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
474 |
} |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
475 |
} |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
476 |
|
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
477 |
static void inc_pending_op_count() { |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
478 |
Atomic::inc(&_pending_op_count); |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
479 |
} |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
480 |
|
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
481 |
static void dec_pending_op_count() { |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
482 |
Atomic::dec(&_pending_op_count); |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
483 |
assert(_pending_op_count >= 0, "Sanity check"); |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
484 |
} |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
485 |
|
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
486 |
|
13195 | 487 |
private: |
488 |
// retrieve a pooled memory record or create new one if there is not |
|
489 |
// one available |
|
490 |
static MemRecorder* get_new_or_pooled_instance(); |
|
491 |
static void create_memory_record(address addr, MEMFLAGS type, |
|
492 |
size_t size, address pc, Thread* thread); |
|
493 |
static void create_record_in_recorder(address addr, MEMFLAGS type, |
|
13300 | 494 |
size_t size, address pc, JavaThread* thread); |
13195 | 495 |
|
15452
3bfde2dea09d
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
15104
diff
changeset
|
496 |
static void set_current_processing_generation(unsigned long generation) { |
3bfde2dea09d
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
15104
diff
changeset
|
497 |
_worker_thread_idle = false; |
3bfde2dea09d
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
15104
diff
changeset
|
498 |
_processing_generation = generation; |
3bfde2dea09d
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
15104
diff
changeset
|
499 |
} |
3bfde2dea09d
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
15104
diff
changeset
|
500 |
|
3bfde2dea09d
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
15104
diff
changeset
|
501 |
static void report_worker_idle() { |
3bfde2dea09d
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
15104
diff
changeset
|
502 |
_worker_thread_idle = true; |
3bfde2dea09d
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
15104
diff
changeset
|
503 |
} |
3bfde2dea09d
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
15104
diff
changeset
|
504 |
|
13195 | 505 |
private: |
506 |
// global memory snapshot |
|
507 |
static MemSnapshot* _snapshot; |
|
508 |
||
509 |
// a memory baseline of snapshot |
|
510 |
static MemBaseline _baseline; |
|
511 |
||
512 |
// query lock |
|
13301
f6dd749390dd
7181986: NMT ON: Assertion failure when running jdi ExpiredRequestDeletionTest
zgu
parents:
13195
diff
changeset
|
513 |
static Mutex* _query_lock; |
13195 | 514 |
|
515 |
// a thread can start to allocate memory before it is attached |
|
516 |
// to VM 'Thread', those memory activities are recorded here. |
|
517 |
// ThreadCritical is required to guard this global recorder. |
|
16991
aa4978a77e1f
8010151: nsk/regression/b6653214 fails "assert(snapshot != NULL) failed: Worker should not be started"
zgu
parents:
16593
diff
changeset
|
518 |
static MemRecorder* volatile _global_recorder; |
13195 | 519 |
|
520 |
// main thread id |
|
521 |
debug_only(static intx _main_thread_tid;) |
|
522 |
||
523 |
// pending recorders to be merged |
|
16991
aa4978a77e1f
8010151: nsk/regression/b6653214 fails "assert(snapshot != NULL) failed: Worker should not be started"
zgu
parents:
16593
diff
changeset
|
524 |
static MemRecorder* volatile _merge_pending_queue; |
13195 | 525 |
|
526 |
NOT_PRODUCT(static volatile jint _pending_recorder_count;) |
|
527 |
||
528 |
// pooled memory recorders |
|
16991
aa4978a77e1f
8010151: nsk/regression/b6653214 fails "assert(snapshot != NULL) failed: Worker should not be started"
zgu
parents:
16593
diff
changeset
|
529 |
static MemRecorder* volatile _pooled_recorders; |
13195 | 530 |
|
531 |
// memory recorder pool management, uses following |
|
532 |
// counter to determine if a released memory recorder |
|
533 |
// should be pooled |
|
534 |
||
535 |
// latest thread count |
|
536 |
static int _thread_count; |
|
537 |
// pooled recorder count |
|
538 |
static volatile jint _pooled_recorder_count; |
|
539 |
||
540 |
||
541 |
// worker thread to merge pending recorders into snapshot |
|
542 |
static MemTrackWorker* _worker_thread; |
|
543 |
||
544 |
// how many safepoints we skipped without entering sync point |
|
545 |
static int _sync_point_skip_count; |
|
546 |
||
547 |
// if the tracker is properly intialized |
|
548 |
static bool _is_tracker_ready; |
|
549 |
// tracking level (off, summary and detail) |
|
550 |
static enum NMTLevel _tracking_level; |
|
551 |
||
552 |
// current nmt state |
|
553 |
static volatile enum NMTStates _state; |
|
554 |
// the reason for shutting down nmt |
|
555 |
static enum ShutdownReason _reason; |
|
15452
3bfde2dea09d
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
15104
diff
changeset
|
556 |
// the generation that NMT is processing |
3bfde2dea09d
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
15104
diff
changeset
|
557 |
static volatile unsigned long _processing_generation; |
3bfde2dea09d
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
15104
diff
changeset
|
558 |
// although NMT is still procesing current generation, but |
3bfde2dea09d
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
15104
diff
changeset
|
559 |
// there is not more recorder to process, set idle state |
3bfde2dea09d
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
15104
diff
changeset
|
560 |
static volatile bool _worker_thread_idle; |
16436
6b67e51e3cfb
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
15452
diff
changeset
|
561 |
|
6b67e51e3cfb
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
15452
diff
changeset
|
562 |
// if NMT should slow down calling thread to allow |
6b67e51e3cfb
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
15452
diff
changeset
|
563 |
// worker thread to catch up |
6b67e51e3cfb
8009298: NMT: Special version of class loading/unloading with runThese stresses out NMT
zgu
parents:
15452
diff
changeset
|
564 |
static volatile bool _slowdown_calling_thread; |
18086
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
565 |
|
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
566 |
// pending memory op count. |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
567 |
// Certain memory ops need to pre-reserve sequence number |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
568 |
// before memory operation can happen to avoid race condition. |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
569 |
// See MemTracker::Tracker for detail |
f44cf213a775
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
16991
diff
changeset
|
570 |
static volatile jint _pending_op_count; |
13195 | 571 |
}; |
572 |
||
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
573 |
#endif // !INCLUDE_NMT |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13861
diff
changeset
|
574 |
|
13195 | 575 |
#endif // SHARE_VM_SERVICES_MEM_TRACKER_HPP |