Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8276663: Cleanup NMT AccessLock #6267

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/hotspot/share/services/mallocSiteTable.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2019, 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
Expand Down Expand Up @@ -226,16 +226,16 @@ void MallocSiteTable::AccessLock::exclusiveLock() {
int val;

assert(_lock_state != ExclusiveLock, "Can only call once");
assert(*_lock >= 0, "Can not content exclusive lock");
assert(Atomic::load(_lock) >= 0, "Can not content exclusive lock");

// make counter negative to block out shared locks
do {
val = *_lock;
target = _MAGIC_ + *_lock;
} while (Atomic::cmpxchg(_lock, val, target) != val);
val = Atomic::load(_lock);
target = _MAGIC_ + val;
} while (Atomic::cmpxchg(_lock, val, target, memory_order_acquire) != val);

// wait for all readers to exit
while (*_lock != _MAGIC_) {
while (Atomic::load(_lock) != _MAGIC_) {
#ifdef _WINDOWS
os::naked_short_sleep(1);
#else
Expand Down
14 changes: 7 additions & 7 deletions src/hotspot/share/services/mallocSiteTable.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2019, 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
Expand Down Expand Up @@ -119,36 +119,36 @@ class MallocSiteTable : AllStatic {
// once exclusive access (exclusiveLock) is requested, all shared accesses are
// rejected forever.
class AccessLock : public StackObj {
private:
enum LockState {
NoLock,
SharedLock,
ExclusiveLock
};

private:
// A very large negative number. The only possibility to "overflow"
// this number is when there are more than -min_jint threads in
// this process, which is not going to happen in foreseeable future.
const static int _MAGIC_ = min_jint;

LockState _lock_state;
volatile int* _lock;
LockState _lock_state;
volatile int* const _lock;
public:
AccessLock(volatile int* lock) :
_lock_state(NoLock), _lock(lock) {
}

~AccessLock() {
if (_lock_state == SharedLock) {
Atomic::dec(_lock);
Atomic::dec(_lock, memory_order_release);
}
}
// Acquire shared lock.
// Return true if shared access is granted.
inline bool sharedLock() {
jint res = Atomic::add(_lock, 1);
jint res = Atomic::add(_lock, 1, memory_order_acquire);
if (res < 0) {
Atomic::dec(_lock);
Atomic::dec(_lock, memory_order_relaxed);
return false;
}
_lock_state = SharedLock;
Expand Down