author | egahlin |
Mon, 08 Jul 2019 18:11:26 +0200 | |
branch | JEP-349-branch |
changeset 57459 | df39f8d8f4d6 |
parent 54292 | c31faeacf00a |
child 58063 | bdf136b8ae0e |
child 59119 | 7bdc4f073c7f |
permissions | -rw-r--r-- |
25946 | 1 |
/* |
54292
c31faeacf00a
8204552: NMT: Separate thread stack tracking from virtual memory tracking
zgu
parents:
49980
diff
changeset
|
2 |
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. |
25946 | 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 |
#include "precompiled.hpp" |
|
25 |
||
49968 | 26 |
#include "logging/log.hpp" |
47553
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
27 |
#include "memory/metaspace.hpp" |
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
38935
diff
changeset
|
28 |
#include "runtime/atomic.hpp" |
38935 | 29 |
#include "runtime/os.hpp" |
25946 | 30 |
#include "runtime/threadCritical.hpp" |
38935 | 31 |
#include "services/memTracker.hpp" |
54292
c31faeacf00a
8204552: NMT: Separate thread stack tracking from virtual memory tracking
zgu
parents:
49980
diff
changeset
|
32 |
#include "services/threadStackTracker.hpp" |
25946 | 33 |
#include "services/virtualMemoryTracker.hpp" |
34 |
||
35 |
size_t VirtualMemorySummary::_snapshot[CALC_OBJ_SIZE_IN_TYPE(VirtualMemorySnapshot, size_t)]; |
|
36 |
||
37 |
void VirtualMemorySummary::initialize() { |
|
38 |
assert(sizeof(_snapshot) >= sizeof(VirtualMemorySnapshot), "Sanity Check"); |
|
39 |
// Use placement operator new to initialize static data area. |
|
40 |
::new ((void*)_snapshot) VirtualMemorySnapshot(); |
|
41 |
} |
|
42 |
||
49968 | 43 |
void VirtualMemorySummary::snapshot(VirtualMemorySnapshot* s) { |
54292
c31faeacf00a
8204552: NMT: Separate thread stack tracking from virtual memory tracking
zgu
parents:
49980
diff
changeset
|
44 |
// Only if thread stack is backed by virtual memory |
c31faeacf00a
8204552: NMT: Separate thread stack tracking from virtual memory tracking
zgu
parents:
49980
diff
changeset
|
45 |
if (ThreadStackTracker::track_as_vm()) { |
c31faeacf00a
8204552: NMT: Separate thread stack tracking from virtual memory tracking
zgu
parents:
49980
diff
changeset
|
46 |
// Snapshot current thread stacks |
c31faeacf00a
8204552: NMT: Separate thread stack tracking from virtual memory tracking
zgu
parents:
49980
diff
changeset
|
47 |
VirtualMemoryTracker::snapshot_thread_stacks(); |
c31faeacf00a
8204552: NMT: Separate thread stack tracking from virtual memory tracking
zgu
parents:
49980
diff
changeset
|
48 |
as_snapshot()->copy_to(s); |
c31faeacf00a
8204552: NMT: Separate thread stack tracking from virtual memory tracking
zgu
parents:
49980
diff
changeset
|
49 |
} |
49968 | 50 |
} |
51 |
||
26136
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
52 |
SortedLinkedList<ReservedMemoryRegion, compare_reserved_region_base>* VirtualMemoryTracker::_reserved_regions; |
25946 | 53 |
|
54 |
int compare_committed_region(const CommittedMemoryRegion& r1, const CommittedMemoryRegion& r2) { |
|
55 |
return r1.compare(r2); |
|
56 |
} |
|
57 |
||
58 |
int compare_reserved_region_base(const ReservedMemoryRegion& r1, const ReservedMemoryRegion& r2) { |
|
59 |
return r1.compare(r2); |
|
60 |
} |
|
61 |
||
49033
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
62 |
static bool is_mergeable_with(CommittedMemoryRegion* rgn, address addr, size_t size, const NativeCallStack& stack) { |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
63 |
return rgn->adjacent_to(addr, size) && rgn->call_stack()->equals(stack); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
64 |
} |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
65 |
|
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
66 |
static bool is_same_as(CommittedMemoryRegion* rgn, address addr, size_t size, const NativeCallStack& stack) { |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
67 |
// It would have made sense to use rgn->equals(...), but equals returns true for overlapping regions. |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
68 |
return rgn->same_region(addr, size) && rgn->call_stack()->equals(stack); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
69 |
} |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
70 |
|
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
71 |
static LinkedListNode<CommittedMemoryRegion>* find_preceding_node_from(LinkedListNode<CommittedMemoryRegion>* from, address addr) { |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
72 |
LinkedListNode<CommittedMemoryRegion>* preceding = NULL; |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
73 |
|
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
74 |
for (LinkedListNode<CommittedMemoryRegion>* node = from; node != NULL; node = node->next()) { |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
75 |
CommittedMemoryRegion* rgn = node->data(); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
76 |
|
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
77 |
// We searched past the region start. |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
78 |
if (rgn->end() > addr) { |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
79 |
break; |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
80 |
} |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
81 |
|
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
82 |
preceding = node; |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
83 |
} |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
84 |
|
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
85 |
return preceding; |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
86 |
} |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
87 |
|
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
88 |
static bool try_merge_with(LinkedListNode<CommittedMemoryRegion>* node, address addr, size_t size, const NativeCallStack& stack) { |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
89 |
if (node != NULL) { |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
90 |
CommittedMemoryRegion* rgn = node->data(); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
91 |
|
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
92 |
if (is_mergeable_with(rgn, addr, size, stack)) { |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
93 |
rgn->expand_region(addr, size); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
94 |
return true; |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
95 |
} |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
96 |
} |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
97 |
|
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
98 |
return false; |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
99 |
} |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
100 |
|
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
101 |
static bool try_merge_with(LinkedListNode<CommittedMemoryRegion>* node, LinkedListNode<CommittedMemoryRegion>* other) { |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
102 |
if (other == NULL) { |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
103 |
return false; |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
104 |
} |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
105 |
|
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
106 |
CommittedMemoryRegion* rgn = other->data(); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
107 |
return try_merge_with(node, rgn->base(), rgn->size(), *rgn->call_stack()); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
108 |
} |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
109 |
|
25946 | 110 |
bool ReservedMemoryRegion::add_committed_region(address addr, size_t size, const NativeCallStack& stack) { |
111 |
assert(addr != NULL, "Invalid address"); |
|
112 |
assert(size > 0, "Invalid size"); |
|
113 |
assert(contain_region(addr, size), "Not contain this region"); |
|
114 |
||
49033
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
115 |
// Find the region that fully precedes the [addr, addr + size) region. |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
116 |
LinkedListNode<CommittedMemoryRegion>* prev = find_preceding_node_from(_committed_regions.head(), addr); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
117 |
LinkedListNode<CommittedMemoryRegion>* next = (prev != NULL ? prev->next() : _committed_regions.head()); |
25946 | 118 |
|
49033
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
119 |
if (next != NULL) { |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
120 |
// Ignore request if region already exists. |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
121 |
if (is_same_as(next->data(), addr, size, stack)) { |
25946 | 122 |
return true; |
123 |
} |
|
124 |
||
49033
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
125 |
// The new region is after prev, and either overlaps with the |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
126 |
// next region (and maybe more regions), or overlaps with no region. |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
127 |
if (next->data()->overlap_region(addr, size)) { |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
128 |
// Remove _all_ overlapping regions, and parts of regions, |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
129 |
// in preparation for the addition of this new region. |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
130 |
remove_uncommitted_region(addr, size); |
38935 | 131 |
|
49033
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
132 |
// The remove could have split a region into two and created a |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
133 |
// new prev region. Need to reset the prev and next pointers. |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
134 |
prev = find_preceding_node_from((prev != NULL ? prev : _committed_regions.head()), addr); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
135 |
next = (prev != NULL ? prev->next() : _committed_regions.head()); |
25946 | 136 |
} |
38935 | 137 |
} |
138 |
||
49033
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
139 |
// At this point the previous overlapping regions have been |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
140 |
// cleared, and the full region is guaranteed to be inserted. |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
141 |
VirtualMemorySummary::record_committed_memory(size, flag()); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
142 |
|
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
143 |
// Try to merge with prev and possibly next. |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
144 |
if (try_merge_with(prev, addr, size, stack)) { |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
145 |
if (try_merge_with(prev, next)) { |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
146 |
// prev was expanded to contain the new region |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
147 |
// and next, need to remove next from the list |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
148 |
_committed_regions.remove_after(prev); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
149 |
} |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
150 |
|
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
151 |
return true; |
48818
ec4a84ba2aaf
8196372: [BACKOUT] NMT: add_committed_regions doesn't merge succeeding regions
jwilhelm
parents:
48815
diff
changeset
|
152 |
} |
25946 | 153 |
|
49033
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
154 |
// Didn't merge with prev, try with next. |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
155 |
if (try_merge_with(next, addr, size, stack)) { |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
156 |
return true; |
25946 | 157 |
} |
49033
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
158 |
|
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
159 |
// Couldn't merge with any regions - create a new region. |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
160 |
return add_committed_region(CommittedMemoryRegion(addr, size, stack)); |
25946 | 161 |
} |
162 |
||
163 |
bool ReservedMemoryRegion::remove_uncommitted_region(LinkedListNode<CommittedMemoryRegion>* node, |
|
164 |
address addr, size_t size) { |
|
165 |
assert(addr != NULL, "Invalid address"); |
|
166 |
assert(size > 0, "Invalid size"); |
|
167 |
||
168 |
CommittedMemoryRegion* rgn = node->data(); |
|
169 |
assert(rgn->contain_region(addr, size), "Has to be contained"); |
|
170 |
assert(!rgn->same_region(addr, size), "Can not be the same region"); |
|
171 |
||
172 |
if (rgn->base() == addr || |
|
173 |
rgn->end() == addr + size) { |
|
174 |
rgn->exclude_region(addr, size); |
|
175 |
return true; |
|
176 |
} else { |
|
177 |
// split this region |
|
178 |
address top =rgn->end(); |
|
179 |
// use this region for lower part |
|
180 |
size_t exclude_size = rgn->end() - addr; |
|
181 |
rgn->exclude_region(addr, exclude_size); |
|
182 |
||
183 |
// higher part |
|
184 |
address high_base = addr + size; |
|
185 |
size_t high_size = top - high_base; |
|
186 |
||
187 |
CommittedMemoryRegion high_rgn(high_base, high_size, *rgn->call_stack()); |
|
188 |
LinkedListNode<CommittedMemoryRegion>* high_node = _committed_regions.add(high_rgn); |
|
189 |
assert(high_node == NULL || node->next() == high_node, "Should be right after"); |
|
190 |
return (high_node != NULL); |
|
191 |
} |
|
192 |
||
193 |
return false; |
|
194 |
} |
|
195 |
||
196 |
bool ReservedMemoryRegion::remove_uncommitted_region(address addr, size_t sz) { |
|
197 |
assert(addr != NULL, "Invalid address"); |
|
198 |
assert(sz > 0, "Invalid size"); |
|
199 |
||
49033
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
200 |
CommittedMemoryRegion del_rgn(addr, sz, *call_stack()); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
201 |
address end = addr + sz; |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
202 |
|
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
203 |
LinkedListNode<CommittedMemoryRegion>* head = _committed_regions.head(); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
204 |
LinkedListNode<CommittedMemoryRegion>* prev = NULL; |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
205 |
CommittedMemoryRegion* crgn; |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
206 |
|
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
207 |
while (head != NULL) { |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
208 |
crgn = head->data(); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
209 |
|
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
210 |
if (crgn->same_region(addr, sz)) { |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
211 |
VirtualMemorySummary::record_uncommitted_memory(crgn->size(), flag()); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
212 |
_committed_regions.remove_after(prev); |
25946 | 213 |
return true; |
49033
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
214 |
} |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
215 |
|
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
216 |
// del_rgn contains crgn |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
217 |
if (del_rgn.contain_region(crgn->base(), crgn->size())) { |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
218 |
VirtualMemorySummary::record_uncommitted_memory(crgn->size(), flag()); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
219 |
head = head->next(); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
220 |
_committed_regions.remove_after(prev); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
221 |
continue; // don't update head or prev |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
222 |
} |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
223 |
|
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
224 |
// Found addr in the current crgn. There are 2 subcases: |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
225 |
if (crgn->contain_address(addr)) { |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
226 |
|
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
227 |
// (1) Found addr+size in current crgn as well. (del_rgn is contained in crgn) |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
228 |
if (crgn->contain_address(end - 1)) { |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
229 |
VirtualMemorySummary::record_uncommitted_memory(sz, flag()); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
230 |
return remove_uncommitted_region(head, addr, sz); // done! |
25946 | 231 |
} else { |
49033
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
232 |
// (2) Did not find del_rgn's end in crgn. |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
233 |
size_t size = crgn->end() - del_rgn.base(); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
234 |
crgn->exclude_region(addr, size); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
235 |
VirtualMemorySummary::record_uncommitted_memory(size, flag()); |
38935 | 236 |
} |
237 |
||
49033
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
238 |
} else if (crgn->contain_address(end - 1)) { |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
239 |
// Found del_rgn's end, but not its base addr. |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
240 |
size_t size = del_rgn.end() - crgn->base(); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
241 |
crgn->exclude_region(crgn->base(), size); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
242 |
VirtualMemorySummary::record_uncommitted_memory(size, flag()); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
243 |
return true; // should be done if the list is sorted properly! |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
244 |
} |
38935 | 245 |
|
49033
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
246 |
prev = head; |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
247 |
head = head->next(); |
25946 | 248 |
} |
249 |
||
250 |
return true; |
|
251 |
} |
|
252 |
||
253 |
void ReservedMemoryRegion::move_committed_regions(address addr, ReservedMemoryRegion& rgn) { |
|
254 |
assert(addr != NULL, "Invalid address"); |
|
255 |
||
256 |
// split committed regions |
|
257 |
LinkedListNode<CommittedMemoryRegion>* head = |
|
258 |
_committed_regions.head(); |
|
259 |
LinkedListNode<CommittedMemoryRegion>* prev = NULL; |
|
260 |
||
261 |
while (head != NULL) { |
|
262 |
if (head->data()->base() >= addr) { |
|
263 |
break; |
|
264 |
} |
|
265 |
prev = head; |
|
266 |
head = head->next(); |
|
267 |
} |
|
268 |
||
269 |
if (head != NULL) { |
|
270 |
if (prev != NULL) { |
|
271 |
prev->set_next(head->next()); |
|
272 |
} else { |
|
273 |
_committed_regions.set_head(NULL); |
|
274 |
} |
|
275 |
} |
|
276 |
||
277 |
rgn._committed_regions.set_head(head); |
|
278 |
} |
|
279 |
||
280 |
size_t ReservedMemoryRegion::committed_size() const { |
|
49033
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
281 |
size_t committed = 0; |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
282 |
LinkedListNode<CommittedMemoryRegion>* head = |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
283 |
_committed_regions.head(); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
284 |
while (head != NULL) { |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
285 |
committed += head->data()->size(); |
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
286 |
head = head->next(); |
25946 | 287 |
} |
49033
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
288 |
return committed; |
25946 | 289 |
} |
290 |
||
291 |
void ReservedMemoryRegion::set_flag(MEMFLAGS f) { |
|
292 |
assert((flag() == mtNone || flag() == f), "Overwrite memory type"); |
|
293 |
if (flag() != f) { |
|
294 |
VirtualMemorySummary::move_reserved_memory(flag(), f, size()); |
|
295 |
VirtualMemorySummary::move_committed_memory(flag(), f, committed_size()); |
|
296 |
_flag = f; |
|
297 |
} |
|
298 |
} |
|
299 |
||
49968 | 300 |
address ReservedMemoryRegion::thread_stack_uncommitted_bottom() const { |
301 |
assert(flag() == mtThreadStack, "Only for thread stack"); |
|
302 |
LinkedListNode<CommittedMemoryRegion>* head = _committed_regions.head(); |
|
303 |
address bottom = base(); |
|
304 |
address top = base() + size(); |
|
305 |
while (head != NULL) { |
|
306 |
address committed_top = head->data()->base() + head->data()->size(); |
|
307 |
if (committed_top < top) { |
|
308 |
// committed stack guard pages, skip them |
|
309 |
bottom = head->data()->base() + head->data()->size(); |
|
310 |
head = head->next(); |
|
311 |
} else { |
|
312 |
assert(top == committed_top, "Sanity"); |
|
313 |
break; |
|
314 |
} |
|
315 |
} |
|
316 |
||
317 |
return bottom; |
|
318 |
} |
|
319 |
||
25946 | 320 |
bool VirtualMemoryTracker::initialize(NMT_TrackingLevel level) { |
321 |
if (level >= NMT_summary) { |
|
322 |
VirtualMemorySummary::initialize(); |
|
323 |
} |
|
324 |
return true; |
|
325 |
} |
|
326 |
||
26136
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
327 |
bool VirtualMemoryTracker::late_initialize(NMT_TrackingLevel level) { |
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
328 |
if (level >= NMT_summary) { |
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
329 |
_reserved_regions = new (std::nothrow, ResourceObj::C_HEAP, mtNMT) |
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
330 |
SortedLinkedList<ReservedMemoryRegion, compare_reserved_region_base>(); |
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
331 |
return (_reserved_regions != NULL); |
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
332 |
} |
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
333 |
return true; |
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
334 |
} |
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
335 |
|
25946 | 336 |
bool VirtualMemoryTracker::add_reserved_region(address base_addr, size_t size, |
49033
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
337 |
const NativeCallStack& stack, MEMFLAGS flag) { |
25946 | 338 |
assert(base_addr != NULL, "Invalid address"); |
339 |
assert(size > 0, "Invalid size"); |
|
26136
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
340 |
assert(_reserved_regions != NULL, "Sanity check"); |
25946 | 341 |
ReservedMemoryRegion rgn(base_addr, size, stack, flag); |
26136
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
342 |
ReservedMemoryRegion* reserved_rgn = _reserved_regions->find(rgn); |
49033
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
343 |
|
25946 | 344 |
if (reserved_rgn == NULL) { |
345 |
VirtualMemorySummary::record_reserved_memory(size, flag); |
|
49033
3acc342c0738
8196405: [REDO] NMT: add_committed_regions doesn't merge succeeding regions
stefank
parents:
48818
diff
changeset
|
346 |
return _reserved_regions->add(rgn) != NULL; |
25946 | 347 |
} else { |
348 |
if (reserved_rgn->same_region(base_addr, size)) { |
|
349 |
reserved_rgn->set_call_stack(stack); |
|
350 |
reserved_rgn->set_flag(flag); |
|
351 |
return true; |
|
352 |
} else if (reserved_rgn->adjacent_to(base_addr, size)) { |
|
353 |
VirtualMemorySummary::record_reserved_memory(size, flag); |
|
354 |
reserved_rgn->expand_region(base_addr, size); |
|
355 |
reserved_rgn->set_call_stack(stack); |
|
356 |
return true; |
|
357 |
} else { |
|
358 |
// Overlapped reservation. |
|
359 |
// It can happen when the regions are thread stacks, as JNI |
|
360 |
// thread does not detach from VM before exits, and leads to |
|
361 |
// leak JavaThread object |
|
362 |
if (reserved_rgn->flag() == mtThreadStack) { |
|
363 |
guarantee(!CheckJNICalls, "Attached JNI thread exited without being detached"); |
|
364 |
// Overwrite with new region |
|
365 |
||
366 |
// Release old region |
|
367 |
VirtualMemorySummary::record_uncommitted_memory(reserved_rgn->committed_size(), reserved_rgn->flag()); |
|
368 |
VirtualMemorySummary::record_released_memory(reserved_rgn->size(), reserved_rgn->flag()); |
|
369 |
||
370 |
// Add new region |
|
371 |
VirtualMemorySummary::record_reserved_memory(rgn.size(), flag); |
|
372 |
||
373 |
*reserved_rgn = rgn; |
|
374 |
return true; |
|
375 |
} |
|
26146
ce3202564442
8055061: assert at share/vm/services/virtualMemoryTracker.cpp:332 Error: ShouldNotReachHere() when running NMT tests
zgu
parents:
26136
diff
changeset
|
376 |
|
ce3202564442
8055061: assert at share/vm/services/virtualMemoryTracker.cpp:332 Error: ShouldNotReachHere() when running NMT tests
zgu
parents:
26136
diff
changeset
|
377 |
// CDS mapping region. |
ce3202564442
8055061: assert at share/vm/services/virtualMemoryTracker.cpp:332 Error: ShouldNotReachHere() when running NMT tests
zgu
parents:
26136
diff
changeset
|
378 |
// CDS reserves the whole region for mapping CDS archive, then maps each section into the region. |
ce3202564442
8055061: assert at share/vm/services/virtualMemoryTracker.cpp:332 Error: ShouldNotReachHere() when running NMT tests
zgu
parents:
26136
diff
changeset
|
379 |
// NMT reports CDS as a whole. |
ce3202564442
8055061: assert at share/vm/services/virtualMemoryTracker.cpp:332 Error: ShouldNotReachHere() when running NMT tests
zgu
parents:
26136
diff
changeset
|
380 |
if (reserved_rgn->flag() == mtClassShared) { |
ce3202564442
8055061: assert at share/vm/services/virtualMemoryTracker.cpp:332 Error: ShouldNotReachHere() when running NMT tests
zgu
parents:
26136
diff
changeset
|
381 |
assert(reserved_rgn->contain_region(base_addr, size), "Reserved CDS region should contain this mapping region"); |
ce3202564442
8055061: assert at share/vm/services/virtualMemoryTracker.cpp:332 Error: ShouldNotReachHere() when running NMT tests
zgu
parents:
26136
diff
changeset
|
382 |
return true; |
ce3202564442
8055061: assert at share/vm/services/virtualMemoryTracker.cpp:332 Error: ShouldNotReachHere() when running NMT tests
zgu
parents:
26136
diff
changeset
|
383 |
} |
ce3202564442
8055061: assert at share/vm/services/virtualMemoryTracker.cpp:332 Error: ShouldNotReachHere() when running NMT tests
zgu
parents:
26136
diff
changeset
|
384 |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
27162
diff
changeset
|
385 |
// Mapped CDS string region. |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
27162
diff
changeset
|
386 |
// The string region(s) is part of the java heap. |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
27162
diff
changeset
|
387 |
if (reserved_rgn->flag() == mtJavaHeap) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
27162
diff
changeset
|
388 |
assert(reserved_rgn->contain_region(base_addr, size), "Reserved heap region should contain this mapping region"); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
27162
diff
changeset
|
389 |
return true; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
27162
diff
changeset
|
390 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
27162
diff
changeset
|
391 |
|
26146
ce3202564442
8055061: assert at share/vm/services/virtualMemoryTracker.cpp:332 Error: ShouldNotReachHere() when running NMT tests
zgu
parents:
26136
diff
changeset
|
392 |
ShouldNotReachHere(); |
ce3202564442
8055061: assert at share/vm/services/virtualMemoryTracker.cpp:332 Error: ShouldNotReachHere() when running NMT tests
zgu
parents:
26136
diff
changeset
|
393 |
return false; |
25946 | 394 |
} |
395 |
} |
|
396 |
} |
|
397 |
||
398 |
void VirtualMemoryTracker::set_reserved_region_type(address addr, MEMFLAGS flag) { |
|
399 |
assert(addr != NULL, "Invalid address"); |
|
26136
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
400 |
assert(_reserved_regions != NULL, "Sanity check"); |
25946 | 401 |
|
402 |
ReservedMemoryRegion rgn(addr, 1); |
|
26136
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
403 |
ReservedMemoryRegion* reserved_rgn = _reserved_regions->find(rgn); |
25946 | 404 |
if (reserved_rgn != NULL) { |
405 |
assert(reserved_rgn->contain_address(addr), "Containment"); |
|
406 |
if (reserved_rgn->flag() != flag) { |
|
407 |
assert(reserved_rgn->flag() == mtNone, "Overwrite memory type"); |
|
408 |
reserved_rgn->set_flag(flag); |
|
409 |
} |
|
410 |
} |
|
411 |
} |
|
412 |
||
413 |
bool VirtualMemoryTracker::add_committed_region(address addr, size_t size, |
|
414 |
const NativeCallStack& stack) { |
|
415 |
assert(addr != NULL, "Invalid address"); |
|
416 |
assert(size > 0, "Invalid size"); |
|
26136
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
417 |
assert(_reserved_regions != NULL, "Sanity check"); |
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
418 |
|
25946 | 419 |
ReservedMemoryRegion rgn(addr, size); |
26136
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
420 |
ReservedMemoryRegion* reserved_rgn = _reserved_regions->find(rgn); |
25946 | 421 |
|
422 |
assert(reserved_rgn != NULL, "No reserved region"); |
|
423 |
assert(reserved_rgn->contain_region(addr, size), "Not completely contained"); |
|
38935 | 424 |
bool result = reserved_rgn->add_committed_region(addr, size, stack); |
425 |
return result; |
|
25946 | 426 |
} |
427 |
||
428 |
bool VirtualMemoryTracker::remove_uncommitted_region(address addr, size_t size) { |
|
429 |
assert(addr != NULL, "Invalid address"); |
|
430 |
assert(size > 0, "Invalid size"); |
|
26136
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
431 |
assert(_reserved_regions != NULL, "Sanity check"); |
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
432 |
|
25946 | 433 |
ReservedMemoryRegion rgn(addr, size); |
26136
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
434 |
ReservedMemoryRegion* reserved_rgn = _reserved_regions->find(rgn); |
25946 | 435 |
assert(reserved_rgn != NULL, "No reserved region"); |
436 |
assert(reserved_rgn->contain_region(addr, size), "Not completely contained"); |
|
38935 | 437 |
bool result = reserved_rgn->remove_uncommitted_region(addr, size); |
438 |
return result; |
|
25946 | 439 |
} |
440 |
||
441 |
bool VirtualMemoryTracker::remove_released_region(address addr, size_t size) { |
|
442 |
assert(addr != NULL, "Invalid address"); |
|
443 |
assert(size > 0, "Invalid size"); |
|
26136
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
444 |
assert(_reserved_regions != NULL, "Sanity check"); |
25946 | 445 |
|
446 |
ReservedMemoryRegion rgn(addr, size); |
|
26136
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
447 |
ReservedMemoryRegion* reserved_rgn = _reserved_regions->find(rgn); |
25946 | 448 |
|
449 |
assert(reserved_rgn != NULL, "No reserved region"); |
|
450 |
||
451 |
// uncommit regions within the released region |
|
452 |
if (!reserved_rgn->remove_uncommitted_region(addr, size)) { |
|
453 |
return false; |
|
454 |
} |
|
455 |
||
35483
d9cf65a7fd2d
8146523: VirtualMemoryTracker::remove_released_region double count unmapped CDS shared memory
jiangli
parents:
33127
diff
changeset
|
456 |
if (reserved_rgn->flag() == mtClassShared && |
d9cf65a7fd2d
8146523: VirtualMemoryTracker::remove_released_region double count unmapped CDS shared memory
jiangli
parents:
33127
diff
changeset
|
457 |
reserved_rgn->contain_region(addr, size) && |
d9cf65a7fd2d
8146523: VirtualMemoryTracker::remove_released_region double count unmapped CDS shared memory
jiangli
parents:
33127
diff
changeset
|
458 |
!reserved_rgn->same_region(addr, size)) { |
d9cf65a7fd2d
8146523: VirtualMemoryTracker::remove_released_region double count unmapped CDS shared memory
jiangli
parents:
33127
diff
changeset
|
459 |
// This is an unmapped CDS region, which is part of the reserved shared |
d9cf65a7fd2d
8146523: VirtualMemoryTracker::remove_released_region double count unmapped CDS shared memory
jiangli
parents:
33127
diff
changeset
|
460 |
// memory region. |
d9cf65a7fd2d
8146523: VirtualMemoryTracker::remove_released_region double count unmapped CDS shared memory
jiangli
parents:
33127
diff
changeset
|
461 |
// See special handling in VirtualMemoryTracker::add_reserved_region also. |
d9cf65a7fd2d
8146523: VirtualMemoryTracker::remove_released_region double count unmapped CDS shared memory
jiangli
parents:
33127
diff
changeset
|
462 |
return true; |
d9cf65a7fd2d
8146523: VirtualMemoryTracker::remove_released_region double count unmapped CDS shared memory
jiangli
parents:
33127
diff
changeset
|
463 |
} |
25946 | 464 |
|
465 |
VirtualMemorySummary::record_released_memory(size, reserved_rgn->flag()); |
|
466 |
||
467 |
if (reserved_rgn->same_region(addr, size)) { |
|
26136
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
468 |
return _reserved_regions->remove(rgn); |
25946 | 469 |
} else { |
470 |
assert(reserved_rgn->contain_region(addr, size), "Not completely contained"); |
|
471 |
if (reserved_rgn->base() == addr || |
|
472 |
reserved_rgn->end() == addr + size) { |
|
473 |
reserved_rgn->exclude_region(addr, size); |
|
474 |
return true; |
|
475 |
} else { |
|
476 |
address top = reserved_rgn->end(); |
|
477 |
address high_base = addr + size; |
|
478 |
ReservedMemoryRegion high_rgn(high_base, top - high_base, |
|
479 |
*reserved_rgn->call_stack(), reserved_rgn->flag()); |
|
480 |
||
481 |
// use original region for lower region |
|
482 |
reserved_rgn->exclude_region(addr, top - addr); |
|
26136
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
483 |
LinkedListNode<ReservedMemoryRegion>* new_rgn = _reserved_regions->add(high_rgn); |
25946 | 484 |
if (new_rgn == NULL) { |
485 |
return false; |
|
486 |
} else { |
|
487 |
reserved_rgn->move_committed_regions(addr, *new_rgn->data()); |
|
488 |
return true; |
|
489 |
} |
|
490 |
} |
|
491 |
} |
|
492 |
} |
|
493 |
||
49968 | 494 |
// Iterate the range, find committed region within its bound. |
495 |
class RegionIterator : public StackObj { |
|
496 |
private: |
|
497 |
const address _start; |
|
498 |
const size_t _size; |
|
499 |
||
500 |
address _current_start; |
|
501 |
size_t _current_size; |
|
502 |
public: |
|
503 |
RegionIterator(address start, size_t size) : |
|
504 |
_start(start), _size(size), _current_start(start), _current_size(size) { |
|
505 |
} |
|
506 |
||
507 |
// return true if committed region is found |
|
508 |
bool next_committed(address& start, size_t& size); |
|
509 |
private: |
|
510 |
address end() const { return _start + _size; } |
|
511 |
}; |
|
512 |
||
513 |
bool RegionIterator::next_committed(address& committed_start, size_t& committed_size) { |
|
514 |
if (end() <= _current_start) return false; |
|
515 |
||
516 |
const size_t page_sz = os::vm_page_size(); |
|
517 |
assert(_current_start + _current_size == end(), "Must be"); |
|
518 |
if (os::committed_in_range(_current_start, _current_size, committed_start, committed_size)) { |
|
519 |
assert(committed_start != NULL, "Must be"); |
|
520 |
assert(committed_size > 0 && is_aligned(committed_size, os::vm_page_size()), "Must be"); |
|
521 |
||
522 |
size_t remaining_size = (_current_start + _current_size) - (committed_start + committed_size); |
|
523 |
_current_start = committed_start + committed_size; |
|
524 |
_current_size = remaining_size; |
|
525 |
return true; |
|
526 |
} else { |
|
527 |
return false; |
|
528 |
} |
|
529 |
} |
|
530 |
||
531 |
// Walk all known thread stacks, snapshot their committed ranges. |
|
532 |
class SnapshotThreadStackWalker : public VirtualMemoryWalker { |
|
533 |
public: |
|
534 |
SnapshotThreadStackWalker() {} |
|
535 |
||
536 |
bool do_allocation_site(const ReservedMemoryRegion* rgn) { |
|
537 |
if (rgn->flag() == mtThreadStack) { |
|
538 |
address stack_bottom = rgn->thread_stack_uncommitted_bottom(); |
|
539 |
address committed_start; |
|
540 |
size_t committed_size; |
|
541 |
size_t stack_size = rgn->base() + rgn->size() - stack_bottom; |
|
542 |
||
543 |
ReservedMemoryRegion* region = const_cast<ReservedMemoryRegion*>(rgn); |
|
544 |
NativeCallStack ncs; // empty stack |
|
545 |
||
546 |
RegionIterator itr(stack_bottom, stack_size); |
|
547 |
DEBUG_ONLY(bool found_stack = false;) |
|
548 |
while (itr.next_committed(committed_start, committed_size)) { |
|
549 |
assert(committed_start != NULL, "Should not be null"); |
|
550 |
assert(committed_size > 0, "Should not be 0"); |
|
551 |
region->add_committed_region(committed_start, committed_size, ncs); |
|
552 |
DEBUG_ONLY(found_stack = true;) |
|
553 |
} |
|
554 |
#ifdef ASSERT |
|
555 |
if (!found_stack) { |
|
556 |
log_debug(thread)("Thread exited without proper cleanup, may leak thread object"); |
|
557 |
} |
|
558 |
#endif |
|
559 |
} |
|
560 |
return true; |
|
561 |
} |
|
562 |
}; |
|
563 |
||
564 |
void VirtualMemoryTracker::snapshot_thread_stacks() { |
|
565 |
SnapshotThreadStackWalker walker; |
|
566 |
walk_virtual_memory(&walker); |
|
567 |
} |
|
25946 | 568 |
|
569 |
bool VirtualMemoryTracker::walk_virtual_memory(VirtualMemoryWalker* walker) { |
|
26136
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
570 |
assert(_reserved_regions != NULL, "Sanity check"); |
25946 | 571 |
ThreadCritical tc; |
27162
0a4a7276949b
8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents:
26149
diff
changeset
|
572 |
// Check that the _reserved_regions haven't been deleted. |
0a4a7276949b
8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents:
26149
diff
changeset
|
573 |
if (_reserved_regions != NULL) { |
0a4a7276949b
8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents:
26149
diff
changeset
|
574 |
LinkedListNode<ReservedMemoryRegion>* head = _reserved_regions->head(); |
0a4a7276949b
8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents:
26149
diff
changeset
|
575 |
while (head != NULL) { |
0a4a7276949b
8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents:
26149
diff
changeset
|
576 |
const ReservedMemoryRegion* rgn = head->peek(); |
0a4a7276949b
8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents:
26149
diff
changeset
|
577 |
if (!walker->do_allocation_site(rgn)) { |
0a4a7276949b
8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents:
26149
diff
changeset
|
578 |
return false; |
0a4a7276949b
8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents:
26149
diff
changeset
|
579 |
} |
0a4a7276949b
8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents:
26149
diff
changeset
|
580 |
head = head->next(); |
25946 | 581 |
} |
27162
0a4a7276949b
8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents:
26149
diff
changeset
|
582 |
} |
25946 | 583 |
return true; |
584 |
} |
|
585 |
||
586 |
// Transition virtual memory tracking level. |
|
587 |
bool VirtualMemoryTracker::transition(NMT_TrackingLevel from, NMT_TrackingLevel to) { |
|
27162
0a4a7276949b
8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents:
26149
diff
changeset
|
588 |
assert (from != NMT_minimal, "cannot convert from the lowest tracking level to anything"); |
0a4a7276949b
8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents:
26149
diff
changeset
|
589 |
if (to == NMT_minimal) { |
25946 | 590 |
assert(from == NMT_summary || from == NMT_detail, "Just check"); |
591 |
// Clean up virtual memory tracking data structures. |
|
592 |
ThreadCritical tc; |
|
27162
0a4a7276949b
8059100: SIGSEGV VirtualMemoryTracker::remove_released_region
coleenp
parents:
26149
diff
changeset
|
593 |
// Check for potential race with other thread calling transition |
26136
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
594 |
if (_reserved_regions != NULL) { |
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
595 |
delete _reserved_regions; |
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
596 |
_reserved_regions = NULL; |
254c226e4402
8054368: nsk/jdi/VirtualMachine/exit/exit002 crash with detail tracking on (NMT2)
zgu
parents:
25946
diff
changeset
|
597 |
} |
25946 | 598 |
} |
599 |
||
600 |
return true; |
|
601 |
} |
|
47553
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
602 |
|
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
603 |
// Metaspace Support |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
604 |
MetaspaceSnapshot::MetaspaceSnapshot() { |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
605 |
for (int index = (int)Metaspace::ClassType; index < (int)Metaspace::MetadataTypeCount; index ++) { |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
606 |
Metaspace::MetadataType type = (Metaspace::MetadataType)index; |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
607 |
assert_valid_metadata_type(type); |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
608 |
_reserved_in_bytes[type] = 0; |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
609 |
_committed_in_bytes[type] = 0; |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
610 |
_used_in_bytes[type] = 0; |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
611 |
_free_in_bytes[type] = 0; |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
612 |
} |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
613 |
} |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
614 |
|
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
615 |
void MetaspaceSnapshot::snapshot(Metaspace::MetadataType type, MetaspaceSnapshot& mss) { |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
616 |
assert_valid_metadata_type(type); |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
617 |
|
49389
9ef2eee8ca7c
8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents:
49349
diff
changeset
|
618 |
mss._reserved_in_bytes[type] = MetaspaceUtils::reserved_bytes(type); |
9ef2eee8ca7c
8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents:
49349
diff
changeset
|
619 |
mss._committed_in_bytes[type] = MetaspaceUtils::committed_bytes(type); |
9ef2eee8ca7c
8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents:
49349
diff
changeset
|
620 |
mss._used_in_bytes[type] = MetaspaceUtils::used_bytes(type); |
47553
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
621 |
|
49389
9ef2eee8ca7c
8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents:
49349
diff
changeset
|
622 |
size_t free_in_bytes = (MetaspaceUtils::capacity_bytes(type) - MetaspaceUtils::used_bytes(type)) |
9ef2eee8ca7c
8199430: Rename MetaspaceAux to something more meaningful
stuefe
parents:
49349
diff
changeset
|
623 |
+ MetaspaceUtils::free_chunks_total_bytes(type) |
49980 | 624 |
+ MetaspaceUtils::free_in_vs_bytes(type); |
47553
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
625 |
mss._free_in_bytes[type] = free_in_bytes; |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
626 |
} |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
627 |
|
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
628 |
void MetaspaceSnapshot::snapshot(MetaspaceSnapshot& mss) { |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
629 |
snapshot(Metaspace::ClassType, mss); |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
630 |
if (Metaspace::using_class_space()) { |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
631 |
snapshot(Metaspace::NonClassType, mss); |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
632 |
} |
5d20359dd938
8186770: NMT: Report metadata information in NMT summary
zgu
parents:
47216
diff
changeset
|
633 |
} |