anantbhandarkar/make-it-right/mir-backend-jvm
Claude Code and agent skill by anantbhandarkar/make-it-right
- community
Checking that the SKILL.md file is still in the repository.
Make It Right (JVM runtime tier). Java 25/21 LTS and Kotlin runtime reliability footguns shared across every JVM backend framework — distinct from the generic backend gates and from any one framework's mechanics. Covers: thread-pool sizing and pool-exhaustion deadlock, blocking I/O on platform threads, virtual threads after JEP 491 (synchronized no longer pins on Java 24+, jdk.VirtualThreadPinned JFR event) and virtual threads not bounding concurrency, GC choice (G1, ZGC, Generational Shenandoah) and container-aware heap sizing (-XX:MaxRAMPercentage), cold start (Leyden AOT cache, AppCDS, GraalVM native image, CRaC), JMM visibility and data races, ThreadLocal leaks in pooled threads, and JVM-level security (untrusted deserialization and ObjectInputFilter, XXE defaults, SSRF to the cloud metadata IP, Security Manager disabled since JDK 24, Maven/Gradle dependency verification). Chains: mir-backend -> this -> framework module. TRIGGER when the backend runtime is Java or Kotlin on the JVM. SKIP for Python, Node, Go, Rust, .NET, Ruby, PHP, and BEAM runtimes (each has its own mir-backend-<runtime> tier), and SKIP for framework-library mechanics — @Transactional, Panache, @ExecuteOn and Hibernate fetch strategies live in mir-backend-jvm-spring, mir-backend-jvm-quarkus, and mir-backend-jvm-micronaut, not here.
Install
npx vskill@latest install anantbhandarkar/make-it-right/mir-backend-jvmSKILL.md
The same SKILL.md was published earlier as anantbhandarkar/make-it-right/mir-backend-jvm.
/mir-backend-jvm · Make It Right (JVM runtime)
The middle tier. mir-backend decides what is correct (any language). The framework module (e.g. mir-backend-jvm-spring) knows the library's mechanics. This tier owns what's true for all JVM backends because they run on the HotSpot JVM — the threading model, garbage collector, memory model, process lifecycle, and JDK-level security defaults that Spring Boot, Quarkus, Micronaut, and Vert.x all inherit.
Runtime assumed: Java 25 LTS or Java 21 LTS, Java or Kotlin. Notes reference OpenJDK/HotSpot defaults. Load order: mir-backend → mir-backend-jvm → <framework module>.
Read the actual JDK version out of the build file before applying any of this. Spring Boot 4, Quarkus 3.x, and Micronaut 4.x all still declare a Java 17 baseline, so a service that uses a current framework can be running a JDK where half of this file does not apply. <maven.compiler.release>, java.toolchain.languageVersion, and the base image tag are the three places to look, and they disagree often.
Version status, verified 13 Aug 2026:
| Release | Status | What it means for a new service | |
|---|---|---|---|
| Java 25 | Current LTS. GA 16 Sep 2025, OpenJDK updates through Sep 2030 | The default target. Brings the AOT cache with method profiling, Generational Shenandoah, compact object headers | |
| Java 21 | Previous LTS, still supported | Fine to stay on, but synchronized still pins virtual threads here — see §2. Oracle's own builds move to the OTN license for updates published after Sep 2026 | |
| Java 17 | Older LTS, still the declared baseline of Spring Boot 4 / Quarkus 3.x / Micronaut 4.x | Virtual threads do not exist. All of §2 is inapplicable: no Thread.ofVirtual(), no newVirtualThreadPerTaskExecutor(), no ScopedValue, no AOT cache, no ZGC generational mode. Thread-per-request means platform threads and §1's pool sizing is the whole story | |
| Java 26 | Non-LTS. GA 17 Mar 2026, updates end Sep 2026 | Do not put a production SLA on it. JDK 27 (also non-LTS) is due Sep 2026 | |
| Java 24 | Non-LTS, past EOL | Matters only as the release where synchronized stopped pinning (JEP 491) |
The JVM footguns AI walks into (framework-agnostic)
1. Thread-pool sizing and pool-exhaustion deadlock
Platform threads are expensive (≈1 MB stack each by default). The JVM's blocking I/O model means every request that waits on the DB, cache, or downstream HTTP holds a thread.
Little's Law sets the floor: threads_needed = throughput_rps × latency_s. At 500 req/s with 200 ms average latency you need 100 threads just to break even — the JVM default ForkJoinPool.commonPool() has only CPU_cores - 1.
Pool-exhaustion deadlock is the failure that produces no error: a pooled request thread submits a subtask to the same pool and then get()s on the future. If all pool slots are occupied waiting on their own subtasks, no thread is available to run those subtasks — the whole pool gridlocks. Every .get() or join() inside a thread-pool-backed executor is a suspect.
Bulkhead: give each downstream (DB, payment service, search) its own bounded pool. A single slow downstream can then only exhaust its own bulkhead, not every request path.
2. Virtual threads: what JEP 491 changed, and what it did not
On platform threads, blocking I/O (JDBC, sync HttpClient, Thread.sleep) holds the OS thread for the full duration. That is why reactive frameworks exist: they free the thread during the wait.
Virtual threads unmount from their carrier thread while blocked on I/O, so a thread-per-request blocking design scales without reactive code. JDK HTTP client, Socket, and file I/O all park correctly.
The pinning advice in most existing code and blog posts is now out of date:
| JDK | synchronized / Object.wait() while blocked | Correct action | |
|---|---|---|---|
| 21–23 | Pins the carrier thread | Upgrade the JDK. Rewriting locks is the expensive way to fix this | |
| 24+ (JEP 491) | Does not pin — the carrier is released | Nothing. Leave synchronized alone |
Older JDBC drivers that used synchronized internally (a well-known source of pinning on Java 21) stop pinning on 24+ for the same reason. Driver upgrades are still worth doing, but they are no longer the fix for pinning.
Still pins on Java 24+, per JEP 491's own list: blocking inside native code, or when native/JNI/FFM code calls back into Java and that callback blocks or waits on a monitor; blocking while a symbolic reference is being resolved and a class loaded; blocking inside a class initializer; and waiting for another thread to finish initializing a class.
The diagnostic flag was removed in JDK 24. Setting it is not an error — it is a system property, so the JVM starts normally, prints nothing, and you conclude there is no pinning.
Virtual threads do not bound concurrency — they remove the bound. A million virtual threads hitting a 20-connection JDBC pool produce a million-deep queue at the pool, not a faster service. Whatever is finite (DB connections, a downstream rate limit, a vendor quota) is the real ceiling. Declare it: a Semaphore per dependency, or a bounded pool, and shed load when it is full instead of queueing without limit.
Never pool virtual threads. They are cheap to create and are meant to be one per task. Executors.newVirtualThreadPerTaskExecutor() is the whole API; a fixed-size virtual-thread pool re-introduces the queueing you switched to avoid.
`ThreadLocal` caching becomes an allocation problem. Libraries that cache an expensive object per thread (ThreadLocal<SimpleDateFormat>, per-thread byte buffers, object pools) assume a small, stable thread set. One virtual thread per request means one fresh copy per request. Audit hot paths for ThreadLocal pooling before moving them onto virtual threads.
3. GC pauses: G1 vs ZGC vs Shenandoah
The default collector (G1) targets throughput with occasional stop-the-world pauses. A full GC can pause all application threads for hundreds of milliseconds to several seconds on large heaps.
| Collector | Pause target | Heap sweet spot | Use when | |
|---|---|---|---|---|
| G1 (default) | 200 ms (tunable with -XX:MaxGCPauseMillis) | 4 GB – 64 GB | General-purpose; CPU to spare | |
ZGC (-XX:+UseZGC) | Sub-millisecond, concurrent | Any | Latency-sensitive APIs, trading, real-time | |
Shenandoah (-XX:+UseShenandoahGC) | Sub-millisecond, concurrent | Any | Same as ZGC; Java 25 adds a generational mode |
ZGC's old non-generational mode has been removed from current JDKs, so flags copied from pre-2024 articles (-XX:+ZGenerational and friends) may be unrecognised or ignored. Confirm against your exact JDK with java -XX:+PrintFlagsFinal -version | grep -i zgc instead of trusting a blog post.
Allocation pressure is the root cause of most G1 trouble: objects allocated faster than G1 reclaims regions trigger full GC. Reduce it by reusing buffers, avoiding boxing (int → Integer) in hot paths, and keeping short-lived objects short-lived so they die in Eden instead of being promoted.
Tune G1 targets before switching collectors:
4. Container memory: use -XX:MaxRAMPercentage, not a hard -Xmx
Container awareness is on by default (-XX:+UseContainerSupport), but AI almost always hard-codes `-Xmx` — and that value is then wrong the moment the pod's memory limit changes.
Leave 20–25% for off-heap: metaspace, code cache (JIT), direct byte buffers, thread stacks. At MaxRAMPercentage=90, metaspace growth pushes the process past the cgroup limit and the OOM killer terminates the container while your heap metrics still look healthy.
Do not set -XX:MaxMetaspaceSize as a reflex — an arbitrary cap converts normal class-metadata growth into an avoidable OutOfMemoryError: Metaspace, and it hides a classloader leak instead of surfacing it. Measure class count and native memory first; add a tested cap only when the container budget demands one, with headroom for framework-generated classes, proxies, and agents.
On Java 25, -XX:+UseCompactObjectHeaders (JEP 519, a product option since 25 — confirm with java -XX:+PrintFlagsFinal -version | grep UseCompactObjectHeaders) cuts the HotSpot object header to 64 bits, from 96 with compressed class pointers or 128 without. Actual savings depend on field layout and alignment, so measure the real heap before raising a pod's memory request.
5. Cold start: JIT warmup and the AOT cache
The JVM starts fast enough for long-running servers but is hostile to serverless / scale-to-zero:
- Bytecode is interpreted until HotSpot's profiler decides a method is "hot" (C1 after ~2000 invocations, C2 after ~10000).
- A freshly started JVM can be 5–20× slower for the first few thousand requests as JIT compilation runs concurrently.
This is the runtime-map reason "SKIP JVM for serverless with zero cold-start tolerance."
Mitigations, current as of Java 25:
| Option | Needs | What it removes | |
|---|---|---|---|
AOT cache (-XX:AOTCache) | JDK 24+ (JEP 483) | Class loading and linking work at startup | |
| AOT cache + method profiles | JDK 25+ (JEP 514/515) | Also the JIT's profiling phase — the JIT starts from recorded profiles | |
| AOT object caching with any GC | JDK 26+ (JEP 516) | The earlier restriction that excluded ZGC | |
| AppCDS | pre-24 JDKs | Class metadata parsing only — superseded by the AOT cache | |
| GraalVM native image | closed-world build | The JIT entirely; millisecond startup, but reflection must be registered and peak throughput can be lower than a warmed JVM | |
| CRaC | Linux + CRIU | Everything — restores a warmed process image. Supported by Spring Boot since 3.2 and Micronaut since 4.2 | |
| Traffic warm-up | a load balancer you control | Nothing, but it keeps cold instances out of rotation until they are warm |
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/mir-backend-jvm/SKILL.md
Popularity
- Repository stars
- 15
- 7-day trend score
- 14
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/anantbhandarkar/make-it-right/mir-backend-jvm)