mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-19 10:34:38 +02:00
8261600: NMT: Relax memory order for updating MemoryCounter and fix racy updating of peak values
Reviewed-by: dholmes, shade
This commit is contained in:
parent
1a7adc8642
commit
f94a845287
2 changed files with 53 additions and 19 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -30,6 +30,36 @@
|
|||
|
||||
size_t MallocMemorySummary::_snapshot[CALC_OBJ_SIZE_IN_TYPE(MallocMemorySnapshot, size_t)];
|
||||
|
||||
#ifdef ASSERT
|
||||
void MemoryCounter::update_peak_count(size_t count) {
|
||||
size_t peak_cnt = peak_count();
|
||||
while (peak_cnt < count) {
|
||||
size_t old_cnt = Atomic::cmpxchg(&_peak_count, peak_cnt, count, memory_order_relaxed);
|
||||
if (old_cnt != peak_cnt) {
|
||||
peak_cnt = old_cnt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryCounter::update_peak_size(size_t sz) {
|
||||
size_t peak_sz = peak_size();
|
||||
while (peak_sz < sz) {
|
||||
size_t old_sz = Atomic::cmpxchg(&_peak_size, peak_sz, sz, memory_order_relaxed);
|
||||
if (old_sz != peak_sz) {
|
||||
peak_sz = old_sz;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t MemoryCounter::peak_count() const {
|
||||
return Atomic::load(&_peak_count);
|
||||
}
|
||||
|
||||
size_t MemoryCounter::peak_size() const {
|
||||
return Atomic::load(&_peak_size);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Total malloc'd memory amount
|
||||
size_t MallocMemorySnapshot::total() const {
|
||||
size_t amount = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue