Memory areas and object layout
23 questions in 8 subtopics.
Heap and generations
Explain the weak generational hypothesis and how the heap is organised in Parallel GC compared with G1.A service runs with -Xmx4g on G1. GC logs show old generation occupancy after each young GC climbing from 1 GB to 3.5 GB over six hours; then a full GC takes it back to 1 GB and the cycle repeats. Is this a memory leak? How do you tell, and what do you change?For a stateless JVM service with steady traffic, the team must choose between running a few large instances with 32 GB heaps or many small instances with 4 GB heaps. How do you decide?JVM memory management moved from many separately sized areas (a fixed PermGen, fixed young and old sizes) toward adaptive, region-based and self-sizing designs. Explain why, and how this trend should shape your company's memory configuration standards.Thread stacks
What is stored on a Java thread stack, and what causesStackOverflowError compared with OutOfMemoryError: unable to create native thread?A container with a 2 GiB memory limit is OOM-killed by the kernel. Heap usage was about 1 GiB of -Xmx1200m. The application has around 1,500 platform threads. Walk through where the rest of the memory went and what you would change.An organisation plans to cut memory across 200 services by moving request handling from large platform thread pools to virtual threads. What memory effects do you expect, and how do you roll it out?Metaspace
What lives in metaspace, how is it different from the PermGen used before Java 8, and which flags control it?HotSpot removed PermGen in JDK 8 and replaced it with metaspace in native memory, and later made metaspace return memory to the OS more promptly. Why was this change made, what did it fix and not fix, and what lesson does it hold for running JVMs in containers today?Code cache
What is the code cache in HotSpot, what is stored there, and how can you see how full it is?A large service logs "CodeCache is full. Compiler has been disabled." and latency degrades gradually over the following hours. Explain what is happening and how you fix it.Direct and native memory
What is the difference between a heapByteBuffer and a direct ByteBuffer in Java NIO? When is the memory of a direct buffer freed?A Java process reaches 6 GB resident memory with -Xmx3g. Native memory tracking totals look reasonable and far below 6 GB. What else could be using native memory, and how do you find it?Define a memory budget policy for JVM services running in Kubernetes. It should cover heap, non-heap areas and the container limit so that teams stop getting kernel OOM kills.Java gained several ways to manage memory outside the heap over the years: direct ByteBuffers, sun.misc.Unsafe, and the Foreign Function and Memory API, final in JDK 22. For systems that keep large data off heap, what long-term strategy do you set?Object headers and layout
What does an object header contain in 64-bit HotSpot, and what information does the mark word hold?On 64-bit HotSpot with default compressed oops and compressed class pointers, estimate the size of newObject(), an Integer, and a String holding 5 ASCII characters. How would you verify your estimate?JDK 25 offers compact object headers as a product feature that is off by default. Your platform team asks whether to enable it across the fleet. How do you decide and roll it out?Compressed oops
Why does a reference field take 4 bytes on most 64-bit JVM heaps but 8 bytes on some? What setting decides this?What are compressed oops, why does a heap of 32 GB or more lose them, and why can -Xmx31g give more usable space and better performance than -Xmx33g?Escape analysis and scalar replacement
Does Java ever allocate objects on the stack? Explain what escape analysis lets HotSpot do instead.Consider:record Point(int x, int y) {}
long sum(int n) {
long s = 0;
for (int i = 0; i < n; i++) {
Point p = new Point(i, i);
s += p.x() + p.y();
}
return s;
}
No question matches these choices.