Introduce NativeAllocationTracer for tracking native memory allocation sites#816
Conversation
…ion sites and usage statistics.
|
Looking good, but let's move the NativeAllocationTracer class to the tools package, and let's access it dynamically with Class.forName just like PointerBufferPoolMXBean. |
|
I like the idea too! I was actually considering moving it to the The problem with your suggestion is that we'd need to handle 5 methods. Even if we get all the Method objects via reflection during initial time, writing all that verbose reflection code at every call site seems weird. Making those methods to I'm curious is there a compelling reason why it must be moved to |
|
Putting everything we don't need at runtime in a different package simply avoids namespace pollution, that's all. And if we don't link dynamically, then the JVM needs to be able to load that class even when it's not needed. |
|
I suppose we could leave it as package private, that also prevents namespace pollution, but we still need a way to load it dynamically. In the case when we don't need to add "import" statements, does the JVM still loads all classes that might not even get used? |
|
Huh, I guess not. With Foo.java and Bar.java like this So I guess having a package private class that doesn't need any imports is fine after all |
|
However, it's not possible to tell AOT tools like GraalVM to keep those debug classes out of the image. When we use Class.forName, that becomes possible. I guess that's the reason we should use dynamic loading explicitly |
|
As you suggested, I've modified it to use dynamic references via reflection instead of direct references. |
…logging, and synchronized methods for thread safety
|
What's the status on this PR? Anything else I should work on? |
Related to #815
Example
Output