Skip to content

Commit 222f9f0

Browse files
committed
8265682: G1: Mutex::_name dangling in HeapRegionRemSet references after JDK-8264146
Reviewed-by: dholmes, sjohanss
1 parent 2b09ff2 commit 222f9f0

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/hotspot/share/runtime/mutex.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ bool Monitor::wait(int64_t timeout) {
258258

259259
Mutex::~Mutex() {
260260
assert_owner(NULL);
261+
os::free(const_cast<char*>(_name));
261262
}
262263

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

268269
Mutex::Mutex(int Rank, const char * name, bool allow_vm_block,
269-
SafepointCheckRequired safepoint_check_required) : _owner(NULL), _name(name) {
270+
SafepointCheckRequired safepoint_check_required) : _owner(NULL) {
270271
assert(os::mutex_init_done(), "Too early!");
271272
assert(name != NULL, "Mutex requires a name");
273+
_name = os::strdup(name, mtInternal);
272274
#ifdef ASSERT
273275
_allow_vm_block = allow_vm_block;
274276
_rank = Rank;

test/hotspot/gtest/runtime/test_mutex_rank.cpp renamed to test/hotspot/gtest/runtime/test_mutex.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,32 @@
2525
#include "runtime/interfaceSupport.inline.hpp"
2626
#include "runtime/mutex.hpp"
2727
#include "runtime/mutexLocker.hpp"
28+
#include "runtime/thread.hpp"
29+
#include "utilities/formatBuffer.hpp"
30+
#include "threadHelper.inline.hpp"
2831
#include "unittest.hpp"
2932

33+
const int iterations = 10;
34+
static Mutex* m[iterations];
35+
static int i = 0;
36+
37+
static void create_mutex(Thread* thr) {
38+
m[i] = new Mutex(Mutex::leaf, FormatBuffer<128>("MyLock lock #%u", i), true, Mutex::_safepoint_check_never);
39+
i++;
40+
}
41+
42+
TEST_VM(MutexName, mutex_name) {
43+
// Create mutexes in threads, where the names are created on the thread
44+
// stacks and then check that their names are correct.
45+
for (int i = 0; i < iterations; i++) {
46+
nomt_test_doer(create_mutex);
47+
}
48+
for (int i = 0; i < iterations; i++) {
49+
FormatBuffer<128> f("MyLock lock #%u", i);
50+
ASSERT_STREQ(m[i]->name(), f.buffer()) << "Wrong name!";
51+
}
52+
}
53+
3054
#ifdef ASSERT
3155

3256
const int rankA = 50;

0 commit comments

Comments
 (0)