<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Aravindh Vellaiyan on Medium]]></title>
        <description><![CDATA[Stories by Aravindh Vellaiyan on Medium]]></description>
        <link>https://medium.com/@aravindh.vellaiyan?source=rss-0e4cca45efe0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*gxj-q1xRrlflGqfd</url>
            <title>Stories by Aravindh Vellaiyan on Medium</title>
            <link>https://medium.com/@aravindh.vellaiyan?source=rss-0e4cca45efe0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 16:59:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aravindh.vellaiyan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Beyond the Bytecode: An Architectural Deep Dive into Modern Java Internals]]></title>
            <link>https://medium.com/@aravindh.vellaiyan/beyond-the-bytecode-an-architectural-deep-dive-into-modern-java-internals-eef12a81227c?source=rss-0e4cca45efe0------2</link>
            <guid isPermaLink="false">https://medium.com/p/eef12a81227c</guid>
            <dc:creator><![CDATA[Aravindh Vellaiyan]]></dc:creator>
            <pubDate>Fri, 02 Jan 2026 05:47:31 GMT</pubDate>
            <atom:updated>2026-01-02T05:47:31.758Z</atom:updated>
            <content:encoded><![CDATA[<p>We often treat the JVM as a black box: we feed it .java files and it spits out running applications. To architect high-throughput, low-latency systems, we must understand the machinery executing our code.</p><p>This article moves beyond the syntax and standard libraries to explore the mechanics of the HotSpot JVM, the evolution of Garbage Collection, the magic of JIT compilation and the paradigm shift of Project Loom.</p><h3>1. The Classloading Subsystem: It’s Not Just “Loading”</h3><p>Most engineers know the Classloader loads classes. But the complexity lies in the <strong>linking</strong> and <strong>initialization</strong> phases, and how they affect startup time and memory footprint.</p><h4>The Lifecycle</h4><ol><li><strong>Loading:</strong> The JVM finds the binary representation of a class (usually a .class file) and creates a java.lang.Class instance in the Heap.</li><li><strong>Linking:</strong> This is the critical step often overlooked.</li></ol><ul><li><strong>Verification:</strong> Ensures bytecodes obey the JVM specification (preventing stack overflows, invalid type conversions).</li><li><strong>Preparation:</strong> Allocates memory for static variables and initializes them to default values (zero/null).</li></ul><p>3. <strong>Initialization:</strong> This is where your static { ... } blocks run.</p><blockquote>Understanding “Resolution” is key to debugging NoClassDefFoundError vs ClassNotFoundException. The former often happens during the linking phase when a dependency that was present at compile time is missing at runtime <em>link</em> time.</blockquote><h3>2. Memory Management: The Evolution of the Heap</h3><p>The “Generational Hypothesis” — that most objects die young — has driven JVM memory architecture for decades. However, as heap sizes grew from gigabytes to terabytes, the strategy had to change.</p><h4><strong>The Old Guard: G1 GC</strong></h4><p>G1 (Garbage First) replaced CMS as the default. It breaks the heap into <strong>regions</strong> rather than contiguous Generational spaces.</p><ul><li>It tracks “live data” in each region.</li><li>It focuses collection on regions with the most garbage (hence “Garbage First”) to meet user-defined pause time goals (-XX:MaxGCPauseMillis).</li></ul><h4>The New Frontier: ZGC and Shenandoah</h4><p>Low-latency collectors are the modern game-changer. ZGC (Z Garbage Collector) is designed for terabyte-sized heaps with pause times not exceeding 10ms (often &lt;1ms).</p><h4>How ZGC works (The Magic of Colored Pointers):</h4><p>ZGC uses <strong>Load Barriers</strong> and <strong>Colored Pointers</strong>. Instead of stopping the world to move objects and update references (compaction), ZGC updates the pointer metadata.</p><ul><li>The 64-bit reference address is used to store state bits (Marked, Remapped, etc.).</li><li>When a thread reads a reference (load barrier), the JVM checks these bits. If the object has moved, the JVM fixes the reference immediately (“self-healing”).</li></ul><blockquote>If you are building high-frequency trading platforms or real-time bidding systems, moving from G1 to ZGC can reduce P99 latency spikes by orders of magnitude without changing a line of code.</blockquote><h3>3. The Execution Engine: Interpreter vs. JIT</h3><p>Java is not purely interpreted, nor is it purely compiled. It is a hybrid.</p><h4>The Tiered Compilation Model</h4><ul><li><strong>Interpreter:</strong> Starts execution immediately. It is slow but has zero startup cost.</li><li><strong>C1 Compiler (Client):</strong> As code becomes “warm” (method invocation counters hit a threshold), the C1 compiler compiles bytecode to native code with simple optimizations.</li><li><strong>C2 Compiler (Server):</strong> As code becomes “hot,” the heavy-duty C2 compiler kicks in. It performs aggressive optimizations based on <strong>profiling data</strong> gathered during the interpreted/C1 phases.</li></ul><h4>Key C2 Optimizations</h4><ul><li><strong>Inlining:</strong> The mother of all optimizations. By pulling the body of a called method into the caller, the overhead of the method call is removed, and further optimizations (like dead code elimination) become possible.</li><li><strong>Loop Unrolling:</strong> Reduces the overhead of loop control code.</li><li><strong>Escape Analysis:</strong> The JVM analyzes the scope of a new object. If the object <strong>does not escape</strong> the method (i.e., it’s not returned or assigned to a static field), the JVM performs <strong>Scalar Replacement</strong>.</li><li><em>The Result:</em> The object is never allocated on the Heap. Its fields are essentially treated as local variables on the Stack. This reduces GC pressure significantly.</li></ul><blockquote>Write simple, small methods. Massive “god methods” are harder for the C2 compiler to inline and optimize. Trust the JIT; don’t hand-optimize code (like manually unrolling loops) unless JMH benchmarks prove it’s necessary.</blockquote><h3>4. The Java Memory Model (JMM) &amp; Concurrency</h3><p>The JMM defines how threads interact through memory. It is defined in terms of actions (read/write) and the <strong>Happens-Before</strong> relationship.</p><h4>The Volatile Keyword</h4><p>volatile is not just about atomicity (it doesn&#39;t guarantee it for compound actions like i++). It guarantees <strong>Visibility</strong> and <strong>Ordering</strong>.</p><ul><li><strong>Visibility:</strong> A write to a volatile field is immediately flushed to main memory, and reads invalidate the local CPU cache.</li><li><strong>Ordering:</strong> It acts as a memory barrier, preventing the CPU/Compiler from reordering instructions across the volatile access.</li></ul><h4>Project Loom: Virtual Threads</h4><p>This is the biggest shift in Java concurrency since Java 5.</p><ul><li><strong>Platform Threads (Old):</strong> 1:1 mapping to OS Kernel threads. Heavy (2MB stack), context switching is expensive (syscalls).</li><li><strong>Virtual Threads (New):</strong> M:N mapping. Thousands of virtual threads map to a single carrier (OS) thread.</li><li><strong>Mechanism:</strong> When a virtual thread performs a blocking I/O operation, the JVM unmounts it from the carrier thread and parks it in the heap. The carrier thread is free to execute another virtual thread.</li></ul><blockquote>Loom kills the “Reactive Programming” necessity for 90% of use cases. You can write simple, blocking, imperative code (thread-per-request) and still achieve the throughput of non-blocking, asynchronous frameworks like WebFlux or Netty.</blockquote><h3>5. Observability: Flight Recorder (JFR)</h3><p><strong>Java Flight Recorder (JFR)</strong> is a low-overhead (typically &lt;1%) profiling engine built directly into the JVM. It records events like:</p><ul><li>GC Pauses and allocation rates.</li><li>Method profiling (CPU hotspots).</li><li>Thread latency (wait/park times).</li><li>Socket read/write durations.</li></ul><p>Because it is built-in, it accesses data structures without the overhead of external agents.</p><h3>Conclusion</h3><p>Understanding the internals of the JVM allows us to reason about performance not as a dark art, but as a deterministic engineering challenge. Whether it’s leveraging Escape Analysis to reduce GC pressure, switching to ZGC for latency, or adopting Virtual Threads for throughput, the “black box” is actually a configurable, high-performance engine waiting to be tuned.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eef12a81227c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>