No Free Lunch? Memory Allocation in the JVM
summary
Claim: allocation on the JVM is not free — the JVM uses pointer bumping into per-thread TLABs but off-fast-path allocation triggers GC work, cache pollution and safepoint overhead. Measurement: instrumentation profilers can slow apps 2–3× and break JIT optimizations, while sampling allocation profiling runs in production with ~1% overhead. Surprises: integer caching only covers -128..127, ArrayList.removeIf can allocate a long[] “death row” bitset, and a demo shows periodic spikes where ~75% of time is spent pausing for GC.
AI-written summary · about
chapters (13)
- 0:00Intro
- 2:53What do we mean by memory allocation?
- 4:32Pointer bumping theory
- 7:30How does allocation work?
- 10:14Memory Hierarchy
- 17:23Autoboxing
- 18:54Strings
- 20:17Immutable APIs and factory methods
- 22:06Expected Allocation but not: Scalar Replacement
- 26:27Instrumenting Allocation Profiling
- 28:10Sampling Allocation Profiling
- 30:01Example: Unexpected Allocation
- 35:44Example: allocation in larger codebases
