Skip to content

Commit 12d6ec6

Browse files
committed
8307236: Rendezvous GC threads under STS for monitor deflation
Reviewed-by: eosterlund, shade
1 parent 6fe959c commit 12d6ec6

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

src/hotspot/share/runtime/monitorDeflationThread.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class MonitorDeflationThread : public JavaThread {
4141

4242
// Hide this thread from external view.
4343
bool is_hidden_from_external_view() const { return true; }
44+
45+
bool is_monitor_deflation_thread() const { return true; }
4446
};
4547

4648
#endif // SHARE_RUNTIME_MONITORDEFLATIONTHREAD_HPP

src/hotspot/share/runtime/synchronizer.cpp

+21-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include "precompiled.hpp"
2626
#include "classfile/vmSymbols.hpp"
27+
#include "gc/shared/suspendibleThreadSet.hpp"
2728
#include "jfr/jfrEvents.hpp"
2829
#include "logging/log.hpp"
2930
#include "logging/logStream.hpp"
@@ -1473,6 +1474,16 @@ class HandshakeForDeflation : public HandshakeClosure {
14731474
}
14741475
};
14751476

1477+
class VM_RendezvousGCThreads : public VM_Operation {
1478+
public:
1479+
bool evaluate_at_safepoint() const override { return false; }
1480+
VMOp_Type type() const override { return VMOp_RendezvousGCThreads; }
1481+
void doit() override {
1482+
SuspendibleThreadSet::synchronize();
1483+
SuspendibleThreadSet::desynchronize();
1484+
};
1485+
};
1486+
14761487
// This function is called by the MonitorDeflationThread to deflate
14771488
// ObjectMonitors. It is also called via do_final_audit_and_print_stats()
14781489
// and VM_ThreadDump::doit() by the VMThread.
@@ -1514,7 +1525,7 @@ size_t ObjectSynchronizer::deflate_idle_monitors(ObjectMonitorsHashtable* table)
15141525
ResourceMark rm;
15151526
GrowableArray<ObjectMonitor*> delete_list((int)deflated_count);
15161527
unlinked_count = _in_use_list.unlink_deflated(current, ls, &timer, &delete_list);
1517-
if (current->is_Java_thread()) {
1528+
if (current->is_monitor_deflation_thread()) {
15181529
if (ls != nullptr) {
15191530
timer.stop();
15201531
ls->print_cr("before handshaking: unlinked_count=" SIZE_FORMAT
@@ -1528,13 +1539,22 @@ size_t ObjectSynchronizer::deflate_idle_monitors(ObjectMonitorsHashtable* table)
15281539
// ObjectMonitors that were deflated in this cycle.
15291540
HandshakeForDeflation hfd_hc;
15301541
Handshake::execute(&hfd_hc);
1542+
// Also, we sync and desync GC threads around the handshake, so that they can
1543+
// safely read the mark-word and look-through to the object-monitor, without
1544+
// being afraid that the object-monitor is going away.
1545+
VM_RendezvousGCThreads sync_gc;
1546+
VMThread::execute(&sync_gc);
15311547

15321548
if (ls != nullptr) {
15331549
ls->print_cr("after handshaking: in_use_list stats: ceiling="
15341550
SIZE_FORMAT ", count=" SIZE_FORMAT ", max=" SIZE_FORMAT,
15351551
in_use_list_ceiling(), _in_use_list.count(), _in_use_list.max());
15361552
timer.start();
15371553
}
1554+
} else {
1555+
// This is not a monitor deflation thread.
1556+
// No handshake or rendezvous is needed when we are already at safepoint.
1557+
assert_at_safepoint();
15381558
}
15391559

15401560
// After the handshake, safely free the ObjectMonitors that were

src/hotspot/share/runtime/thread.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ class Thread: public ThreadShadow {
319319
virtual bool is_Named_thread() const { return false; }
320320
virtual bool is_Worker_thread() const { return false; }
321321
virtual bool is_JfrSampler_thread() const { return false; }
322+
virtual bool is_monitor_deflation_thread() const { return false; }
322323

323324
// Can this thread make Java upcalls
324325
virtual bool can_call_java() const { return false; }

src/hotspot/share/runtime/vmOperation.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@
106106
template(GTestExecuteAtSafepoint) \
107107
template(GTestStopSafepoint) \
108108
template(JFROldObject) \
109-
template(JvmtiPostObjectFree)
109+
template(JvmtiPostObjectFree) \
110+
template(RendezvousGCThreads)
110111

111112
class Thread;
112113
class outputStream;

0 commit comments

Comments
 (0)