docs/plans/DistributionRestructuring.md
Status: Not Started Target: v3.x (long-term) Prerequisites: Masked JAR architecture (completed, see MaskedJarArchitecture.md)
The current masked JAR architecture reduces bootstrap classloader pollution to ~112 classes. This plan proposes further reducing the bootstrap footprint to ~50 KB by replacing direct method calls in instrumented bytecode with invokedynamic instructions, following the approach pioneered by Elastic APM.
Reduce the bootstrap classloader footprint from ~112 classes (~200 KB) to a single dispatcher class (~50 KB) by routing all instrumented bytecode through invokedynamic.
Based on Elastic APM's approach: instrumented bytecode uses INVOKEDYNAMIC instead of direct calls to BTrace runtime API. A tiny IndyDispatcher in the bootstrap classloader resolves these calls at first invocation.
btrace-bootstrap-minimal.jar (~50 KB)
└── org/openjdk/btrace/indy/
└── IndyDispatcher.java # Only class in bootstrap CL
Current: Instrumented bytecode directly calls BTrace runtime API (requires API in bootstrap CL).
Proposed: Instrumented bytecode uses INVOKEDYNAMIC, resolved by IndyDispatcher. The actual runtime API lives in an isolated classloader, not bootstrap.
invokedynamic (no performance loss after warmup)invokedynamic resolution (mitigated by JIT)IndyDispatcher bootstrap class with CallSite factory methodsInstrumentor to emit INVOKEDYNAMIC instead of INVOKESTATIC for BTrace runtime callsMaskedClassLoader to serve as the isolated runtime CLIndyDispatcher