24
24
25
25
#include " precompiled.hpp"
26
26
#include " classfile/vmSymbols.hpp"
27
+ #include " gc/shared/suspendibleThreadSet.hpp"
27
28
#include " jfr/jfrEvents.hpp"
28
29
#include " logging/log.hpp"
29
30
#include " logging/logStream.hpp"
@@ -1473,6 +1474,16 @@ class HandshakeForDeflation : public HandshakeClosure {
1473
1474
}
1474
1475
};
1475
1476
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
+
1476
1487
// This function is called by the MonitorDeflationThread to deflate
1477
1488
// ObjectMonitors. It is also called via do_final_audit_and_print_stats()
1478
1489
// and VM_ThreadDump::doit() by the VMThread.
@@ -1514,7 +1525,7 @@ size_t ObjectSynchronizer::deflate_idle_monitors(ObjectMonitorsHashtable* table)
1514
1525
ResourceMark rm;
1515
1526
GrowableArray<ObjectMonitor*> delete_list ((int )deflated_count);
1516
1527
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 ()) {
1518
1529
if (ls != nullptr ) {
1519
1530
timer.stop ();
1520
1531
ls->print_cr (" before handshaking: unlinked_count=" SIZE_FORMAT
@@ -1528,13 +1539,22 @@ size_t ObjectSynchronizer::deflate_idle_monitors(ObjectMonitorsHashtable* table)
1528
1539
// ObjectMonitors that were deflated in this cycle.
1529
1540
HandshakeForDeflation hfd_hc;
1530
1541
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);
1531
1547
1532
1548
if (ls != nullptr ) {
1533
1549
ls->print_cr (" after handshaking: in_use_list stats: ceiling="
1534
1550
SIZE_FORMAT " , count=" SIZE_FORMAT " , max=" SIZE_FORMAT,
1535
1551
in_use_list_ceiling (), _in_use_list.count (), _in_use_list.max ());
1536
1552
timer.start ();
1537
1553
}
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 ();
1538
1558
}
1539
1559
1540
1560
// After the handshake, safely free the ObjectMonitors that were
0 commit comments