< prev index next >
src/hotspot/share/gc/shenandoah/shenandoahLock.cpp
Print this page
rev 59811 : 8247670: Shenandoah: deadlock during class unloading OOME
*** 41,50 ****
--- 41,54 ----
void ShenandoahSimpleLock::unlock() {
_lock.unlock();
}
+ bool ShenandoahSimpleLock::try_lock() {
+ return _lock.try_lock();
+ }
+
ShenandoahReentrantLock::ShenandoahReentrantLock() :
ShenandoahSimpleLock(), _owner(NULL), _count(0) {
assert(os::mutex_init_done(), "Too early!");
}
*** 62,71 ****
--- 66,90 ----
}
_count++;
}
+ bool ShenandoahReentrantLock::try_lock() {
+ Thread* const thread = Thread::current();
+ Thread* const owner = Atomic::load(&_owner);
+
+ if (owner != thread) {
+ if (!ShenandoahSimpleLock::try_lock()) {
+ return false;
+ }
+ Atomic::store(&_owner, thread);
+ }
+
+ _count++;
+ return true;
+ }
+
void ShenandoahReentrantLock::unlock() {
assert(owned_by_self(), "Invalid owner");
assert(_count > 0, "Invalid count");
_count--;
< prev index next >