Skip to content

Commit 5c95bb1

Browse files
author
Markus Grönlund
committedApr 17, 2023
8257967: JFR: Events for loaded agents
Reviewed-by: dholmes, sspitsyn
1 parent 2a062f1 commit 5c95bb1

23 files changed

+1406
-518
lines changed
 

‎make/hotspot/lib/JvmFeatures.gmk

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ ifneq ($(call check-jvm-feature, jvmti), true)
8888
jvmtiImpl.cpp jvmtiManageCapabilities.cpp jvmtiRawMonitor.cpp jvmtiUtil.cpp jvmtiTrace.cpp \
8989
jvmtiCodeBlobEvents.cpp jvmtiEnv.cpp jvmtiRedefineClasses.cpp jvmtiEnvBase.cpp jvmtiEnvThreadState.cpp \
9090
jvmtiTagMap.cpp jvmtiEventController.cpp evmCompat.cpp jvmtiEnter.xsl jvmtiExport.cpp \
91-
jvmtiClassFileReconstituter.cpp jvmtiTagMapTable.cpp
91+
jvmtiClassFileReconstituter.cpp jvmtiTagMapTable.cpp jvmtiAgent.cpp jvmtiAgentList.cpp
9292
endif
9393

9494
ifneq ($(call check-jvm-feature, jvmci), true)

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

+19
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,25 @@
11721172
<Field type="ulong" name="totalFinalizersRun" label="Finalizers Run" description="Total number of finalizers run since JVM start" />
11731173
</Event>
11741174

1175+
<Event name="JavaAgent" category="Java Virtual Machine, Diagnostics" label="Java Agent" description="A Java programming language agent making use of the java.lang.instrument package for instrumenting programs running on the JVM"
1176+
thread="false" startTime="false" period="endChunk" stackTrace="false">
1177+
<Field type="string" name="name" label="Name" />
1178+
<Field type="string" name="options" label="Options" />
1179+
<Field type="boolean" name="dynamic" label="Dynamic" description="If the agent attached to the JVM dynamically during runtime, i.e. not at startup" />
1180+
<Field type="Ticks" name="initializationTime" label="Initialization Time" description="The time the JVM initialized the agent" />
1181+
<Field type="Tickspan" name="initializationDuration" label="Initialization Duration" description="The duration of executing the initialization method, either premain or agentmain" />
1182+
</Event>
1183+
1184+
<Event name="NativeAgent" category="Java Virtual Machine, Diagnostics" label="Native Agent" description="A native programming language agent making use of the JVMTI interface used by development, profiling and monitoring tools"
1185+
thread="false" startTime="false" period="endChunk" stackTrace="false">
1186+
<Field type="string" name="name" label="Name" />
1187+
<Field type="string" name="options" label="Options" />
1188+
<Field type="boolean" name="dynamic" label="Dynamic" description="If the library attached to the JVM dynamically during runtime, i.e. not at startup" />
1189+
<Field type="Ticks" name="initializationTime" label="Initialization Time" description="The time the JVM initialized the agent" />
1190+
<Field type="Tickspan" name="initializationDuration" label="Initialization Duration" description="The duration of executing the JVMTI VMInit event callback. If no VMInit callback is specified, the duration is 0. For a dynamically loaded agent, it is the duration of executing the call to Agent_OnAttach." />
1191+
<Field type="string" name="path" label="Path" description="The path of the library" />
1192+
</Event>
1193+
11751194
<Type name="DeoptimizationReason" label="Deoptimization Reason">
11761195
<Field type="string" name="reason" label="Reason" />
11771196
</Type>

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

+39-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -52,6 +52,7 @@
5252
#include "memory/heapInspection.hpp"
5353
#include "memory/resourceArea.hpp"
5454
#include "oops/oop.inline.hpp"
55+
#include "prims/jvmtiAgentList.hpp"
5556
#include "runtime/arguments.hpp"
5657
#include "runtime/flags/jvmFlag.hpp"
5758
#include "runtime/globals.hpp"
@@ -269,6 +270,43 @@ TRACE_REQUEST_FUNC(SystemProcess) {
269270
}
270271
}
271272

273+
template <typename AgentEvent>
274+
static void send_agent_event(AgentEvent& event, const JvmtiAgent* agent) {
275+
event.set_name(agent->name());
276+
event.set_options(agent->options());
277+
event.set_dynamic(agent->is_dynamic());
278+
event.set_initializationTime(agent->initialization_time());
279+
event.set_initializationDuration(agent->initialization_duration());
280+
event.commit();
281+
}
282+
283+
TRACE_REQUEST_FUNC(JavaAgent) {
284+
const JvmtiAgentList::Iterator it =JvmtiAgentList::java_agents();
285+
while (it.has_next()) {
286+
const JvmtiAgent* agent = it.next();
287+
assert(agent->is_jplis(), "invariant");
288+
EventJavaAgent event;
289+
send_agent_event(event, agent);
290+
}
291+
}
292+
293+
static void send_native_agent_events(const JvmtiAgentList::Iterator& it) {
294+
while (it.has_next()) {
295+
const JvmtiAgent* agent = it.next();
296+
assert(!agent->is_jplis(), "invariant");
297+
EventNativeAgent event;
298+
event.set_path(agent->os_lib_path());
299+
send_agent_event(event, agent);
300+
}
301+
}
302+
303+
TRACE_REQUEST_FUNC(NativeAgent) {
304+
const JvmtiAgentList::Iterator native_agents_it = JvmtiAgentList::native_agents();
305+
send_native_agent_events(native_agents_it);
306+
const JvmtiAgentList::Iterator xrun_agents_it = JvmtiAgentList::xrun_agents();
307+
send_native_agent_events(xrun_agents_it);
308+
}
309+
272310
TRACE_REQUEST_FUNC(ThreadContextSwitchRate) {
273311
double rate = 0.0;
274312
int ret_val = OS_ERR;

0 commit comments

Comments
 (0)
Please sign in to comment.