Skip to content

Instantly share code, notes, and snippets.

@jbachorik
jbachorik / fosdem_2025_resources.md
Created January 28, 2025 09:46
FOSDEM 2025: Advancing Java Profiling
#include <jvmti.h>
#include <jni.h>
#include <string.h>
static jvmtiEnv *jvmti = NULL;
static jclass outOfMemoryErrorClass = NULL;
void check_exact_exception_type(JNIEnv *jni_env, jobject exception) {
jclass exceptionClass = (*jni_env)->GetObjectClass(jni_env, exception);
if ((*jni_env)->IsSameObject(jni_env, exceptionClass, outOfMemoryErrorClass)) {
#! /bin/bash
# see http://hirt.se/images/openjdk/ilw.png
if [ $# -ne 1 ]; then
echo "Provide ILW score"
exit 1
fi
priority="P5"
import org.openjdk.btrace.core.BTraceUtils;
import org.openjdk.btrace.core.annotations.*;
import org.openjdk.btrace.core.jfr.JfrEvent;
import static org.openjdk.btrace.core.BTraceUtils.*;
import static org.openjdk.btrace.core.BTraceUtils.Jfr.*;
@BTrace
public class TracePreparedQuery {
@Event(
name = "jdbc.PreparedQuery",

Start a JVM with active recording which gets persisted to <path>

java -XX:+FlightRecorder -XX:StartFlightRecording=maxsize=1g,filename=<path> ...

gunther:0.0.0-JFR jbachorik$ ./bin/btrace -lp anagrams.jar
btrace INFO: Attaching BTrace to PID: 32199
1: 6c83f579-2624-4acb-9cbf-1f59b3aa2076 [org.openjdk.btrace.runtime.aux.AllMethods1]
import org.openjdk.btrace.core.BTraceUtils;
import org.openjdk.btrace.core.annotations.*;
import org.openjdk.btrace.core.jfr.JfrEvent;
import static org.openjdk.btrace.core.BTraceUtils.*;
import static org.openjdk.btrace.core.BTraceUtils.Jfr.*;
@BTrace public class JfrEventsProbe {
@Event(
name = "CustomEvent",
label = "Custom Event",
@JfrPeriodicEventHandler
// register a periodic JFR event and assing its handler to this method; the periodicity is defined in the Event itself via 'jdk.jfr.Period' annotation
public static void handleSimplePeriodic(SimplePeriodicEvent event) {
// the handler code will be called periodically by the JFR infrastructure
if (event.shouldCommit()) {
// if the event type is enabled and there is an ongoing recording set up the valued and commit the event
event.setValue(10);
event.commit();
}
}

To make BTrace work with OSGI set the following system property: org.osgi.framework.bootdelegation=com.sun.btrace, com.sun.btrace.*