Skip to content

Commit

Permalink
8286707: JFR: Don't commit JFR internal jdk.JavaMonitorWait events
Browse files Browse the repository at this point in the history
Backport-of: fc889577eaf3f564d896818c1d9b1eb6fa5a8758
  • Loading branch information
GoeLin committed Jan 12, 2023
1 parent eceb480 commit 0db4add
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/jfr/support/jfrIntrinsics.hpp
Expand Up @@ -37,6 +37,7 @@
template(jdk_jfr_internal_JVM, "jdk/jfr/internal/JVM") \
template(jdk_jfr_internal_handlers_EventHandler_signature, "Ljdk/jfr/internal/handlers/EventHandler;") \
template(eventHandler_name, "eventHandler") \
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) \
Expand Down
12 changes: 11 additions & 1 deletion src/hotspot/share/runtime/objectMonitor.cpp
Expand Up @@ -1416,14 +1416,24 @@ 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,
jlong notifier_tid,
jlong timeout,
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
Expand Down
12 changes: 9 additions & 3 deletions src/jdk.jfr/share/classes/jdk/jfr/internal/JVM.java
Expand Up @@ -38,11 +38,17 @@
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();
Expand Down
Expand Up @@ -523,8 +523,8 @@ private boolean isToDisk() {

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
Expand Down
4 changes: 2 additions & 2 deletions src/jdk.jfr/share/classes/jdk/jfr/internal/RequestEngine.java
Expand Up @@ -291,8 +291,8 @@ static void setFlushInterval(long millis) {
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();
}
}
}
Expand Down

1 comment on commit 0db4add

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.