8343726: [BACKOUT] NMT should not use ThreadCritical
Reviewed-by: shade, dholmes
This commit is contained in:
parent
0e1c1b793d
commit
c3df050b88
@ -1086,7 +1086,7 @@ static char* mmap_create_shared(size_t size) {
|
||||
static void unmap_shared(char* addr, size_t bytes) {
|
||||
int res;
|
||||
if (MemTracker::enabled()) {
|
||||
NmtVirtualMemoryLocker ml;
|
||||
ThreadCritical tc;
|
||||
res = ::munmap(addr, bytes);
|
||||
if (res == 0) {
|
||||
MemTracker::record_virtual_memory_release((address)addr, bytes);
|
||||
|
@ -3825,8 +3825,7 @@ bool os::pd_release_memory(char* addr, size_t bytes) {
|
||||
if (err != nullptr) {
|
||||
log_warning(os)("bad release: [" PTR_FORMAT "-" PTR_FORMAT "): %s", p2i(start), p2i(end), err);
|
||||
#ifdef ASSERT
|
||||
fileStream fs(stdout);
|
||||
os::print_memory_mappings((char*)start, bytes, &fs);
|
||||
os::print_memory_mappings((char*)start, bytes, tty);
|
||||
assert(false, "bad release: [" PTR_FORMAT "-" PTR_FORMAT "): %s", p2i(start), p2i(end), err);
|
||||
#endif
|
||||
return false;
|
||||
|
@ -1803,7 +1803,7 @@ void PerfMemory::detach(char* addr, size_t bytes) {
|
||||
|
||||
if (MemTracker::enabled()) {
|
||||
// it does not go through os api, the operation has to record from here
|
||||
NmtVirtualMemoryLocker ml;
|
||||
ThreadCritical tc;
|
||||
remove_file_mapping(addr);
|
||||
MemTracker::record_virtual_memory_release((address)addr, bytes);
|
||||
} else {
|
||||
|
@ -141,7 +141,7 @@ void MemBaseline::baseline_summary() {
|
||||
MallocMemorySummary::snapshot(&_malloc_memory_snapshot);
|
||||
VirtualMemorySummary::snapshot(&_virtual_memory_snapshot);
|
||||
{
|
||||
NmtVirtualMemoryLocker ml;
|
||||
MemoryFileTracker::Instance::Locker lock;
|
||||
MemoryFileTracker::Instance::summary_snapshot(&_virtual_memory_snapshot);
|
||||
}
|
||||
|
||||
|
@ -465,7 +465,7 @@ void MemDetailReporter::report_virtual_memory_region(const ReservedMemoryRegion*
|
||||
void MemDetailReporter::report_memory_file_allocations() {
|
||||
stringStream st;
|
||||
{
|
||||
NmtVirtualMemoryLocker ml;
|
||||
MemoryFileTracker::Instance::Locker lock;
|
||||
MemoryFileTracker::Instance::print_all_reports_on(&st, scale());
|
||||
}
|
||||
output()->print_raw(st.freeze());
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "nmt/threadStackTracker.hpp"
|
||||
#include "nmt/virtualMemoryTracker.hpp"
|
||||
#include "runtime/mutexLocker.hpp"
|
||||
#include "runtime/threadCritical.hpp"
|
||||
#include "utilities/debug.hpp"
|
||||
#include "utilities/nativeCallStack.hpp"
|
||||
|
||||
@ -124,7 +125,7 @@ class MemTracker : AllStatic {
|
||||
assert_post_init();
|
||||
if (!enabled()) return;
|
||||
if (addr != nullptr) {
|
||||
NmtVirtualMemoryLocker ml;
|
||||
ThreadCritical tc;
|
||||
VirtualMemoryTracker::add_reserved_region((address)addr, size, stack, mem_tag);
|
||||
}
|
||||
}
|
||||
@ -150,7 +151,7 @@ class MemTracker : AllStatic {
|
||||
assert_post_init();
|
||||
if (!enabled()) return;
|
||||
if (addr != nullptr) {
|
||||
NmtVirtualMemoryLocker ml;
|
||||
ThreadCritical tc;
|
||||
VirtualMemoryTracker::add_reserved_region((address)addr, size, stack, mem_tag);
|
||||
VirtualMemoryTracker::add_committed_region((address)addr, size, stack);
|
||||
}
|
||||
@ -161,7 +162,7 @@ class MemTracker : AllStatic {
|
||||
assert_post_init();
|
||||
if (!enabled()) return;
|
||||
if (addr != nullptr) {
|
||||
NmtVirtualMemoryLocker ml;
|
||||
ThreadCritical tc;
|
||||
VirtualMemoryTracker::add_committed_region((address)addr, size, stack);
|
||||
}
|
||||
}
|
||||
@ -169,7 +170,7 @@ class MemTracker : AllStatic {
|
||||
static inline MemoryFileTracker::MemoryFile* register_file(const char* descriptive_name) {
|
||||
assert_post_init();
|
||||
if (!enabled()) return nullptr;
|
||||
NmtVirtualMemoryLocker ml;
|
||||
MemoryFileTracker::Instance::Locker lock;
|
||||
return MemoryFileTracker::Instance::make_file(descriptive_name);
|
||||
}
|
||||
|
||||
@ -177,7 +178,7 @@ class MemTracker : AllStatic {
|
||||
assert_post_init();
|
||||
if (!enabled()) return;
|
||||
assert(file != nullptr, "must be");
|
||||
NmtVirtualMemoryLocker ml;
|
||||
MemoryFileTracker::Instance::Locker lock;
|
||||
MemoryFileTracker::Instance::free_file(file);
|
||||
}
|
||||
|
||||
@ -186,7 +187,7 @@ class MemTracker : AllStatic {
|
||||
assert_post_init();
|
||||
if (!enabled()) return;
|
||||
assert(file != nullptr, "must be");
|
||||
NmtVirtualMemoryLocker ml;
|
||||
MemoryFileTracker::Instance::Locker lock;
|
||||
MemoryFileTracker::Instance::allocate_memory(file, offset, size, stack, mem_tag);
|
||||
}
|
||||
|
||||
@ -195,7 +196,7 @@ class MemTracker : AllStatic {
|
||||
assert_post_init();
|
||||
if (!enabled()) return;
|
||||
assert(file != nullptr, "must be");
|
||||
NmtVirtualMemoryLocker ml;
|
||||
MemoryFileTracker::Instance::Locker lock;
|
||||
MemoryFileTracker::Instance::free_memory(file, offset, size);
|
||||
}
|
||||
|
||||
@ -209,7 +210,7 @@ class MemTracker : AllStatic {
|
||||
assert_post_init();
|
||||
if (!enabled()) return;
|
||||
if (addr != nullptr) {
|
||||
NmtVirtualMemoryLocker ml;
|
||||
ThreadCritical tc;
|
||||
VirtualMemoryTracker::split_reserved_region((address)addr, size, split, mem_tag, split_tag);
|
||||
}
|
||||
}
|
||||
@ -218,7 +219,7 @@ class MemTracker : AllStatic {
|
||||
assert_post_init();
|
||||
if (!enabled()) return;
|
||||
if (addr != nullptr) {
|
||||
NmtVirtualMemoryLocker ml;
|
||||
ThreadCritical tc;
|
||||
VirtualMemoryTracker::set_reserved_region_type((address)addr, mem_tag);
|
||||
}
|
||||
}
|
||||
|
@ -29,11 +29,13 @@
|
||||
#include "nmt/nmtCommon.hpp"
|
||||
#include "nmt/nmtNativeCallStackStorage.hpp"
|
||||
#include "nmt/vmatree.hpp"
|
||||
#include "runtime/mutex.hpp"
|
||||
#include "utilities/growableArray.hpp"
|
||||
#include "utilities/nativeCallStack.hpp"
|
||||
#include "utilities/ostream.hpp"
|
||||
|
||||
MemoryFileTracker* MemoryFileTracker::Instance::_tracker = nullptr;
|
||||
PlatformMutex* MemoryFileTracker::Instance::_mutex = nullptr;
|
||||
|
||||
MemoryFileTracker::MemoryFileTracker(bool is_detailed_mode)
|
||||
: _stack_storage(is_detailed_mode), _files() {}
|
||||
@ -130,6 +132,7 @@ bool MemoryFileTracker::Instance::initialize(NMT_TrackingLevel tracking_level) {
|
||||
_tracker = static_cast<MemoryFileTracker*>(os::malloc(sizeof(MemoryFileTracker), mtNMT));
|
||||
if (_tracker == nullptr) return false;
|
||||
new (_tracker) MemoryFileTracker(tracking_level == NMT_TrackingLevel::NMT_detail);
|
||||
_mutex = new PlatformMutex();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -190,3 +193,11 @@ void MemoryFileTracker::summary_snapshot(VirtualMemorySnapshot* snapshot) const
|
||||
void MemoryFileTracker::Instance::summary_snapshot(VirtualMemorySnapshot* snapshot) {
|
||||
_tracker->summary_snapshot(snapshot);
|
||||
}
|
||||
|
||||
MemoryFileTracker::Instance::Locker::Locker() {
|
||||
MemoryFileTracker::Instance::_mutex->lock();
|
||||
}
|
||||
|
||||
MemoryFileTracker::Instance::Locker::~Locker() {
|
||||
MemoryFileTracker::Instance::_mutex->unlock();
|
||||
}
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "nmt/nmtNativeCallStackStorage.hpp"
|
||||
#include "nmt/virtualMemoryTracker.hpp"
|
||||
#include "nmt/vmatree.hpp"
|
||||
#include "runtime/mutex.hpp"
|
||||
#include "runtime/os.inline.hpp"
|
||||
#include "utilities/growableArray.hpp"
|
||||
#include "utilities/nativeCallStack.hpp"
|
||||
@ -80,8 +81,14 @@ public:
|
||||
|
||||
class Instance : public AllStatic {
|
||||
static MemoryFileTracker* _tracker;
|
||||
static PlatformMutex* _mutex;
|
||||
|
||||
public:
|
||||
class Locker : public StackObj {
|
||||
public:
|
||||
Locker();
|
||||
~Locker();
|
||||
};
|
||||
|
||||
static bool initialize(NMT_TrackingLevel tracking_level);
|
||||
|
||||
|
@ -29,8 +29,6 @@
|
||||
|
||||
#include "memory/allStatic.hpp"
|
||||
#include "nmt/memTag.hpp"
|
||||
#include "runtime/mutexLocker.hpp"
|
||||
#include "runtime/thread.hpp"
|
||||
#include "utilities/align.hpp"
|
||||
#include "utilities/globalDefinitions.hpp"
|
||||
|
||||
@ -139,13 +137,5 @@ class NMTUtil : AllStatic {
|
||||
static S _strings[mt_number_of_tags];
|
||||
};
|
||||
|
||||
// Same as MutexLocker but can be used during VM init.
|
||||
// Performs no action if given a null mutex or with detached threads.
|
||||
class NmtVirtualMemoryLocker: public ConditionalMutexLocker {
|
||||
public:
|
||||
NmtVirtualMemoryLocker() :
|
||||
ConditionalMutexLocker(NmtVirtualMemory_lock, Thread::current_or_null_safe() != nullptr, Mutex::_no_safepoint_check_flag) {
|
||||
}
|
||||
};
|
||||
|
||||
#endif // SHARE_NMT_NMTCOMMON_HPP
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "nmt/threadStackTracker.hpp"
|
||||
#include "nmt/virtualMemoryTracker.hpp"
|
||||
#include "runtime/os.hpp"
|
||||
#include "runtime/threadCritical.hpp"
|
||||
#include "utilities/align.hpp"
|
||||
#include "utilities/debug.hpp"
|
||||
#include "utilities/globalDefinitions.hpp"
|
||||
@ -52,7 +53,7 @@ void ThreadStackTracker::new_thread_stack(void* base, size_t size, const NativeC
|
||||
assert(base != nullptr, "Should have been filtered");
|
||||
align_thread_stack_boundaries_inward(base, size);
|
||||
|
||||
NmtVirtualMemoryLocker ml;
|
||||
ThreadCritical tc;
|
||||
VirtualMemoryTracker::add_reserved_region((address)base, size, stack, mtThreadStack);
|
||||
_thread_count++;
|
||||
}
|
||||
@ -62,7 +63,7 @@ void ThreadStackTracker::delete_thread_stack(void* base, size_t size) {
|
||||
assert(base != nullptr, "Should have been filtered");
|
||||
align_thread_stack_boundaries_inward(base, size);
|
||||
|
||||
NmtVirtualMemoryLocker ml;
|
||||
ThreadCritical tc;
|
||||
VirtualMemoryTracker::remove_released_region((address)base, size);
|
||||
_thread_count--;
|
||||
}
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "nmt/threadStackTracker.hpp"
|
||||
#include "nmt/virtualMemoryTracker.hpp"
|
||||
#include "runtime/os.hpp"
|
||||
#include "runtime/threadCritical.hpp"
|
||||
#include "utilities/ostream.hpp"
|
||||
|
||||
VirtualMemorySnapshot VirtualMemorySummary::_snapshot;
|
||||
@ -620,7 +621,6 @@ public:
|
||||
SnapshotThreadStackWalker() {}
|
||||
|
||||
bool do_allocation_site(const ReservedMemoryRegion* rgn) {
|
||||
assert_lock_strong(NmtVirtualMemory_lock);
|
||||
if (rgn->mem_tag() == mtThreadStack) {
|
||||
address stack_bottom = rgn->thread_stack_uncommitted_bottom();
|
||||
address committed_start;
|
||||
@ -661,7 +661,7 @@ void VirtualMemoryTracker::snapshot_thread_stacks() {
|
||||
|
||||
bool VirtualMemoryTracker::walk_virtual_memory(VirtualMemoryWalker* walker) {
|
||||
assert(_reserved_regions != nullptr, "Sanity check");
|
||||
NmtVirtualMemoryLocker ml;
|
||||
ThreadCritical tc;
|
||||
// Check that the _reserved_regions haven't been deleted.
|
||||
if (_reserved_regions != nullptr) {
|
||||
LinkedListNode<ReservedMemoryRegion>* head = _reserved_regions->head();
|
||||
|
@ -135,7 +135,6 @@ Mutex* SharedDecoder_lock = nullptr;
|
||||
Mutex* DCmdFactory_lock = nullptr;
|
||||
Mutex* NMTQuery_lock = nullptr;
|
||||
Mutex* NMTCompilationCostHistory_lock = nullptr;
|
||||
Mutex* NmtVirtualMemory_lock = nullptr;
|
||||
|
||||
#if INCLUDE_CDS
|
||||
#if INCLUDE_JVMTI
|
||||
@ -294,11 +293,10 @@ void mutex_init() {
|
||||
MUTEX_DEFN(CodeHeapStateAnalytics_lock , PaddedMutex , safepoint);
|
||||
MUTEX_DEFN(ThreadsSMRDelete_lock , PaddedMonitor, service-2); // Holds ConcurrentHashTableResize_lock
|
||||
MUTEX_DEFN(ThreadIdTableCreate_lock , PaddedMutex , safepoint);
|
||||
MUTEX_DEFN(SharedDecoder_lock , PaddedMutex , service-5); // Must be lower than NmtVirtualMemory_lock due to MemTracker::print_containing_region
|
||||
MUTEX_DEFN(SharedDecoder_lock , PaddedMutex , tty-1);
|
||||
MUTEX_DEFN(DCmdFactory_lock , PaddedMutex , nosafepoint);
|
||||
MUTEX_DEFN(NMTQuery_lock , PaddedMutex , safepoint);
|
||||
MUTEX_DEFN(NMTCompilationCostHistory_lock , PaddedMutex , nosafepoint);
|
||||
MUTEX_DEFN(NmtVirtualMemory_lock , PaddedMutex , service-4);
|
||||
#if INCLUDE_CDS
|
||||
#if INCLUDE_JVMTI
|
||||
MUTEX_DEFN(CDSClassFileStream_lock , PaddedMutex , safepoint);
|
||||
|
@ -117,7 +117,6 @@ extern Mutex* SharedDecoder_lock; // serializes access to the dec
|
||||
extern Mutex* DCmdFactory_lock; // serialize access to DCmdFactory information
|
||||
extern Mutex* NMTQuery_lock; // serialize NMT Dcmd queries
|
||||
extern Mutex* NMTCompilationCostHistory_lock; // guards NMT compilation cost history
|
||||
extern Mutex* NmtVirtualMemory_lock; // guards NMT virtual memory updates
|
||||
#if INCLUDE_CDS
|
||||
#if INCLUDE_JVMTI
|
||||
extern Mutex* CDSClassFileStream_lock; // FileMapInfo::open_stream_for_jvmti
|
||||
|
@ -2186,7 +2186,7 @@ bool os::uncommit_memory(char* addr, size_t bytes, bool executable) {
|
||||
assert_nonempty_range(addr, bytes);
|
||||
bool res;
|
||||
if (MemTracker::enabled()) {
|
||||
NmtVirtualMemoryLocker ml;
|
||||
ThreadCritical tc;
|
||||
res = pd_uncommit_memory(addr, bytes, executable);
|
||||
if (res) {
|
||||
MemTracker::record_virtual_memory_uncommit((address)addr, bytes);
|
||||
@ -2208,7 +2208,7 @@ bool os::release_memory(char* addr, size_t bytes) {
|
||||
assert_nonempty_range(addr, bytes);
|
||||
bool res;
|
||||
if (MemTracker::enabled()) {
|
||||
NmtVirtualMemoryLocker ml;
|
||||
ThreadCritical tc;
|
||||
res = pd_release_memory(addr, bytes);
|
||||
if (res) {
|
||||
MemTracker::record_virtual_memory_release((address)addr, bytes);
|
||||
@ -2293,7 +2293,7 @@ char* os::map_memory(int fd, const char* file_name, size_t file_offset,
|
||||
bool os::unmap_memory(char *addr, size_t bytes) {
|
||||
bool result;
|
||||
if (MemTracker::enabled()) {
|
||||
NmtVirtualMemoryLocker ml;
|
||||
ThreadCritical tc;
|
||||
result = pd_unmap_memory(addr, bytes);
|
||||
if (result) {
|
||||
MemTracker::record_virtual_memory_release((address)addr, bytes);
|
||||
@ -2332,7 +2332,7 @@ char* os::reserve_memory_special(size_t size, size_t alignment, size_t page_size
|
||||
bool os::release_memory_special(char* addr, size_t bytes) {
|
||||
bool res;
|
||||
if (MemTracker::enabled()) {
|
||||
NmtVirtualMemoryLocker ml;
|
||||
ThreadCritical tc;
|
||||
res = pd_release_memory_special(addr, bytes);
|
||||
if (res) {
|
||||
MemTracker::record_virtual_memory_release((address)addr, bytes);
|
||||
|
@ -717,10 +717,6 @@ void VMError::report(outputStream* st, bool _verbose) {
|
||||
address lastpc = nullptr;
|
||||
|
||||
BEGIN
|
||||
if (MemTracker::enabled() && NmtVirtualMemory_lock != nullptr && NmtVirtualMemory_lock->owned_by_self()) {
|
||||
// Manually unlock to avoid reentrancy due to mallocs in detailed mode.
|
||||
NmtVirtualMemory_lock->unlock();
|
||||
}
|
||||
|
||||
STEP("printing fatal error message")
|
||||
st->print_cr("#");
|
||||
|
Loading…
x
Reference in New Issue
Block a user