Re-register custom events on every JFR chunk (#1740)
Co-authored-by: Andrei Pangin <1749416+apangin@users.noreply.github.com>
This commit is contained in:
@@ -64,6 +64,7 @@ public class JfrReader implements Closeable {
|
||||
public final Map<String, Map<Integer, String>> enums = new HashMap<>();
|
||||
|
||||
private final Dictionary<Constructor<? extends Event>> customEvents = new Dictionary<>();
|
||||
private final Map<String, Class<? extends Event>> customEventsByName = new HashMap<>();
|
||||
|
||||
private int executionSample;
|
||||
private int nativeMethodSample;
|
||||
@@ -129,6 +130,11 @@ public class JfrReader implements Closeable {
|
||||
}
|
||||
|
||||
public <E extends Event> void registerEvent(String name, Class<E> eventClass) {
|
||||
customEventsByName.put(name, eventClass);
|
||||
registerCustomEvent(name, eventClass);
|
||||
}
|
||||
|
||||
private <E extends Event> void registerCustomEvent(String name, Class<E> eventClass) {
|
||||
JfrClass type = typesByName.get(name);
|
||||
if (type != null) {
|
||||
try {
|
||||
@@ -139,6 +145,22 @@ public class JfrReader implements Closeable {
|
||||
}
|
||||
}
|
||||
|
||||
private void registerCustomEvents() {
|
||||
customEvents.clear();
|
||||
|
||||
// The following classes are instantiated reflectively.
|
||||
// Make sure to list them in reachability-metadata.json.
|
||||
registerCustomEvent("jdk.CPULoad", CPULoad.class);
|
||||
registerCustomEvent("jdk.GCHeapSummary", GCHeapSummary.class);
|
||||
registerCustomEvent("jdk.ObjectCount", ObjectCount.class);
|
||||
registerCustomEvent("jdk.ObjectCountAfterGC", ObjectCount.class);
|
||||
registerCustomEvent("profiler.ProcessSample", ProcessSample.class);
|
||||
|
||||
for (Map.Entry<String, Class<? extends Event>> entry : customEventsByName.entrySet()) {
|
||||
registerCustomEvent(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
// Similar to eof(), but parses the next chunk header
|
||||
public boolean hasMoreChunks() throws IOException {
|
||||
return state == STATE_NEW_CHUNK ? readChunk(buf.position()) : state == STATE_READING;
|
||||
@@ -361,6 +383,7 @@ public class JfrReader implements Closeable {
|
||||
readMeta(chunkStart + metaOffset);
|
||||
readConstantPool(chunkStart + cpOffset);
|
||||
cacheEventTypes();
|
||||
registerCustomEvents();
|
||||
|
||||
seek(chunkStart + CHUNK_HEADER_SIZE);
|
||||
state = STATE_READING;
|
||||
@@ -616,14 +639,6 @@ public class JfrReader implements Closeable {
|
||||
cpuTimeSample = getTypeId("jdk.CPUTimeSample");
|
||||
nativeLock = getTypeId("profiler.NativeLock");
|
||||
|
||||
// The following classes are instantiated reflectively.
|
||||
// Make sure to list them in reachability-metadata.json.
|
||||
registerEvent("jdk.CPULoad", CPULoad.class);
|
||||
registerEvent("jdk.GCHeapSummary", GCHeapSummary.class);
|
||||
registerEvent("jdk.ObjectCount", ObjectCount.class);
|
||||
registerEvent("jdk.ObjectCountAfterGC", ObjectCount.class);
|
||||
registerEvent("profiler.ProcessSample", ProcessSample.class);
|
||||
|
||||
JfrClass wallClass = typesByName.get("profiler.WallClockSample");
|
||||
hasWallTimeSpan = wallClass != null && wallClass.field("timeSpan") != null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user