Skip to content

Commit 5a036ac

Browse files
committed
8277990: NMT: Remove NMT shutdown capability
Reviewed-by: stuefe, shade
1 parent 7217cb7 commit 5a036ac

20 files changed

+118
-433
lines changed

src/hotspot/os/posix/perfMemory_posix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ static char* mmap_create_shared(size_t size) {
10281028
//
10291029
static void unmap_shared(char* addr, size_t bytes) {
10301030
int res;
1031-
if (MemTracker::tracking_level() > NMT_minimal) {
1031+
if (MemTracker::enabled()) {
10321032
// Note: Tracker contains a ThreadCritical.
10331033
Tracker tkr(Tracker::release);
10341034
res = ::munmap(addr, bytes);

src/hotspot/os/windows/perfMemory_windows.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1834,7 +1834,7 @@ void PerfMemory::detach(char* addr, size_t bytes) {
18341834
return;
18351835
}
18361836

1837-
if (MemTracker::tracking_level() > NMT_minimal) {
1837+
if (MemTracker::enabled()) {
18381838
// it does not go through os api, the operation has to record from here
18391839
Tracker tkr(Tracker::release);
18401840
remove_file_mapping(addr);

src/hotspot/share/gc/z/zPhysicalMemory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -282,7 +282,7 @@ void ZPhysicalMemoryManager::nmt_commit(uintptr_t offset, size_t size) const {
282282
}
283283

284284
void ZPhysicalMemoryManager::nmt_uncommit(uintptr_t offset, size_t size) const {
285-
if (MemTracker::tracking_level() > NMT_minimal) {
285+
if (MemTracker::enabled()) {
286286
const uintptr_t addr = ZAddress::marked0(offset);
287287
Tracker tracker(Tracker::uncommit);
288288
tracker.record((address)addr, size);

src/hotspot/share/prims/whitebox.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -703,37 +703,6 @@ WB_ENTRY(void, WB_NMTReleaseMemory(JNIEnv* env, jobject o, jlong addr, jlong siz
703703
os::release_memory((char *)(uintptr_t)addr, size);
704704
WB_END
705705

706-
WB_ENTRY(jboolean, WB_NMTChangeTrackingLevel(JNIEnv* env))
707-
// Test that we can downgrade NMT levels but not upgrade them.
708-
if (MemTracker::tracking_level() == NMT_off) {
709-
MemTracker::transition_to(NMT_off);
710-
return MemTracker::tracking_level() == NMT_off;
711-
} else {
712-
assert(MemTracker::tracking_level() == NMT_detail, "Should start out as detail tracking");
713-
MemTracker::transition_to(NMT_summary);
714-
assert(MemTracker::tracking_level() == NMT_summary, "Should be summary now");
715-
716-
// Can't go to detail once NMT is set to summary.
717-
MemTracker::transition_to(NMT_detail);
718-
assert(MemTracker::tracking_level() == NMT_summary, "Should still be summary now");
719-
720-
// Shutdown sets tracking level to minimal.
721-
MemTracker::shutdown();
722-
assert(MemTracker::tracking_level() == NMT_minimal, "Should be minimal now");
723-
724-
// Once the tracking level is minimal, we cannot increase to summary.
725-
// The code ignores this request instead of asserting because if the malloc site
726-
// table overflows in another thread, it tries to change the code to summary.
727-
MemTracker::transition_to(NMT_summary);
728-
assert(MemTracker::tracking_level() == NMT_minimal, "Should still be minimal now");
729-
730-
// Really can never go up to detail, verify that the code would never do this.
731-
MemTracker::transition_to(NMT_detail);
732-
assert(MemTracker::tracking_level() == NMT_minimal, "Should still be minimal now");
733-
return MemTracker::tracking_level() == NMT_minimal;
734-
}
735-
WB_END
736-
737706
WB_ENTRY(jint, WB_NMTGetHashSize(JNIEnv* env, jobject o))
738707
int hash_size = MallocSiteTable::hash_buckets();
739708
assert(hash_size > 0, "NMT hash_size should be > 0");
@@ -2567,7 +2536,6 @@ static JNINativeMethod methods[] = {
25672536
{CC"NMTCommitMemory", CC"(JJ)V", (void*)&WB_NMTCommitMemory },
25682537
{CC"NMTUncommitMemory", CC"(JJ)V", (void*)&WB_NMTUncommitMemory },
25692538
{CC"NMTReleaseMemory", CC"(JJ)V", (void*)&WB_NMTReleaseMemory },
2570-
{CC"NMTChangeTrackingLevel", CC"()Z", (void*)&WB_NMTChangeTrackingLevel},
25712539
{CC"NMTGetHashSize", CC"()I", (void*)&WB_NMTGetHashSize },
25722540
{CC"NMTNewArena", CC"(J)J", (void*)&WB_NMTNewArena },
25732541
{CC"NMTFreeArena", CC"(J)V", (void*)&WB_NMTFreeArena },

src/hotspot/share/runtime/os.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,7 @@ void os::commit_memory_or_exit(char* addr, size_t size, size_t alignment_hint,
17861786

17871787
bool os::uncommit_memory(char* addr, size_t bytes, bool executable) {
17881788
bool res;
1789-
if (MemTracker::tracking_level() > NMT_minimal) {
1789+
if (MemTracker::enabled()) {
17901790
Tracker tkr(Tracker::uncommit);
17911791
res = pd_uncommit_memory(addr, bytes, executable);
17921792
if (res) {
@@ -1800,7 +1800,7 @@ bool os::uncommit_memory(char* addr, size_t bytes, bool executable) {
18001800

18011801
bool os::release_memory(char* addr, size_t bytes) {
18021802
bool res;
1803-
if (MemTracker::tracking_level() > NMT_minimal) {
1803+
if (MemTracker::enabled()) {
18041804
// Note: Tracker contains a ThreadCritical.
18051805
Tracker tkr(Tracker::release);
18061806
res = pd_release_memory(addr, bytes);
@@ -1869,7 +1869,7 @@ char* os::remap_memory(int fd, const char* file_name, size_t file_offset,
18691869

18701870
bool os::unmap_memory(char *addr, size_t bytes) {
18711871
bool result;
1872-
if (MemTracker::tracking_level() > NMT_minimal) {
1872+
if (MemTracker::enabled()) {
18731873
Tracker tkr(Tracker::release);
18741874
result = pd_unmap_memory(addr, bytes);
18751875
if (result) {
@@ -1905,7 +1905,7 @@ char* os::reserve_memory_special(size_t size, size_t alignment, size_t page_size
19051905

19061906
bool os::release_memory_special(char* addr, size_t bytes) {
19071907
bool res;
1908-
if (MemTracker::tracking_level() > NMT_minimal) {
1908+
if (MemTracker::enabled()) {
19091909
// Note: Tracker contains a ThreadCritical.
19101910
Tracker tkr(Tracker::release);
19111911
res = pd_release_memory_special(addr, bytes);

src/hotspot/share/services/mallocSiteTable.cpp

Lines changed: 64 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -33,12 +33,6 @@ MallocSiteHashtableEntry* MallocSiteTable::_table[MallocSiteTable::table_size];
3333
const NativeCallStack* MallocSiteTable::_hash_entry_allocation_stack = NULL;
3434
const MallocSiteHashtableEntry* MallocSiteTable::_hash_entry_allocation_site = NULL;
3535

36-
// concurrent access counter
37-
volatile int MallocSiteTable::_access_count = 0;
38-
39-
// Tracking hashtable contention
40-
NOT_PRODUCT(int MallocSiteTable::_peak_count = 0;)
41-
4236
/*
4337
* Initialize malloc site table.
4438
* Hashtable entry is malloc'd, so it can cause infinite recursion.
@@ -202,122 +196,81 @@ void MallocSiteTable::delete_linked_list(MallocSiteHashtableEntry* head) {
202196
}
203197
}
204198

205-
void MallocSiteTable::shutdown() {
206-
AccessLock locker(&_access_count);
207-
locker.exclusiveLock();
208-
reset();
209-
}
210-
211199
bool MallocSiteTable::walk_malloc_site(MallocSiteWalker* walker) {
212200
assert(walker != NULL, "NuLL walker");
213-
AccessLock locker(&_access_count);
214-
if (locker.sharedLock()) {
215-
NOT_PRODUCT(_peak_count = MAX2(_peak_count, _access_count);)
216-
return walk(walker);
217-
}
218-
return false;
219-
}
220-
221-
222-
void MallocSiteTable::AccessLock::exclusiveLock() {
223-
int target;
224-
int val;
225-
226-
assert(_lock_state != ExclusiveLock, "Can only call once");
227-
assert(*_lock >= 0, "Can not content exclusive lock");
228-
229-
// make counter negative to block out shared locks
230-
do {
231-
val = *_lock;
232-
target = _MAGIC_ + *_lock;
233-
} while (Atomic::cmpxchg(_lock, val, target) != val);
234-
235-
// wait for all readers to exit
236-
while (*_lock != _MAGIC_) {
237-
#ifdef _WINDOWS
238-
os::naked_short_sleep(1);
239-
#else
240-
os::naked_yield();
241-
#endif
242-
}
243-
_lock_state = ExclusiveLock;
201+
return walk(walker);
244202
}
245203

246204
void MallocSiteTable::print_tuning_statistics(outputStream* st) {
247-
248-
AccessLock locker(&_access_count);
249-
if (locker.sharedLock()) {
250-
// Total number of allocation sites, include empty sites
251-
int total_entries = 0;
252-
// Number of allocation sites that have all memory freed
253-
int empty_entries = 0;
254-
// Number of captured call stack distribution
255-
int stack_depth_distribution[NMT_TrackingStackDepth + 1] = { 0 };
256-
// Chain lengths
257-
int lengths[table_size] = { 0 };
258-
259-
for (int i = 0; i < table_size; i ++) {
260-
int this_chain_length = 0;
261-
const MallocSiteHashtableEntry* head = _table[i];
262-
while (head != NULL) {
263-
total_entries ++;
264-
this_chain_length ++;
265-
if (head->size() == 0) {
266-
empty_entries ++;
267-
}
268-
const int callstack_depth = head->peek()->call_stack()->frames();
269-
assert(callstack_depth >= 0 && callstack_depth <= NMT_TrackingStackDepth,
270-
"Sanity (%d)", callstack_depth);
271-
stack_depth_distribution[callstack_depth] ++;
272-
head = head->next();
273-
}
274-
lengths[i] = this_chain_length;
275-
}
276-
277-
st->print_cr("Malloc allocation site table:");
278-
st->print_cr("\tTotal entries: %d", total_entries);
279-
st->print_cr("\tEmpty entries: %d (%2.2f%%)", empty_entries, ((float)empty_entries * 100) / total_entries);
280-
st->cr();
281-
282-
// We report the hash distribution (chain length distribution) of the n shortest chains
283-
// - under the assumption that this usually contains all lengths. Reporting threshold
284-
// is 20, and the expected avg chain length is 5..6 (see table size).
285-
static const int chain_length_threshold = 20;
286-
int chain_length_distribution[chain_length_threshold] = { 0 };
287-
int over_threshold = 0;
288-
int longest_chain_length = 0;
289-
for (int i = 0; i < table_size; i ++) {
290-
if (lengths[i] >= chain_length_threshold) {
291-
over_threshold ++;
292-
} else {
293-
chain_length_distribution[lengths[i]] ++;
205+
// Total number of allocation sites, include empty sites
206+
int total_entries = 0;
207+
// Number of allocation sites that have all memory freed
208+
int empty_entries = 0;
209+
// Number of captured call stack distribution
210+
int stack_depth_distribution[NMT_TrackingStackDepth + 1] = { 0 };
211+
// Chain lengths
212+
int lengths[table_size] = { 0 };
213+
214+
for (int i = 0; i < table_size; i ++) {
215+
int this_chain_length = 0;
216+
const MallocSiteHashtableEntry* head = _table[i];
217+
while (head != NULL) {
218+
total_entries ++;
219+
this_chain_length ++;
220+
if (head->size() == 0) {
221+
empty_entries ++;
294222
}
295-
longest_chain_length = MAX2(longest_chain_length, lengths[i]);
223+
const int callstack_depth = head->peek()->call_stack()->frames();
224+
assert(callstack_depth >= 0 && callstack_depth <= NMT_TrackingStackDepth,
225+
"Sanity (%d)", callstack_depth);
226+
stack_depth_distribution[callstack_depth] ++;
227+
head = head->next();
296228
}
229+
lengths[i] = this_chain_length;
230+
}
297231

298-
st->print_cr("Hash distribution:");
299-
if (chain_length_distribution[0] == 0) {
300-
st->print_cr("no empty buckets.");
232+
st->print_cr("Malloc allocation site table:");
233+
st->print_cr("\tTotal entries: %d", total_entries);
234+
st->print_cr("\tEmpty entries: %d (%2.2f%%)", empty_entries, ((float)empty_entries * 100) / total_entries);
235+
st->cr();
236+
237+
// We report the hash distribution (chain length distribution) of the n shortest chains
238+
// - under the assumption that this usually contains all lengths. Reporting threshold
239+
// is 20, and the expected avg chain length is 5..6 (see table size).
240+
static const int chain_length_threshold = 20;
241+
int chain_length_distribution[chain_length_threshold] = { 0 };
242+
int over_threshold = 0;
243+
int longest_chain_length = 0;
244+
for (int i = 0; i < table_size; i ++) {
245+
if (lengths[i] >= chain_length_threshold) {
246+
over_threshold ++;
301247
} else {
302-
st->print_cr("%d buckets are empty.", chain_length_distribution[0]);
303-
}
304-
for (int len = 1; len < MIN2(longest_chain_length + 1, chain_length_threshold); len ++) {
305-
st->print_cr("%2d %s: %d.", len, (len == 1 ? " entry" : "entries"), chain_length_distribution[len]);
248+
chain_length_distribution[lengths[i]] ++;
306249
}
307-
if (longest_chain_length >= chain_length_threshold) {
308-
st->print_cr(">=%2d entries: %d.", chain_length_threshold, over_threshold);
309-
}
310-
st->print_cr("most entries: %d.", longest_chain_length);
311-
st->cr();
250+
longest_chain_length = MAX2(longest_chain_length, lengths[i]);
251+
}
312252

313-
st->print_cr("Call stack depth distribution:");
314-
for (int i = 0; i <= NMT_TrackingStackDepth; i ++) {
315-
st->print_cr("\t%d: %d", i, stack_depth_distribution[i]);
316-
}
317-
st->cr();
318-
} // lock
319-
}
253+
st->print_cr("Hash distribution:");
254+
if (chain_length_distribution[0] == 0) {
255+
st->print_cr("no empty buckets.");
256+
} else {
257+
st->print_cr("%d buckets are empty.", chain_length_distribution[0]);
258+
}
259+
for (int len = 1; len < MIN2(longest_chain_length + 1, chain_length_threshold); len ++) {
260+
st->print_cr("%2d %s: %d.", len, (len == 1 ? " entry" : "entries"), chain_length_distribution[len]);
261+
}
262+
if (longest_chain_length >= chain_length_threshold) {
263+
st->print_cr(">=%2d entries: %d.", chain_length_threshold, over_threshold);
264+
}
265+
st->print_cr("most entries: %d.", longest_chain_length);
266+
st->cr();
320267

268+
st->print_cr("Call stack depth distribution:");
269+
for (int i = 0; i <= NMT_TrackingStackDepth; i ++) {
270+
st->print_cr("\t%d: %d", i, stack_depth_distribution[i]);
271+
}
272+
st->cr();
273+
}
321274

322275
bool MallocSiteHashtableEntry::atomic_insert(MallocSiteHashtableEntry* entry) {
323276
return Atomic::replace_if_null(&_next, entry);

0 commit comments

Comments
 (0)