⚙️ JVM Internals and Performance — interview questions
11 questions. Filter by what the role asks for; open one for the six layers of the answer. The course is where the answers come from.
11 of 11
01A teammate says "Metaspace is just PermGen with a new name." Someone else adds "and it can't run out of memory anymore, since it's not part of the heap." What's wrong with each claim?Memory areaseasy0-2y02A service holds five million numbers in a `List<Integer>` and someone proposes switching to `int[]` "to save a bit of overhead." How much memory does that actually save, and why is the answer not obvious from the field types alone?Memory areaseasy0-2y03A production error reads `ClassCastException: Cannot cast plugin.PriceRule to plugin.PriceRule` — the exact same class name on both sides. A teammate assumes it's a build artifact with a stale class file. Is that a reasonable first guess, and what's actually going on?Class loadingmedium3-5y04A code review comment says "this method allocates a small, short-lived object every call in a hot loop — that's going to hurt GC." Is that always true in Java, and what would you actually check before rewriting the code to avoid the allocation?JIT compilationmedium3-5y05A service's G1 GC log shows frequent young collections tagged `(G1 Humongous Allocation)`, and separately, over a few hours, GC time climbs toward 100% of wall-clock time with each collection recovering almost nothing. Are these the same problem? What's the fix for each?Garbage collectionmedium3-5y06G1's young collections only scan eden and survivor spaces, not the whole heap — that's how they stay fast. But an object in eden can be kept alive by a reference sitting in the old generation. How does a 'partial' collection find that reference without scanning the old generation on every single pause?Garbage collectionhard5-8y07A `-XX:+PrintCompilation` log shows a compile tagged with a `%` symbol — an on-stack replacement compile — right after a batch job's main loop has been running for a while. Why does the JVM need a special mechanism for this, instead of just letting the normal tier-based recompilation handle it the way it does for an ordinary method?JIT compilationhard5-8y08Parent delegation means a class loader asks its parent first, and a parent has no way to ask a child. So how does `DriverManager` — loaded by the bootstrap loader, part of the core JDK — ever find a JDBC driver class that lives in application code, sitting on a child loader several levels below it?Class loadinghard5-8y09A JFR flame graph shows 70% of samples inside a small, three-line utility method called from dozens of hot call sites, and it's compiled at tier 4 early in the run. A team is about to spend a week rewriting it. What should they check before trusting that number, and why does this specific method — small, aggressively inlined, fully optimised — deserve extra suspicion rather than less?Profilingsenior8+y10Eclipse MAT's Leak Suspects Report ranks a `HashMap` instance as the #1 candidate in one heap dump, and finds nothing obviously wrong in a second dump where the actual leak turns out to be eight separate `ArrayList` instances, each individually unremarkable. Why would the same kind of tool succeed on one and miss the other, and what would make it catch both?Memory leak diagnosissenior8+y11A G1 GC log shows a run of mixed collections that stop keeping up, followed by a line tagged `(Evacuation Failure)`, followed shortly by a `Pause Full` that takes over half a second. What does each of these three events actually mean, in order, and what's the one thing you'd change first?Profiling and tuninghard5-8y