Skip to content
Permalink
Browse files
8265682: G1: Mutex::_name dangling in HeapRegionRemSet references aft…
…er JDK-8264146

Reviewed-by: dholmes, sjohanss
  • Loading branch information
coleenp committed Apr 26, 2021
1 parent 2b09ff2 commit 222f9f07d1f75370174f5073f0b6c10695ea858d
Showing 2 changed files with 27 additions and 1 deletion.
@@ -258,6 +258,7 @@ bool Monitor::wait(int64_t timeout) {

Mutex::~Mutex() {
assert_owner(NULL);
os::free(const_cast<char*>(_name));
}

// Only Threads_lock and Heap_lock may be safepoint_check_sometimes.
@@ -266,9 +267,10 @@ bool is_sometimes_ok(const char* name) {
}

Mutex::Mutex(int Rank, const char * name, bool allow_vm_block,
SafepointCheckRequired safepoint_check_required) : _owner(NULL), _name(name) {
SafepointCheckRequired safepoint_check_required) : _owner(NULL) {
assert(os::mutex_init_done(), "Too early!");
assert(name != NULL, "Mutex requires a name");
_name = os::strdup(name, mtInternal);
#ifdef ASSERT
_allow_vm_block = allow_vm_block;
_rank = Rank;
@@ -25,8 +25,32 @@
#include "runtime/interfaceSupport.inline.hpp"
#include "runtime/mutex.hpp"
#include "runtime/mutexLocker.hpp"
#include "runtime/thread.hpp"
#include "utilities/formatBuffer.hpp"
#include "threadHelper.inline.hpp"
#include "unittest.hpp"

const int iterations = 10;
static Mutex* m[iterations];
static int i = 0;

static void create_mutex(Thread* thr) {
m[i] = new Mutex(Mutex::leaf, FormatBuffer<128>("MyLock lock #%u", i), true, Mutex::_safepoint_check_never);
i++;
}

TEST_VM(MutexName, mutex_name) {
// Create mutexes in threads, where the names are created on the thread
// stacks and then check that their names are correct.
for (int i = 0; i < iterations; i++) {
nomt_test_doer(create_mutex);
}
for (int i = 0; i < iterations; i++) {
FormatBuffer<128> f("MyLock lock #%u", i);
ASSERT_STREQ(m[i]->name(), f.buffer()) << "Wrong name!";
}
}

#ifdef ASSERT

const int rankA = 50;

1 comment on commit 222f9f0

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 222f9f0 Apr 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.