allocation-instrumenter icon indicating copy to clipboard operation
allocation-instrumenter copied to clipboard

Comparing with another JVMTI way to hook object allocation

Open anonymouscode1 opened this issue 4 years ago • 2 comments

Hello,

Since the JDK 11 already had a way to monitor object allocations (https://openjdk.java.net/jeps/331), what's the new feature the allocation-instrumenter can provide?

Thanks!

anonymouscode1 avatar Nov 30 '20 20:11 anonymouscode1

Note that both this tool and JEP-331 came from the same team, and that this tool predates JEP-331 by about a decade. We developed that JEP because we couldn't do everything we wanted with this instrumenter.

That said, we find that this tool still has two meaningful use cases:

  • This lets you write the callbacks directly in Java without trampolining through native code. This is the biggest difference: many people don't want to deal with native code if they can avoid it, and it means developers can easily use Java logic their application already depends upon (e.g., logging) if they want. There's a performance penalty, but many folks are happy to take the tradeoff.

  • When instrumenting constructors, you can restrict which classes get instrumented, which allows a lightweight way of tracking instantiations of particular types.

jhmanson avatar Nov 30 '20 23:11 jhmanson

Thank you!

anonymouscode1 avatar Dec 01 '20 00:12 anonymouscode1