Testing for excess allocation
Aleksey Shipilev
shade at redhat.com
Sat Jan 4 11:48:17 UTC 2020
On 1/4/20 12:01 PM, Florian Weimer wrote:
> Is there a way to check that a particular test does not allocate to
> match memory? I'm not interesting in fine-grained checks, the
> difference is more in the order of 1 GiB with the bug vs 10 MiB
> without it.
>
> Using Epsilon with a suitable heap size (fairly low, but with some
> headroom) comes to my mind. Is there a better approach?
Depends on your use case constraints. For external test that has to fail hard on exhaustion, Epsilon
is fine. For internal (programmatic) test, polling MXBeans is fine: either
MemoryMXBean.getHeapMemoryUsage() or ThreadMXBean.getThreadAllocatedBytes() are your friends. For
JMH-driven benchmarks, internal profiles like -prof gc call these for you.
--
Thanks,
-Aleksey
More information about the discuss
mailing list