Draft
Conversation
7558470 to
37d8726
Compare
Replace direct BTrace probe method calls with INVOKEDYNAMIC-based
dispatch through IndyDispatcher bootstrap methods, resolving handlers
lazily at link time via HandlerRepositoryImpl.
Key changes:
- IndyDispatcher: bootstrap(), runtimeBootstrap(), levelBootstrap()
resolve handlers/runtime methods/level checks via ConstantCallSite
- HandlerRepositoryImpl: probe registration, handler cache, level field
cache using Field.get() for hot-path level reads
- Assembler/MethodTrackingContext: emit INVOKEDYNAMIC for all handler
calls and level checks (replaces GETSTATIC + static invocations)
- BTraceProbeNode/BTraceProbePersisted: register/unregister probes in
HandlerRepositoryImpl; expose getFullBytecode() for dispatch resolution
- HandlerRepository interface: adds getLevel(String) for level checks
- LinkingFlag: re-entrancy guard to prevent recursive linking
- Minimal bootstrap: only IndyDispatcher, LinkingFlag, HandlerRepository,
and AnyType are stored as .class (bootstrap-visible); all other BTrace
classes are masked .classdata in META-INF/btrace/{agent,client,shared}
- BTraceRuntime: use reflection to access Unsafe (no longer bootstrap)
- Benchmarks: DispatchBenchmark measures actual INVOKEDYNAMIC overhead
- Golden files: regenerated for leveled and non-leveled probe tests
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- BTraceRuntimeImpl_8: skip auxiliary frames when resolving caller class (MH adapter frames on JDK 8 have null declaringClass) - ClassFilter: add JDK 8 internal packages (sun.*, com.sun.*) to sensitive class filter to prevent instrumentation loops - LinkerInstrumentor: fall back to java/lang/Object in getCommonSuperClass() when resolution fails, matching BTraceClassWriter behavior (needed for JDK 8 package-private types like MemberName and LambdaForm referenced by MethodHandleNatives) - BTraceTransformer: exclude org/openjdk/btrace/ classes from instrumentation unconditionally to protect agent classes loaded via MaskedClassLoader (bypasses loader-based sensitive check) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
d71842a to
66a6686
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace INVOKESTATIC handler copying with INVOKEDYNAMIC dispatch. Probe handler methods now stay in the probe class (bootstrap CL) and are called via
ConstantCallSite, eliminating bytecode copying into target classes.Architecture change
Indy.class(Java 15-specific, reflection)IndyDispatcher+HandlerRepositoryinterfaceDispatch chain
Integration test fixes
AnyType descriptor transformation — Probe methods using
@AnyTypegetLorg/openjdk/btrace/core/types/AnyType;→Ljava/lang/Object;in descriptors so INVOKEDYNAMIC call site types match. Applied in bothBTraceProbeNode.getBytecode()andBTraceProbePersisted.register().StackWalker auxiliary frame skipping —
getCallerClassLoader()andgetCallerClass()inBTraceRuntimeImpl_9and_11now skiporg.openjdk.btrace.runtime.auxiliary.*frames so probe handler frames are transparent to classloader resolution.HandlerRepositoryImpl cleanup — Removed fragile
asType()fallback; handler resolution is now a cleanfindStaticlookup with warn-on-failure.Review fixes
ConcurrentHashMapdisallows null values; replaced withget()+put()pattern so failed resolutions aren't cached and can retry.HandlerRepositoryImpl.unregisterProbe()to bothBTraceProbeNode.unregister()andBTraceProbePersisted.unregister(). Removed prematureregisterProbefromBTraceProbeFactory.createProbe()— registration now happens only inprobe.register()afterdefinedClassis set.BTraceProbePersisted.transformAnyTypeDescriptors()— only descriptors change (not control flow), so existing frames are preserved as-is.COMPUTE_FRAMESwas unnecessary and riskedClassNotFoundExceptionduring hierarchy resolution.Client.onExit()(now handled by probe lifecycle).Benchmark results
DispatchBenchmarkuses the realBTraceTransformerpipeline to instrument a target class with a compiled BTrace probe, then measures dispatch overhead.@Duration: ~19.7 ns overhead — dominated by twoSystem.nanoTime()calls (~11 ns each on macOS), not dispatchFiles
New:
IndyDispatcher,HandlerRepository,DispatchBenchmark,DispatchTarget,Workload,DispatchScriptDeleted:
CopyingVisitor,Indy, ~400 redundant golden files (static/dynamic/leveled → unified)Refactored:
HandlerRepositoryImpl,Instrumentor,Assembler,BTraceProbeNode,BTraceProbePersisted,BTraceRuntimeImpl_9/_11Test plan
./gradlew :btrace-instr:test— all instrumentor tests pass./gradlew :integration-tests:test -Pintegration— all 22 integration tests pass (including Docker)./gradlew :benchmarks:runtime-benchmarks:jmh -PjmhInclude='DispatchBenchmark'— benchmarks run and produce stable results🤖 Generated with Claude Code
This change is