Skip to content

Commit 895f64a

Browse files
committed
8351142: Add JFR monitor deflation and statistics events
Reviewed-by: egahlin, dholmes, lmesnik
1 parent db531bf commit 895f64a

File tree

13 files changed

+280
-11
lines changed

13 files changed

+280
-11
lines changed

src/hotspot/share/jfr/metadata/metadata.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@
116116
<Field type="InflateCause" name="cause" label="Monitor Inflation Cause" description="Cause of inflation" />
117117
</Event>
118118

119+
<Event name="JavaMonitorDeflate" category="Java Application" label="Java Monitor Deflated">
120+
<Field type="Class" name="monitorClass" label="Monitor Class" />
121+
<Field type="ulong" contentType="address" name="address" label="Monitor Address" relation="JavaMonitorAddress" />
122+
</Event>
123+
124+
<Event name="JavaMonitorStatistics" category="Java Application, Statistics" label="Java Monitor Statistics" period="everyChunk">
125+
<Field type="ulong" name="count" label="Monitors in Use" description="Current number of in-use monitors" />
126+
</Event>
127+
119128
<Event name="SyncOnValueBasedClass" category="Java Virtual Machine, Diagnostics" label="Value Based Class Synchronization" thread="true" stackTrace="true" startTime="false" experimental="true">
120129
<Field type="Class" name="valueBasedClass" label="Value Based Class" />
121130
</Event>

