From fc889577eaf3f564d896818c1d9b1eb6fa5a8758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nordstr=C3=B6m?= Date: Wed, 19 Oct 2022 10:34:17 +0000 Subject: [PATCH] 8286707: JFR: Don't commit JFR internal jdk.JavaMonitorWait events Reviewed-by: dholmes, egahlin --- .../jfr/recorder/repository/jfrChunkRotation.cpp | 2 +- src/hotspot/share/jfr/support/jfrIntrinsics.hpp | 1 + src/hotspot/share/runtime/objectMonitor.cpp | 12 +++++++++++- src/jdk.jfr/share/classes/jdk/jfr/internal/JVM.java | 12 +++++++++--- .../classes/jdk/jfr/internal/PlatformRecorder.java | 4 ++-- .../classes/jdk/jfr/internal/RequestEngine.java | 4 ++-- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/hotspot/share/jfr/recorder/repository/jfrChunkRotation.cpp b/src/hotspot/share/jfr/recorder/repository/jfrChunkRotation.cpp index 461bb490f68..54f33c0ffdc 100644 --- a/src/hotspot/share/jfr/recorder/repository/jfrChunkRotation.cpp +++ b/src/hotspot/share/jfr/recorder/repository/jfrChunkRotation.cpp @@ -38,7 +38,7 @@ static jobject install_chunk_monitor(JavaThread* thread) { // read static field HandleMark hm(thread); static const char klass[] = "jdk/jfr/internal/JVM"; - static const char field[] = "FILE_DELTA_CHANGE"; + static const char field[] = "CHUNK_ROTATION_MONITOR"; static const char signature[] = "Ljava/lang/Object;"; JavaValue result(T_OBJECT); JfrJavaArguments field_args(&result, klass, field, signature, thread); diff --git a/src/hotspot/share/jfr/support/jfrIntrinsics.hpp b/src/hotspot/share/jfr/support/jfrIntrinsics.hpp index c6822aa535f..aa307062cfa 100644 --- a/src/hotspot/share/jfr/support/jfrIntrinsics.hpp +++ b/src/hotspot/share/jfr/support/jfrIntrinsics.hpp @@ -52,6 +52,7 @@ class JfrIntrinsicSupport : AllStatic { template(getEventWriter_signature, "()Ljdk/jfr/internal/event/EventWriter;") \ template(eventConfiguration_name, "eventConfiguration") \ template(commit_name, "commit") \ + template(jfr_chunk_rotation_monitor, "jdk/jfr/internal/JVM$ChunkRotationMonitor") \ #define JFR_INTRINSICS(do_intrinsic, do_class, do_name, do_signature, do_alias) \ do_intrinsic(_counterTime, jdk_jfr_internal_JVM, counterTime_name, void_long_signature, F_SN) \ diff --git a/src/hotspot/share/runtime/objectMonitor.cpp b/src/hotspot/share/runtime/objectMonitor.cpp index 50ab95e1669..3cb09e462bf 100644 --- a/src/hotspot/share/runtime/objectMonitor.cpp +++ b/src/hotspot/share/runtime/objectMonitor.cpp @@ -1416,6 +1416,12 @@ bool ObjectMonitor::check_owner(TRAPS) { "current thread is not owner", false); } +static inline bool is_excluded(const Klass* monitor_klass) { + assert(monitor_klass != nullptr, "invariant"); + NOT_JFR_RETURN_(false); + JFR_ONLY(return vmSymbols::jfr_chunk_rotation_monitor() == monitor_klass->name()); +} + static void post_monitor_wait_event(EventJavaMonitorWait* event, ObjectMonitor* monitor, uint64_t notifier_tid, @@ -1423,7 +1429,11 @@ static void post_monitor_wait_event(EventJavaMonitorWait* event, bool timedout) { assert(event != NULL, "invariant"); assert(monitor != NULL, "invariant"); - event->set_monitorClass(monitor->object()->klass()); + const Klass* monitor_klass = monitor->object()->klass(); + if (is_excluded(monitor_klass)) { + return; + } + event->set_monitorClass(monitor_klass); event->set_timeout(timeout); // Set an address that is 'unique enough', such that events close in // time and with the same address are likely (but not guaranteed) to diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/JVM.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/JVM.java index 002c55ee9d4..40a094d6562 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/JVM.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/JVM.java @@ -39,11 +39,17 @@ import jdk.jfr.internal.event.EventWriter; public final class JVM { private static final JVM jvm = new JVM(); - // JVM signals file changes by doing Object#notify on this object - static final Object FILE_DELTA_CHANGE = new Object(); - static final long RESERVED_CLASS_ID_LIMIT = 500; + private static class ChunkRotationMonitor {} + + /* + * The JVM uses the chunk rotation monitor to notify Java that a rotation is warranted. + * The monitor type is used to exclude jdk.JavaMonitorWait events from being generated + * when Object.wait() is called on this monitor. + */ + static final Object CHUNK_ROTATION_MONITOR = new ChunkRotationMonitor(); + private volatile boolean nativeOK; private static native void registerNatives(); diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecorder.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecorder.java index 98687d8b700..b046f6be166 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecorder.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecorder.java @@ -520,8 +520,8 @@ public final class PlatformRecorder { private void takeNap(long duration) { try { - synchronized (JVM.FILE_DELTA_CHANGE) { - JVM.FILE_DELTA_CHANGE.wait(duration < 10 ? 10 : duration); + synchronized (JVM.CHUNK_ROTATION_MONITOR) { + JVM.CHUNK_ROTATION_MONITOR.wait(duration < 10 ? 10 : duration); } } catch (InterruptedException e) { // Ignore diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/RequestEngine.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/RequestEngine.java index 6ac4b136cb5..2958e585893 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/RequestEngine.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/RequestEngine.java @@ -302,8 +302,8 @@ public final class RequestEngine { boolean needNotify = interval < flushInterval; flushInterval = interval; if (needNotify) { - synchronized (JVM.FILE_DELTA_CHANGE) { - JVM.FILE_DELTA_CHANGE.notifyAll(); + synchronized (JVM.CHUNK_ROTATION_MONITOR) { + JVM.CHUNK_ROTATION_MONITOR.notifyAll(); } } }