On Tue, 17 Sep 2024 22:07:40 GMT, Robert Toyonaga <[email protected]> wrote:
>> ### Summary
>> This PR just replaces `ThreadCritical` with a lock specific to NMT.
>> `ThreadCritical` is a big lock and is unnecessary for the purposes of NMT.
>> I've implemented the new lock with a semaphore so that it can be used early
>> before VM init. There is also the possibility of adding assertions in
>> places we expect NMT to have synchronization. I haven't added assertions yet
>> in many places because some code paths such as the (NMT tests) don't lock
>> yet. I think it makes sense to close any gaps in locking in another PR in
>> which I can also add more assertions.
>>
>> Testing:
>> - hotspot_nmt
>> - gtest:VirtualSpace
>> - tier1
>
> Robert Toyonaga has updated the pull request with a new target base due to a
> merge or a rebase. The pull request now contains five commits:
>
> - Merge master
> - replace tty in pd_release_memory while holding NMT lock.
> - Switch to using a Hotspot Mutex.
> - Comments. Hide assertion behind DEBUG. Replace MemoryFileTracker locker.
> make reentrant.
> - Replace ThreadCritical with a specific NMT lock
Changes requested by dholmes (Reviewer).
src/hotspot/os/windows/os_windows.cpp line 3785:
> 3783: log_warning(os)("bad release: [" PTR_FORMAT "-" PTR_FORMAT "):
> %s", p2i(start), p2i(end), err);
> 3784: #ifdef ASSERT
> 3785: fileStream fs(stderr);
tty generally prints to stdout, but now this prints to stderr. I guess it
doesn't really matter as we are about to crash anyway.
src/hotspot/share/runtime/mutexLocker.hpp line 197:
> 195: _mutex(mutex) {
> 196: bool no_safepoint_check = flag == Mutex::_no_safepoint_check_flag;
> 197: if (_mutex != nullptr && Thread::current_or_null() != nullptr) {
I do not like this addition to the mutex locker code. First, it probably needs
to be `Thread::current_or_null_safe` in case we ever lock in a signal-handling
context. But second this slows down all mutex uses. Instead `NMTLocker` should
extend ConditionalMutexLocker and make the current thread check the condition.
-------------
PR Review: https://git.openjdk.org/jdk/pull/20852#pullrequestreview-2311303401
PR Review Comment: https://git.openjdk.org/jdk/pull/20852#discussion_r1764175522
PR Review Comment: https://git.openjdk.org/jdk/pull/20852#discussion_r1764239104