src/hotspot/share/jfr/periodic/jfrPeriodic.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,3 +739,9 @@ TRACE_REQUEST_FUNC(NativeMemoryUsage) {
739739
TRACE_REQUEST_FUNC(NativeMemoryUsageTotal) {
740740
JfrNativeMemoryEvent::send_total_event(timestamp());
741741
}
742+
743+
TRACE_REQUEST_FUNC(JavaMonitorStatistics) {
744+
EventJavaMonitorStatistics event;
745+
event.set_count(ObjectSynchronizer::in_use_list_count());
746+
event.commit();
747+
}

src/hotspot/share/runtime/lightweightSynchronizer.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,11 @@ static void post_monitor_inflate_event(EventJavaMonitorInflate* event,
369369
const oop obj,
370370
ObjectSynchronizer::InflateCause cause) {
371371
assert(event != nullptr, "invariant");
372-
event->set_monitorClass(obj->klass());
372+
const Klass* monitor_klass = obj->klass();
373+
if (ObjectMonitor::is_jfr_excluded(monitor_klass)) {
374+
return;
375+
}
376+
event->set_monitorClass(monitor_klass);
373377
event->set_address((uintptr_t)(void*)obj);
374378
event->set_cause((u1)cause);
375379
event->commit();

src/hotspot/share/runtime/objectMonitor.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,18 @@ bool ObjectMonitor::try_lock_or_add_to_entry_list(JavaThread* current, ObjectWai
734734
}
735735
}
736736

737+
static void post_monitor_deflate_event(EventJavaMonitorDeflate* event,
738+
const oop obj) {
739+
assert(event != nullptr, "invariant");
740+
const Klass* monitor_klass = obj->klass();
741+
if (ObjectMonitor::is_jfr_excluded(monitor_klass)) {
742+
return;
743+
}
744+
event->set_monitorClass(monitor_klass);
745+
event->set_address((uintptr_t)(void*)obj);
746+
event->commit();
747+
}
748+
737749
// Deflate the specified ObjectMonitor if not in-use. Returns true if it
738750
// was deflated and false otherwise.
739751
//
@@ -753,6 +765,8 @@ bool ObjectMonitor::deflate_monitor(Thread* current) {
753765
return false;
754766
}
755767

768+
EventJavaMonitorDeflate event;
769+
756770
const oop obj = object_peek();
757771

758772
if (obj == nullptr) {
@@ -826,6 +840,10 @@ bool ObjectMonitor::deflate_monitor(Thread* current) {
826840
install_displaced_markword_in_object(obj);
827841
}
828842

843+
if (event.should_commit()) {
844+
post_monitor_deflate_event(&event, obj);
845+
}
846+
829847
// We leave owner == DEFLATER_MARKER and contentions < 0
830848
// to force any racing threads to retry.
831849
return true; // Success, ObjectMonitor has been deflated.
@@ -1628,12 +1646,6 @@ bool ObjectMonitor::check_owner(TRAPS) {
16281646
"current thread is not owner", false);
16291647
}
16301648

1631-
static inline bool is_excluded(const Klass* monitor_klass) {
1632-
assert(monitor_klass != nullptr, "invariant");
1633-
NOT_JFR_RETURN_(false);
1634-
JFR_ONLY(return vmSymbols::jdk_jfr_internal_management_HiddenWait() == monitor_klass->name();)
1635-
}
1636-
16371649
static void post_monitor_wait_event(EventJavaMonitorWait* event,
16381650
ObjectMonitor* monitor,
16391651
uint64_t notifier_tid,
@@ -1642,7 +1654,7 @@ static void post_monitor_wait_event(EventJavaMonitorWait* event,
16421654
assert(event != nullptr, "invariant");
16431655
assert(monitor != nullptr, "invariant");
16441656
const Klass* monitor_klass = monitor->object()->klass();
1645-
if (is_excluded(monitor_klass)) {
1657+
if (ObjectMonitor::is_jfr_excluded(monitor_klass)) {
16461658
return;
16471659
}
16481660
event->set_monitorClass(monitor_klass);

src/hotspot/share/runtime/objectMonitor.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,10 @@ class ObjectMonitor : public CHeapObj<mtObjectMonitor> {
463463
bool deflate_monitor(Thread* current);
464464
private:
465465
void install_displaced_markword_in_object(const oop obj);
466+
467+
// JFR support
468+
public:
469+
static bool is_jfr_excluded(const Klass* monitor_klass);
466470
};
467471

468472
// RAII object to ensure that ObjectMonitor::is_being_async_deflated() is

src/hotspot/share/runtime/objectMonitor.inline.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "runtime/objectMonitor.hpp"
2929

30+
#include "classfile/vmSymbols.hpp"
3031
#include "logging/log.hpp"
3132
#include "oops/access.inline.hpp"
3233
#include "oops/markWord.hpp"
@@ -286,4 +287,10 @@ inline bool ObjectMonitor::object_refers_to(oop obj) const {
286287
return _object.peek() == obj;
287288
}
288289

290+
inline bool ObjectMonitor::is_jfr_excluded(const Klass* monitor_klass) {
291+
assert(monitor_klass != nullptr, "invariant");
292+
NOT_JFR_RETURN_(false);
293+
JFR_ONLY(return vmSymbols::jdk_jfr_internal_management_HiddenWait() == monitor_klass->name();)
294+
}
295+
289296
#endif // SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP

src/hotspot/share/runtime/synchronizer.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,14 @@ static bool monitors_used_above_threshold(MonitorList* list) {
13121312
return false;
13131313
}
13141314

1315+
size_t ObjectSynchronizer::in_use_list_count() {
1316+
return _in_use_list.count();
1317+
}
1318+
1319+
size_t ObjectSynchronizer::in_use_list_max() {
1320+
return _in_use_list.max();
1321+
}
1322+
13151323
size_t ObjectSynchronizer::in_use_list_ceiling() {
13161324
return _in_use_list_ceiling;
13171325
}
@@ -1419,7 +1427,11 @@ static void post_monitor_inflate_event(EventJavaMonitorInflate* event,
14191427
const oop obj,
14201428
ObjectSynchronizer::InflateCause cause) {
14211429
assert(event != nullptr, "invariant");
1422-
event->set_monitorClass(obj->klass());
1430+
const Klass* monitor_klass = obj->klass();
1431+
if (ObjectMonitor::is_jfr_excluded(monitor_klass)) {
1432+
return;
1433+
}
1434+
event->set_monitorClass(monitor_klass);
14231435
event->set_address((uintptr_t)(void*)obj);
14241436
event->set_cause((u1)cause);
14251437
event->commit();
@@ -1710,8 +1722,8 @@ class ObjectMonitorDeflationLogging: public StackObj {
17101722
elapsedTimer _timer;
17111723

17121724
size_t ceiling() const { return ObjectSynchronizer::in_use_list_ceiling(); }
1713-
size_t count() const { return ObjectSynchronizer::_in_use_list.count(); }
1714-
size_t max() const { return ObjectSynchronizer::_in_use_list.max(); }
1725+
size_t count() const { return ObjectSynchronizer::in_use_list_count(); }
1726+
size_t max() const { return ObjectSynchronizer::in_use_list_max(); }
17151727

17161728
public:
17171729
ObjectMonitorDeflationLogging()

src/hotspot/share/runtime/synchronizer.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ class ObjectSynchronizer : AllStatic {
188188

189189
// Deflate idle monitors:
190190
static size_t deflate_monitor_list(ObjectMonitorDeflationSafepointer* safepointer);
191+
static size_t in_use_list_count();
192+
static size_t in_use_list_max();
191193
static size_t in_use_list_ceiling();
192194
static void dec_in_use_list_ceiling();
193195
static void inc_in_use_list_ceiling();

src/jdk.jfr/share/conf/jfr/default.jfc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@
101101
<setting name="threshold">0 ms</setting>
102102
</event>
103103

104+
<event name="jdk.JavaMonitorDeflate">
105+
<setting name="enabled">false</setting>
106+
<setting name="threshold">0 ms</setting>
107+
</event>
108+
109+
<event name="jdk.JavaMonitorStatistics">
110+
<setting name="enabled">true</setting>
111+
<setting name="period">everyChunk</setting>
112+
</event>
113+
104114
<event name="jdk.SyncOnValueBasedClass">
105115
<setting name="enabled">true</setting>
106116
<setting name="stackTrace">true</setting>

src/jdk.jfr/share/conf/jfr/profile.jfc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@
101101
<setting name="threshold">0 ms</setting>
102102
</event>
103103

104+
<event name="jdk.JavaMonitorDeflate">
105+
<setting name="enabled">false</setting>
106+
<setting name="threshold">0 ms</setting>
107+
</event>
108+
109+
<event name="jdk.JavaMonitorStatistics">
110+
<setting name="enabled">true</setting>
111+
<setting name="period">everyChunk</setting>
112+
</event>
113+
104114
<event name="jdk.SyncOnValueBasedClass">
105115
<setting name="enabled">true</setting>
106116
<setting name="stackTrace">true</setting>

0 commit comments

Comments
 (0)