> Markdown version of [/videos/240-just-in-time-compilation-in-jvm?t=901](https://www.wearedevelopers.com/videos/240-just-in-time-compilation-in-jvm?t=901). Every page supports `.md` or `Accept: text/markdown`. Links point to the HTML versions so they work for humans too. Agent guide: [/agents.md](https://www.wearedevelopers.com/agents.md). --- # Just-in-time Compilation in JVM Is Java compiled or interpreted? The answer is uniquely both. Discover how the JVM's tiered JIT compilation dynamically transforms bytecode into optimized machine code. - **Speakers:** Daniel Strmečki - **Event:** WeAreDevelopers LIVE - **Published:** September 1, 2021 - **Duration:** 37:45 - **URL:** https://www.wearedevelopers.com/videos/240-just-in-time-compilation-in-jvm ## Summary Explore the fundamental question of software execution: Is Java compiled or interpreted? Conceptually, it is uniquely both. Java achieves its highly coveted "write once, run anywhere" portability by initially compiling high-level source code into platform-neutral bytecode. However, the true performance engine lies within the Java Virtual Machine (JVM), which utilizes Just-In-Time (JIT) compilation in tandem with an active interpreter. By dynamically translating highly executed bytecode segments—referred to as "hotspots"—into native machine code during runtime, Java perfectly balances cross-platform compatibility with execution speeds that can frequently rival natively compiled languages like C++. Since Java 7, the JVM has leveraged "tiered compilation" to natively marry the best of its two internal compilation processes: the C1 "client compiler" and the C2 "server compiler." Application execution always begins at Level 0 with standard code interpretation. As the JVM continuously gathers method runtime profiling data, highly invoked methods escalate through initial C1 compilation to guarantee fast startup times. Over time, these stabilized methods graduate to Level 4 C2 compilation, which produces heavily optimized machine code for long-running execution. This complex orchestration strictly relies on a dedicated JVM code cache to securely store optimized instructions, dynamically maximizing post-warmup performance. Developers can look inside this execution lifecycle using the `-XX:+PrintCompilation` diagnostic flag, which accurately reveals timestamps, tiered compilation levels, and critical state changes such as "de-optimization." De-optimization specifically acts as an execution failsafe; if the JIT compiler's runtime assumptions are invalidated by shifting application behavior, it aggressively discards the cached machine code and forces the JVM back to the interpreter for fresh profiling. While developers maintain the power to manually tweak compilation thresholds or entirely disable JIT execution using the `-Xint` flag, leaning heavily on the JVM's default tiered parameters typically guarantees peak application performance while abstracting the heavy lifting of continuous profiling and memory heap allocation. **Keywords:** JVM architecture, JIT compilation, tiered compilation, C1 and C2 compilers, bytecode interpretation, hotspot JVM profiling, JVM de-optimization, compilation thresholds, printcompilation flag, runtime performance benchmarking, JVM code cache, machine code generation, execution engine internals ## Chapters 1. **Differences between compiled and interpreted programming languages** (01:04) — Compilers convert code directly to machine native form while interpreters execute instructions piece by piece during runtime. 1. **Java portability and JVM bytecode execution architecture** (04:10) — Java achieves cross-platform compatibility by compiling source files into specialized bytecode that the Java Virtual Machine interprets natively. 1. **Enhancing JVM performance with just-in-time compilation** (07:52) — The JIT compiler boosts performance by dynamically translating frequently executed hotspot routines into machine-native instructions during runtime. 1. **Benchmarking JIT performance against C++ and JavaScript** (10:09) — Disabling the JIT compiler reveals vast algorithmic slowdowns when compared to the highly optimized execution speeds of native languages like C++. 1. **Comparing client and server JIT compiler implementations** (12:57) — Client compilation prioritizes fast application startup times while server compilation focuses on deep code optimization for long-running workloads. 1. **Optimizing Java performance with tiered compilation concepts** (15:01) — Tiered compilation blends rapid startup with long-term efficiency by progressively replacing quickly compiled blocks with heavily optimized instructions as profiling data accumulates. 1. **Exploring five distinct compilation levels within the JVM** (18:06) — The JVM escalates source logic through multiple interpretation and profiling stages depending on algorithm complexity and available compilation queues. 1. **Managing code caching and assumption-based method deoptimization** (20:22) — The JVM automatically purges compiled methods from the internal cache when changing runtime behaviors invalidate the compiler's initial optimization assumptions. 1. **Tweaking JVM compilation thresholds and runtime execution flags** (21:56) — Software engineers can optionally bypass optimization layers or edit threshold thresholds to restrict how many invocations are required before aggressive compilation starts. 1. **Tracing method lifecycles using printed JVM compilation logs** (23:48) — Activating print parameters exposes detailed output revealing the exact timestamp, active compilation tier, and deoptimization triggers for specific application methods. 1. **Discussion on JIT memory parameters and cross-language benchmarking** (29:15) — The final sessions explore topics covering internal heap allocation limits for compiled code pools, machine code portability constraints, and overall language efficiency metrics. ## Related Moments - [Understanding Java virtualization and just-in-time compiler performance challenges](https://www.wearedevelopers.com/videos/1595-like-spring-but-faster-the-new-java-jedi) (from "Like Spring, but Faster: The new Java Jedi") - [Understanding Java virtual machine just-in-time compilation](https://www.wearedevelopers.com/videos/443-going-serverless-using-the-spring-framework-ecosystem) (from "Going serverless using the Spring Framework ecosystem") - [Understanding JIT compilation and breakpoint de-optimization](https://www.wearedevelopers.com/videos/846-debugging-unveiled-exploring-debugger-internals-and-hidden-gems) (from "Debugging Unveiled: Exploring Debugger Internals and Hidden Gems") - [Improving runtime performance through just-in-time compilation](https://www.wearedevelopers.com/videos/100094-from-bytes-to-execution-writing-a-webassembly-runtime-in-rust) (from "From Bytes to Execution: Writing a WebAssembly Runtime in Rust") - [Optimizing Java tiered compilation in short-lived environments](https://www.wearedevelopers.com/videos/1205-high-performance-serverless-java-on-aws) (from "High performance Serverless Java on AWS") - [Comparing Java adaptive compilation with ahead-of-time builds](https://www.wearedevelopers.com/videos/383-kubernetes-native-java) (from "Kubernetes Native Java") ## Related Articles - [Using Java 17 latest features in real world projects](https://www.wearedevelopers.com/magazine/121-using-java-17-latest-features-in-real-world-projects) - [Java Basics](https://www.wearedevelopers.com/magazine/122-java-basics) - [Top 10 Java Libraries](https://www.wearedevelopers.com/magazine/364-top-10-java-libraries) - [Modern Java Records](https://www.wearedevelopers.com/magazine/41-modern-java-records) ## Related Jobs - [Senior Software Engineer](https://www.wearedevelopers.com/jobs/ext/15942-senior-software-engineer) at **GitHub** - [Hardware-naher Algorithmenentwickler](https://www.wearedevelopers.com/jobs/ext/1684535-hardware-naher-algorithmenentwickler) at **ZEISS Group** - [Senior Engineer, Infrastructure Platform](https://www.wearedevelopers.com/jobs/ext/328836-senior-engineer-infrastructure-platform) at **Intercom, Inc.** - [Software Engineer L2 - Cloud Infrastructure](https://www.wearedevelopers.com/jobs/ext/1282024-software-engineer-l2-cloud-infrastructure) at **Twilio** - [Software Engineer L3](https://www.wearedevelopers.com/jobs/ext/1840587-software-engineer-l3) at **Twilio** - [Software Engineer, Platform Engineering (L2)](https://www.wearedevelopers.com/jobs/ext/1956829-software-engineer-platform-engineering-l2) at **Twilio**