Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.
/ jdk21 Public archive

Commit

Permalink
8244289: fatal error: Possible safepoint reached by thread that does …
Browse files Browse the repository at this point in the history
…not allow it

Reviewed-by: egahlin
Backport-of: 61932f49a58b73530e89e511874fbe2fbc343e99
  • Loading branch information
Markus Grönlund committed Jul 14, 2023
1 parent 281aee9 commit fd949c7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/hotspot/share/jfr/recorder/service/jfrPostBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void JfrPostBox::deposit(int new_messages) {
void JfrPostBox::asynchronous_post(int msg) {
assert(!is_synchronous(msg), "invariant");
deposit(msg);
JfrMonitorTryLock try_msg_lock(JfrMsg_lock);
JfrMutexTryLock try_msg_lock(JfrMsg_lock);
if (try_msg_lock.acquired()) {
JfrMsg_lock->notify_all();
}
Expand Down
5 changes: 3 additions & 2 deletions src/hotspot/share/jfr/recorder/storage/jfrStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "jfr/utilities/jfrIterator.hpp"
#include "jfr/utilities/jfrLinkedList.inline.hpp"
#include "jfr/utilities/jfrTime.hpp"
#include "jfr/utilities/jfrTryLock.hpp"
#include "jfr/writers/jfrNativeEventWriter.hpp"
#include "logging/log.hpp"
#include "runtime/javaThread.hpp"
Expand Down Expand Up @@ -316,7 +317,8 @@ static void log_discard(size_t pre_full_count, size_t post_full_count, size_t am
}

void JfrStorage::discard_oldest(Thread* thread) {
if (JfrBuffer_lock->try_lock()) {
JfrMutexTryLock mutex(JfrBuffer_lock);
if (mutex.acquired()) {
if (!control().should_discard()) {
// another thread handled it
return;
Expand All @@ -338,7 +340,6 @@ void JfrStorage::discard_oldest(Thread* thread) {
oldest->release(); // publish
break;
}
JfrBuffer_lock->unlock();
log_discard(num_full_pre_discard, control().full_count(), discarded_size);
}
}
Expand Down
16 changes: 7 additions & 9 deletions src/hotspot/share/jfr/utilities/jfrTryLock.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2023, 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 @@ -50,25 +50,23 @@ class JfrTryLock {
}
};

class JfrMonitorTryLock : public StackObj {
class JfrMutexTryLock : public StackObj {
private:
Monitor* _lock;
Mutex* _mutex;
bool _acquired;

public:
JfrMonitorTryLock(Monitor* lock) : _lock(lock), _acquired(lock->try_lock()) {}

~JfrMonitorTryLock() {
JfrMutexTryLock(Mutex* mutex) : _mutex(mutex), _acquired(mutex->try_lock()) {}
~JfrMutexTryLock() {
if (_acquired) {
assert(_lock->owned_by_self(), "invariant");
_lock->unlock();
assert(_mutex->owned_by_self(), "invariant");
_mutex->unlock();
}
}

bool acquired() const {
return _acquired;
}

};

#endif // SHARE_JFR_UTILITIES_JFRTRYLOCK_HPP

1 comment on commit fd949c7

@openjdk-notifier
Copy link

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.