Draft
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Replace INVOKESTATIC handler copying with INVOKEDYNAMIC dispatch via ConstantCallSite for probe handler isolation - Transform AnyType→Object in probe method descriptors - Skip auxiliary frames in StackWalker classloader resolution - Add real instrumentation JMH benchmarks (DispatchBenchmark) - Fix ConcurrentHashMap.computeIfAbsent null NPE in handler cache - Add symmetric unregisterProbe on probe unregister - Remove premature registerProbe from BTraceProbeFactory - Unify static/dynamic/leveled golden files into single set - Delete CopyingVisitor and Indy (no longer needed) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
On JDK 8, MethodHandleNatives references package-private types (MemberName, LambdaForm) that Class.forName() cannot resolve from the agent classloader. The default ClassWriter.getCommonSuperClass() throws, causing addGuard() to fail silently — leaving linkCallSite() unpatched and the LinkingFlag guard uninstalled. Override getCommonSuperClass() to fall back to java/lang/Object on resolution failure, matching the pattern used by BTraceClassWriter. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…entation Two fixes for the StackOverflowError in testTraceAll on JDK 8: 1. Guard probe handler execution against re-entrance: openLinkerCheck now calls LinkingFlag.guardLinking() before the INVOKEDYNAMIC probe call and reset() after it. This prevents infinite recursion when a probe handler (e.g. doall -> AtomicLong.getAndIncrement) calls instrumented code that would fire the same probe again. 2. Exclude org/openjdk/btrace/ classes from instrumentation unconditionally at the top of transform(), before acquiring the read lock. Agent classes loaded by MaskedClassLoader were bypassing the loader-based sensitive check (which only covers bootstrap and system classloaders). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
7558470 to
37d8726
Compare
- LinkingFlag: replace ThreadLocal<Integer> with ThreadLocal<int[]> to eliminate autoboxing on the hot path (3 ThreadLocal ops per probe). Use anonymous class instead of lambda to avoid INVOKEDYNAMIC in the bootstrap classloader. - IndyDispatcher: add null-check for volatile repository field before resolveHandler/resolveRuntime calls (race during agent init). - HandlerRepositoryImpl: replace manual get/put with computeIfAbsent to avoid redundant findStatic lookups under concurrent resolution. - LinkerInstrumentor: log at debug level when getCommonSuperClass falls back to Object, instead of silently swallowing the exception. - BTraceTransformer: clarify comment on intentional duplicate of the org/openjdk/btrace/ sensitive prefix check. - BTraceRuntimeImpl_9/11: replace forEach+AtomicInteger/AtomicReference with StackWalker.walk()+stream to short-circuit after finding the target frame and eliminate per-call wrapper allocations. Note: the try-finally around probe dispatch (counter leak on exception) is deferred — emitting ATHROW in the exception handler triggers recursive instrumentation in ThrowInstrumentor, requiring deeper integration with the visitor chain. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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