I have a java function whose documentation claims that it does no heap memory allocations.
How can I verify whether it (still) behaves as claimed, at runtime?
Ideally, I'd like to do this during a normal (production) program run, in a way that can be introspected by the program and shown as program output.
I'm hoping for a simple solid runtime API such as:
- set checkpoint A, call the function, set checkpoint B, ask whether any heap memory allocations occurred in this thread between A and B.
- or, temporarily turn on "throw an exception if a heap memory allocation occurs in this thread" mode.
If that's not possible, I'd like to at least be able to do the equivalent during some kind of debug-mode / profiling run.
Mainly I'm interested in doing this at runtime, but if it's possible to do it using static analysis tools, I'd be interested in that too.
I've searched the web and found nothing. There are memory profilers, e.g. JFR that can do things like report and break down current heap usage at any given time, but I haven't seen any evidence that they can answer this simple precise yes-or-no "did any allocations happen in this thread during this interval" query.