Recent from talks
Contribute something
Nothing was collected or created yet.
Java virtual machine
View on Wikipedia| Designer | Sun Microsystems |
|---|---|
| Bits | 32-bit, 64-bit[a] |
| Introduced | 1994 |
| Type | Stack and register–register |
| Encoding | Variable |
| Branching | Compare and branch |
| Endianness | Big |
| Open | Yes |
| Registers | |
| General-purpose | Per-method operand stack (up to 65535 operands) plus per-method local variables (up to 65535) |

A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally describes what is required in a JVM implementation. Having a specification ensures interoperability of Java programs across different implementations so that program authors using the Java Development Kit (JDK) need not worry about idiosyncrasies of the underlying hardware platform.
The JVM reference implementation is developed by the OpenJDK project as open source code and includes a JIT compiler called HotSpot. The commercially supported Java releases available from Oracle are based on the OpenJDK runtime. Eclipse OpenJ9 is another open source JVM for OpenJDK.
JVM specification
[edit]The Java virtual machine is an abstract (virtual) computer defined by a specification. It is a part of the Java runtime environment. The garbage collection algorithm used and any internal optimization of the Java virtual machine instructions (their translation into machine code) are not specified. The main reason for this omission is to not unnecessarily constrain implementers. Any Java application can be run only inside some concrete implementation of the abstract specification of the Java virtual machine.[3]
Starting with Java Platform, Standard Edition (J2SE) 5.0, changes to the JVM specification have been developed under the Java Community Process as JSR 924.[4] As of 2006[update], changes to the specification to support changes proposed to the class file format (JSR 202)[5] are being done as a maintenance release of JSR 924. The specification for the JVM was published as the blue book,[6] whose preface states:
We intend that this specification should sufficiently document the Java Virtual Machine to make possible compatible clean-room implementations. Oracle provides tests that verify the proper operation of implementations of the Java Virtual Machine.
The most commonly used Java virtual machine is Oracle's HotSpot.
Oracle owns the Java trademark and may allow its use to certify implementation suites as fully compatible with Oracle's specification.
Garbage collectors
[edit]| Version | Default GC | Available GCs |
|---|---|---|
| 6u14 | Serial / Parallel (MP) |
Serial, Parallel, CMS, G1 (E) |
| 7u4 - 8 | Serial, Parallel, CMS, G1 | |
| 9 - 10 | G1 | |
| 11 | Serial, Parallel, CMS, G1, Epsilon (E), ZGC (E) | |
| 12 - 13 | Serial, Parallel, CMS, G1, Epsilon (E), ZGC (E), Shenandoah (E) | |
| 14 | Serial, Parallel, G1, Epsilon (E), ZGC (E), Shenandoah (E) | |
| 15 - 20 | Serial, Parallel, G1, Epsilon (E), ZGC, Shenandoah | |
| 21 - 22 | Serial, Parallel, G1, Epsilon (E), ZGC, Shenandoah, GenZGC (E) | |
| 23 | Serial, Parallel, G1, Epsilon (E), ZGC, Shenandoah, GenZGC (default ZGC) | |
| 24 | Serial, Parallel, G1, Epsilon (E), Shenandoah, GenZGC, GenShen (E) | |
| 25 | Serial, Parallel, G1, Epsilon (E), Shenandoah, GenZGC, GenShen | |
| (E) = experimental | ||
Class loader
[edit]One of the organizational units of JVM byte code is a class. A class loader implementation must be able to recognize and load anything that conforms to the Java class file format. Any implementation is free to recognize other binary forms besides class files, but it must recognize class files.
The class loader performs three basic activities in this strict order:
- Loading: finds and imports the binary data for a type
- Linking: performs verification, preparation, and (optionally) resolution
- Verification: ensures the correctness of the imported type
- Preparation: allocates memory for class variables and initializing the memory to default values
- Resolution: transforms symbolic references from the type into direct references.
- Initialization: invokes Java code that initializes class variables to their proper starting values.
In general, there are three types of class loader: bootstrap class loader, extension class loader and System / Application class loader.
Every Java virtual machine implementation must have a bootstrap class loader that is capable of loading trusted classes, as well as an extension class loader or application class loader. The Java virtual machine specification does not specify how a class loader should locate classes.
Virtual machine architecture
[edit]The JVM operates on specific types of data as specified in Java Virtual Machine specifications. The data types can be divided[7] into primitive types (integer and floating-point values) and reference types. long and double types, which are 64-bits, are supported natively, but consume two units of storage in a frame's local variables or operand stack, since each unit is 32 bits. boolean, byte, short, and char types are all sign-extended (except char which is zero-extended) and operated on as 32-bit integers, the same as int types. The smaller types only have a few type-specific instructions for loading, storing, and type conversion. boolean is operated on as 8-bit byte values, with 0 representing false and 1 representing true. (Although boolean has been treated as a type since The Java Virtual Machine Specification, Second Edition clarified this issue, in compiled and executed code there is little difference between a boolean and a byte except for name mangling in method signatures and the type of boolean arrays. booleans in method signatures are mangled as Z while bytes are mangled as B. Boolean arrays carry the type boolean[] but use 8 bits per element, and the JVM has no built-in capability to pack booleans into a bit array, so except for the type they perform and behave the same as byte arrays. In all other uses, the boolean type is effectively unknown to the JVM as all instructions to operate on booleans are also used to operate on bytes.)
The JVM has a garbage-collected heap for storing objects and arrays. Code, constants, and other class data are stored in the "method area". The method area is logically part of the heap, but implementations may treat the method area separately from the heap, and for example might not garbage collect it. Each JVM thread also has its own call stack (called a "Java Virtual Machine stack" for clarity), which stores frames. A new frame is created each time a method is called, and the frame is destroyed when that method exits.
Each frame provides an "operand stack" and an array of "local variables". The operand stack is used for operands to run computations and for receiving the return value of a called method, while local variables serve the same purpose as registers and are also used to pass method arguments. Thus, the JVM is both a stack machine and a register machine. In practice, HotSpot eliminates every stack besides the native thread/call stack even when running in Interpreted mode, as its Templating Interpreter technically functions as a compiler.
The JVM uses references and stack/array indexes to address data; it does not use byte addressing like most physical machines do, so it does not neatly fit the usual categorization of 32-bit or 64-bit machines. In one sense, it could be classified as a 32-bit machine, since this is the size of the largest value it natively stores: a 32-bit integer or floating-point value or a 32-bit reference. Because a reference is 32 bits, each program is limited to at most 232 unique references and therefore at most 232 objects. However, each object can be more than one byte large, and potentially very large; the largest possible object is an array of long of length 231 - 1 which would consume 16 GiB of memory, and there could potentially be 232 of these if there were enough memory available. This results in upper bounds that are more comparable to a typical 64-bit byte-addressable machine. A JVM implementation can be designed to run on a processor that natively uses any bit width as long as it correctly implements the integer (8-, 16-, 32-, and 64-bit) and floating-point (32- and 64-bit) math that the JVM requires. Depending on the method used to implement references (native pointers, compressed pointers, or an indirection table), this can limit the number of objects to less than the theoretical maximum. An implementation of the JVM on a 64-bit platform has access to a much larger address space than one on a 32-bit platform, which allows for a much larger heap size and an increased maximum number of threads, which is needed for certain kinds of large applications; however, there can be a performance hit from using a 64-bit implementation compared to a 32-bit implementation.
Bytecode instructions
[edit]The JVM has instructions for the following groups of tasks:
The aim is binary compatibility. Each particular host operating system needs its own implementation of the JVM and runtime. These JVMs interpret the bytecode semantically the same way, but the actual implementation may be different. More complex than just emulating bytecode is compatibly and efficiently implementing the Java core API that must be mapped to each host operating system.
These instructions operate on a set of common abstracted data types rather the native data types of any specific instruction set architecture.
JVM languages
[edit]A JVM language is any language with functionality that can be expressed in terms of a valid class file which can be hosted by the Java Virtual Machine. A class file contains Java Virtual Machine instructions (Java byte code) and a symbol table, as well as other ancillary information. The class file format is the hardware- and operating system-independent binary format used to represent compiled classes and interfaces.[8]
There are several JVM languages, both old languages ported to JVM and completely new languages. JRuby and Jython are perhaps the most well-known ports of existing languages, i.e. Ruby and Python respectively. Of the new languages that have been created from scratch to compile to Java bytecode, Clojure, Groovy, Scala and Kotlin may be the most popular ones. A notable feature with the JVM languages is that they are compatible with each other, so that, for example, Scala libraries can be used with Java programs and vice versa.[9]
Java 7 JVM implements JSR 292: Supporting Dynamically Typed Languages[10] on the Java Platform, a new feature which supports dynamically typed languages in the JVM. This feature is developed within the Da Vinci Machine project whose mission is to extend the JVM so that it supports languages other than Java.[11][12]
Bytecode verifier
[edit]A basic philosophy of Java is that it is inherently safe from the standpoint that no user program can crash the host machine or otherwise interfere inappropriately with other operations on the host machine, and that it is possible to protect certain methods and data structures belonging to trusted code from access or corruption by untrusted code executing within the same JVM. Furthermore, common programmer errors that often led to data corruption or unpredictable behavior such as accessing off the end of an array or using an uninitialized pointer are not allowed to occur. Several features of Java combine to provide this safety, including the class model, the garbage-collected heap, and the verifier.
The JVM verifies all bytecode before it is executed. This verification consists primarily of three types of checks:
- Branches are always to valid locations
- Data is always initialized and references are always type-safe
- Access to private or package private data and methods is rigidly controlled
The first two of these checks take place primarily during the verification step that occurs when a class is loaded and made eligible for use. The third is primarily performed dynamically, when data items or methods of a class are first accessed by another class.
The verifier permits only some bytecode sequences in valid programs, e.g. a jump (branch) instruction can only target an instruction within the same method. Furthermore, the verifier ensures that any given instruction operates on a fixed stack location,[13] allowing the JIT compiler to transform stack accesses into fixed register accesses. Because of this, that the JVM is a stack architecture does not imply a speed penalty for emulation on register-based architectures when using a JIT compiler. In the face of the code-verified JVM architecture, it makes no difference to a JIT compiler whether it gets named imaginary registers or imaginary stack positions that must be allocated to the target architecture's registers. In fact, code verification makes the JVM different from a classic stack architecture, of which efficient emulation with a JIT compiler is more complicated and typically carried out by a slower interpreter. Additionally, the Interpreter used by the default JVM is a special type known as a Template Interpreter, which translates bytecode directly to native, register based machine language rather than emulate a stack like a typical interpreter.[14] In many aspects the HotSpot Interpreter can be considered a JIT compiler rather than a true interpreter, meaning the stack architecture that the bytecode targets is not actually used in the implementation, but merely a specification for the intermediate representation that can well be implemented in a register based architecture. Another instance of a stack architecture being merely a specification and implemented in a register based virtual machine is the Common Language Runtime.[15]
The original specification for the bytecode verifier used natural language that was incomplete or incorrect in some respects. A number of attempts have been made to specify the JVM as a formal system. By doing this, the security of current JVM implementations can more thoroughly be analyzed, and potential security exploits prevented. It will also be possible to optimize the JVM by skipping unnecessary safety checks, if the application being run is proven to be safe.[16]
Secure execution of remote code
[edit]A virtual machine architecture allows very fine-grained control over the actions that code within the machine is permitted to take. It assumes the code is "semantically" correct, that is, it successfully passed the (formal) bytecode verifier process, materialized by a tool, possibly off-board the virtual machine. This is designed to allow safe execution of untrusted code from remote sources, a model used by Java applets, and other secure code downloads. Once bytecode-verified, the downloaded code runs in a restricted "sandbox", which is designed to protect the user from misbehaving or malicious code. As an addition to the bytecode verification process, publishers can purchase a certificate with which to digitally sign applets as safe, giving them permission to ask the user to break out of the sandbox and access the local file system, clipboard, execute external pieces of software, or network.
Formal proof of bytecode verifiers have been done by the Javacard industry (Formal Development of an Embedded Verifier for Java Card Byte Code[17])
Bytecode interpreter and just-in-time compiler
[edit]For each hardware architecture a different Java bytecode interpreter is needed. When a computer has a Java bytecode interpreter, it can run any Java bytecode program, and the same program can be run on any computer that has such an interpreter.
When Java bytecode is executed by an interpreter, the execution will always be slower than the execution of the same program compiled into native machine language. This problem is mitigated by just-in-time (JIT) compilers for executing Java bytecode. A JIT compiler may translate Java bytecode into native machine language while executing the program. The translated parts of the program can then be executed much more quickly than they could be interpreted. This technique gets applied to those parts of a program frequently executed. This way a JIT compiler can significantly speed up the overall execution time.
There is no necessary connection between the Java programming language and Java bytecode. A program written in Java can be compiled directly into the machine language of a real computer and programs written in other languages than Java can be compiled into Java bytecode.
Java bytecode is intended to be platform-independent and secure.[18] Some JVM implementations do not include an interpreter, but consist only of a just-in-time compiler.[19]
JVM in the web browser
[edit]At the start of the Java platform's lifetime, the JVM was marketed as a web technology for creating Rich Web Applications. As of 2018[update], most web browsers and operating systems bundling web browsers do not ship with a Java plug-in, nor do they permit side-loading any non-Flash plug-in. The Java browser plugin was deprecated in JDK 9.[20]
The NPAPI Java browser plug-in was designed to allow the JVM to execute so-called Java applets embedded into HTML pages. For browsers with the plug-in installed, the applet is allowed to draw into a rectangular region on the page assigned to it. Because the plug-in includes a JVM, Java applets are not restricted to the Java programming language; any language targeting the JVM may run in the plug-in. A restricted set of APIs allow applets access to the user's microphone or 3D acceleration, although applets are not able to modify the page outside its rectangular region. Adobe Flash Player, the main competing technology, works in the same way in this respect.
As of June 2015[update] according to W3Techs, Java applet and Silverlight use had fallen to 0.1% each for all web sites, while Flash had fallen to 10.8%.[21]
JavaScript JVMs and interpreters
[edit]Since May 2016, JavaPoly allows users to import unmodified Java libraries, and invoke them directly from JavaScript. JavaPoly allows websites to use unmodified Java libraries, even if the user does not have Java installed on their computer.[22]
Transpilation to JavaScript
[edit]With the continuing improvements in JavaScript execution speed, combined with the increased use of mobile devices whose web browsers do not implement support for plugins, there are efforts to target those users through transpilation to JavaScript. It is possible to either transpile the source code or JVM bytecode to JavaScript.
Compiling the JVM bytecode, which is universal across JVM languages, allows building upon the language's existing compiler to bytecode. The main JVM bytecode to JavaScript transpilers are TeaVM,[23] the compiler contained in Dragome Web SDK,[24] Bck2Brwsr,[25] and j2js-compiler.[26]
Leading transpilers from JVM languages to JavaScript include the Java-to-JavaScript transpiler contained in Google Web Toolkit, J2CL[27], Clojurescript (Clojure), GrooScript (Apache Groovy), Scala.js (Scala) and others.[28]
See also
[edit]Notes
[edit]References
[edit]- ^ "JEP 479: Remove the Windows 32-bit x86 Port". OpenJDK.
- ^ "JEP 503: Remove the 32-bit x86 Port". OpenJDK.
- ^ Bill Venners, Inside the Java Virtual Machine Archived 2021-01-25 at the Wayback Machine Chapter 5
- ^ "The Java Community Process(SM) Program - JSRs: Java Specification Requests - detail JSR# 924". Jcp.org. Archived from the original on 2020-12-24. Retrieved 2015-06-26.
- ^ "The Java Community Process(SM) Program - JSRs: Java Specification Requests - detail JSR# 202". Jcp.org. Archived from the original on 2012-02-26. Retrieved 2015-06-26.
- ^ The Java Virtual Machine Specification Archived 2008-07-09 at the Wayback Machine (the first Archived 2008-10-12 at the Wayback Machine and second Archived 2011-09-25 at the Wayback Machine editions are also available online).
- ^ "Chapter 2. The Structure of the Java Virtual Machine". Archived from the original on 2021-09-15. Retrieved 2021-09-15.
- ^ "The Java Virtual Machine Specification : Java SE 7 Edition" (PDF). Docs.oracle.com. Archived (PDF) from the original on 2021-02-04. Retrieved 2015-06-26.
- ^ "Frequently Asked Questions - Java Interoperability". scala-lang.org. Archived from the original on 2020-08-09. Retrieved 2015-11-18.
- ^ "The Java Community Process(SM) Program - JSRs: Java Specification Requests - detail JSR# 292". Jcp.org. Archived from the original on 2020-12-20. Retrieved 2015-06-26.
- ^ "Da Vinci Machine project". Openjdk.java.net. Archived from the original on 2020-11-11. Retrieved 2015-06-26.
- ^ "New JDK 7 Feature: Support for Dynamically Typed Languages in the Java Virtual Machine". Oracle.com. Archived from the original on 2018-09-13. Retrieved 2015-06-26.
- ^ "The Verification process". The Java Virtual Machine Specification. Sun Microsystems. 1999. Archived from the original on 2011-03-21. Retrieved 2009-05-31.
- ^ "HotSpot Runtime Overview - Interpreter". OpenJDK. Archived from the original on 2022-05-21. Retrieved 2021-05-24.
- ^ "Why not make CLR register-based? · Issue #4775 · dotnet/runtime". GitHub. Archived from the original on 2023-04-20. Retrieved 2021-05-24.
- ^ Freund, Stephen N.; Mitchell, John C. (1999). "A formal framework for the Java bytecode language and verifier". Proceedings of the 14th ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications - OOPSLA '99. pp. 147–166. CiteSeerX 10.1.1.2.4663. doi:10.1145/320384.320397. ISBN 978-1581132380. S2CID 14302964.
- ^ Casset, Ludovic; Burdy, Lilian; Requet, Antoine (10 April 2002). "Formal Development of an Embedded Verifier for Java Card Byte Code" (PDF). Inria - National Institute for Research in Digital Science and Technology at Côte d'Azur University. Archived (PDF) from the original on 3 October 2022.
- ^ David J. Eck, Introduction to Programming Using Java Archived 2014-10-11 at the Wayback Machine, Seventh Edition, Version 7.0, August 2014 at Section 1.3 "The Java Virtual Machine"
- ^ Oracle JRockit Introduction Archived 2015-09-06 at the Wayback Machine Release R28 at 2. "Understanding Just-In-Time Compilation and Optimization"
- ^ "Oracle deprecates the Java browser plugin, prepares for its demise". Ars Technica. 28 January 2016. Archived from the original on 8 April 2016. Retrieved 15 April 2016.
- ^ "Historical yearly trends in the usage of client-side programming languages, June 2015". W3techs.com. Retrieved 2015-06-26.
- ^ Krill, Paul (13 May 2016). "JavaPoly.js imports existing Java code and invokes it directly from JavaScript". InfoWorld. Archived from the original on 25 July 2016. Retrieved 18 July 2016.
- ^ "TeaVM project home page". Teavm.org. Archived from the original on 2015-06-27. Retrieved 2015-06-26.
- ^ "Dragome Web SDK". Dragome.com. Archived from the original on 2015-08-01. Retrieved 2015-06-26.
- ^ "Bck2Brwsr - APIDesign". Wiki.apidesign.org. Archived from the original on 2015-06-27. Retrieved 2015-06-26.
- ^ Wolfgang Kuehn (decatur). j2js-compiler Archived 2013-09-29 at the Wayback Machine GitHub
- ^ "J2cl: Transpile Java to JavaScript for Closure Compiler | Hacker News". news.ycombinator.com. Archived from the original on 2021-01-02. Retrieved 2025-10-31.
- ^ "List of languages that compile to JS · jashkenas/coffeescript Wiki · GitHub". Github.com. 2015-06-19. Archived from the original on 2020-01-31. Retrieved 2015-06-26.
- Clarifications and Amendments to the Java Virtual Machine Specification, Second Edition Archived 2006-01-10 at the Wayback Machine includes list of changes to be made to support J2SE 5.0 and JSR 45
- JSR 45 Archived 2006-02-05 at the Wayback Machine, specifies changes to the class file format to support source-level debugging of languages such as JavaServer Pages (JSP) and SQLJ that are translated to Java
Java virtual machine
View on GrokipediaOverview and History
Definition and Role
The Java Virtual Machine (JVM) is an abstract computing machine that enables the execution of Java bytecode, converting it into native machine code suitable for the host hardware and operating system. This specification-defined engine provides a runtime environment where compiled Java programs, in the form of platform-independent bytecode, are interpreted or just-in-time (JIT) compiled to ensure efficient operation across diverse systems. In the broader Java ecosystem, the JVM plays a central role by facilitating portability through its "write once, run anywhere" principle, allowing applications to execute seamlessly on any platform with a compatible JVM implementation without recompilation.[6] It manages memory automatically via a garbage collector that reclaims unused heap space, preventing memory leaks and simplifying development by eliminating manual allocation and deallocation.[4] Additionally, the JVM handles exceptions through dedicated bytecode instructions and runtime mechanisms, ensuring robust error propagation and recovery within applications. Key benefits of the JVM include its abstraction from underlying hardware and operating system details, which shields developers from platform-specific optimizations and compatibility issues. It provides built-in automatic memory management to optimize resource usage and reduce errors associated with manual memory handling.[4] Furthermore, the JVM natively supports multithreading, allowing multiple threads of execution to run concurrently and share access to the same memory spaces under controlled synchronization.[4]Development Timeline
The development of the Java Virtual Machine (JVM) began in 1991 as part of Sun Microsystems' Green Project, initiated by James Gosling, Mike Sheridan, and Patrick Naughton to create a platform-independent language for consumer electronics like set-top boxes.[7] Originally named Oak, the project evolved, and by 1995, it was renamed Java, with the first public demonstration occurring that year. The JVM, as the runtime environment enabling Java's "write once, run anywhere" paradigm, was integral from the outset, compiling Java source to platform-neutral bytecode executed by the JVM. The first public release came with JDK 1.0 on January 23, 1996, introducing the core JVM architecture including the bytecode verifier and interpreter. Subsequent releases built on this foundation with key enhancements. JDK 1.1, released on February 19, 1997, added support for inner classes and JavaBeans, refining JVM class loading and reflection capabilities.[8] The shift to J2SE 5.0 in September 2004 introduced generics, annotations, and autoboxing, with JVM improvements in metadata handling and concurrency primitives. Java SE 8, released March 18, 2014, brought lambda expressions and the Stream API, accompanied by JVM optimizations like the Nashorn JavaScript engine and improved garbage collection. Later long-term support (LTS) versions included Java 11 on September 25, 2018, featuring the module system via Project Jigsaw for better encapsulation; Java 17 on September 14, 2021, with sealed classes for restricted inheritance; Java 21 on September 19, 2023, integrating virtual threads from Project Loom for scalable concurrency; Java 24 on March 18, 2025, continuing previews of structured concurrency and other enhancements; and Java 25 (LTS) on September 16, 2025, finalizing Scoped Values (JEP 506) from Project Loom while placing Structured Concurrency in sixth preview (JEP 525).[8][9] Ownership transitions marked significant shifts in JVM stewardship. Sun Microsystems open-sourced the reference implementation as OpenJDK in 2006, fostering community contributions under the GPL with Classpath Exception. Oracle's acquisition of Sun, announced in April 2009 and completed on January 27, 2010, transferred control of Java and the JVM to Oracle, which has since maintained OpenJDK as the primary upstream project while offering proprietary builds.[10] As of November 2025, recent JVM advancements emphasize performance and interoperability. Project Loom's virtual threads, fully integrated in Java 21, continue evolving, with Scoped Values finalized in JDK 25 (JEP 506) and Structured Concurrency in sixth preview (JEP 525). Project Valhalla advances value types to reduce object overhead, with prototypes in previews aiming for production in 2026.[11] Project Panama's Foreign Function & Memory API, finalized in JDK 22, and the Vector API, in tenth incubator in JDK 25, enable efficient native interactions.[12][13] Influential contributors have shaped the JVM's trajectory. Brian Goetz, Oracle's Java Language Architect, has driven concurrency enhancements, including leadership on Project Loom. Doug Lea, a SUNY Oswego professor, authored key concurrency utilities like java.util.concurrent and influenced collections frameworks. The Java Community Process (JCP), established in 1998, governs specification development through expert groups, ensuring collaborative evolution of JVM-related JEPs.Core Architecture
Class Loader System
The class loader subsystem in the Java Virtual Machine (JVM) manages the dynamic loading, linking, and initialization of classes and interfaces at runtime, supporting the language's "write once, run anywhere" principle by abstracting class origins and enabling lazy evaluation. This mechanism allows the JVM to load only required classes on demand, optimizing memory usage and startup time, while maintaining a runtime representation of loaded types throughjava.lang.Class objects stored in the method area. The subsystem operates within a parent-delegation model to resolve class names uniquely across different loaders, ensuring that the same class binary yields the same Class instance only if loaded by the same loader.[14]
The namespace model relies on a delegating hierarchy of built-in class loaders to partition the JVM's class space and prevent naming conflicts. The bootstrap class loader, integral to the JVM, has no parent and loads core platform classes from the runtime image, such as the modular lib/modules file in Java SE 9 and later. It is followed by the platform class loader, which handles classes from the platform module path and runtime image modules in Java SE 9 and later. The application class loader, typically the system class loader, serves as the default parent for user-defined loaders and sources classes from the user-specified classpath, including directories and JAR files. Delegation proceeds upward: a loader first queries its parent before searching its own resources, guaranteeing that foundational classes are loaded preferentially by higher-level loaders.[14]
Loading initiates when the JVM encounters a reference to an unloaded class, such as during new, method invocation, or field access, prompting the defining class loader to locate the corresponding .class file. The loader translates the class's binary name (e.g., com.example.MyClass) into a filesystem path and searches the classpath—a sequence of directories, ZIP/JAR archives, or other resources—for the matching file. Upon discovery, the loader reads the binary stream, verifies basic format compliance, and constructs a Class object encapsulating the type's metadata, fields, methods, and constant pool, which is then associated with the loader as its defining entity. If the class is an array type, it is created synthetically without file access. This phase completes when the Class object is defined, marking the loader as initiating for that type.[15]
Linking builds upon the loaded Class object through several phases to integrate it into the JVM. Verification performs an initial structural check on the class file, passing it to the bytecode verifier for type safety analysis (as detailed in the Bytecode Verifier section). Preparation follows, allocating and initializing static variables to default values (e.g., null for references, zero for primitives) in the method area, while resolving interfaces to ensure they are loaded. Resolution dynamically links symbolic references in the constant pool—such as field or method names—to concrete runtime entities, which may recursively trigger loading and linking of dependencies. Finally, initialization executes the type's static initializers, including the <clinit> method, to compute user-defined static field values and perform one-time setup, ensuring thread-safe execution via class-level locking. These phases are triggered lazily, with resolution often deferred until first use.
The JVM provides extensibility through custom class loaders, implemented by subclassing the abstract java.lang.ClassLoader class and overriding key methods like loadClass for delegation logic or findClass for resource-specific loading. This allows applications to source classes from non-standard locations, such as networks, databases, or generated bytecode, enabling dynamic behaviors like plugin systems or versioned modules. In frameworks like OSGi, custom loaders create isolated hierarchies to manage bundle dependencies without interfering with the global namespace, supporting modular application deployment.[16]
Security in the class loader system arises from its hierarchical isolation, where each loader maintains a distinct namespace, restricting visibility and preventing untrusted code from substituting or accessing privileged classes loaded by parents. Delegation enforces a "trust but verify" model, as child loaders cannot override parent-loaded classes, thereby blocking malicious injections that could compromise core APIs. This isolation complements broader security mechanisms like permissions, with full details addressed in the Sandboxing and Permissions section.
Bytecode Representation
Java bytecode serves as the platform-independent intermediate representation of Java programs, executed by the Java Virtual Machine (JVM). It consists of typed, stack-based instructions stored within .class files, which encapsulate the compiled form of a single class or interface. The .class file format begins with a magic number (0xCAFEBABE), followed by minor and major version numbers, and includes a constant pool—a table of literals such as strings, numeric constants, class names, and method signatures—that bytecode instructions reference to avoid redundancy. Methods within the class are defined with attributes, notably the Code attribute, which specifies the maximum stack depth (max_stack), the number of local variables (max_locals), the bytecode array itself, an exception table for handling try-catch blocks, and additional attributes like LineNumberTable for debugging. The operand stack is a runtime structure implied by the bytecode design, where instructions push and pop values during execution, enabling operations without explicit registers. Bytecode instructions are variable-length, with each starting with a one-byte opcode ranging from 0 to 255, followed by zero or more operands that provide immediate values or indices into the constant pool or local variables. For instance, the dup opcode (0x59) duplicates the top value on the operand stack without operands, facilitating common patterns like parameter passing. This compact format optimizes for the JVM's stack machine model, contrasting with register-based architectures.[17] Instructions are categorized by function to support the semantics of the Java language. Load and store instructions manage data transfer between local variables and the operand stack; examples include iload_n (where n is 0-3, opcodes 0x1A-0x1D) for loading an int from a local variable and istore_n (opcodes 0x3B-0x3E) for storing an int to one. Arithmetic instructions perform computations on stack values, such as iadd (opcode 0x60), which pops two ints, adds them, and pushes the result. Control flow instructions enable branching and loops, like ifeq (opcode 0x99), which pops an int and branches to a 16-bit signed offset if it is zero, or goto (opcode 0xA7) for unconditional jumps with a similar offset. Method invocation instructions handle calls, with invokevirtual (opcode 0xB6) popping an object reference and arguments from the stack, resolving the method via the constant pool, and pushing the return value if applicable. The compilation process transforms Java source code into bytecode using the javac compiler, which parses .java files and emits optimized instructions tailored to the JVM's stack-based paradigm. Javac infers stack usage to ensure operations fit within the declared max_stack, incorporating optimizations like constant folding where possible while preserving portability. This generation adheres to the JVM specification, producing .class files verifiable for type safety and resource bounds. Over time, the bytecode instruction set has evolved to enhance flexibility, particularly for non-Java languages. A notable addition in Java SE 7 was the invokedynamic instruction (opcode 0xBA), introduced via JSR 292 to support dynamic method invocation. Unlike static invokevirtual, invokedynamic uses a bootstrap method from the constant pool to resolve call sites at runtime, enabling efficient implementation of dynamic typing and higher-order functions in languages like InvokeDynamic on the JVM.[18][19]Execution Mechanisms
Interpreter and JIT Compilation
The Java Virtual Machine (JVM) employs an interpreter as its primary mechanism for executing bytecode, ensuring platform independence by emulating a stack-based virtual machine. The interpreter processes instructions sequentially, fetching each opcode and its operands from the bytecode stream, then performing the specified operation on an operand stack and local variables. This step-by-step execution mimics hardware instructions but operates abstractly, allowing Java programs to run on diverse architectures without recompilation. To enhance performance beyond interpretation, the JVM incorporates a Just-In-Time (JIT) compiler, which dynamically translates frequently executed bytecode into native machine code tailored to the host processor. In the HotSpot JVM, the dominant implementation, JIT compilation targets "hot" code paths identified during runtime, reducing the interpretive overhead that can slow initial execution. This approach balances startup speed with long-term efficiency, as native code execution is substantially faster than interpretation.[20] HotSpot utilizes a tiered compilation strategy, progressing through multiple optimization levels to minimize compilation latency while maximizing runtime speed. The process begins with interpretation, then advances to the Client Compiler (C1), which performs quick, lightweight optimizations for rapid warmup, followed by the Server Compiler (C2) for aggressive, profile-driven enhancements. Tier 0 involves pure interpretation; tiers 1–3 use C1 with varying profiling depths (e.g., no profiling in tier 1, full in tier 3); and tier 4 invokes C2 for peak performance. This multi-tier system, enabled by default in Java 7 and later, allows methods to evolve from interpreted to highly optimized code as usage patterns emerge.[21] Compilation is triggered by invocation counters that track method calls and loop back-edges, escalating when thresholds are met to prioritize hot methods. In HotSpot, the default threshold for initial C1 compilation is approximately 200 method invocations or loop iterations for tier 3, adjustable via flags like-XX:Tier3InvocationThreshold. Once compiled, profile data from execution—such as type frequencies and branch probabilities—guides further optimizations in higher tiers, including method inlining to eliminate call overhead and loop unrolling to reduce iteration costs. These profile-guided techniques enable the JIT to specialize code based on observed behavior, often yielding 2–5x speedups over interpretation for compute-intensive loops.[22]
The JVM supports adaptive optimization, allowing the JIT to refine code dynamically while handling changes in program assumptions through deoptimization. If class loading or other events invalidate optimizations (e.g., a previously monomorphic call site becomes polymorphic), the runtime deoptimizes by discarding native code and reverting frames to interpreted or lower-tier states, preserving correctness. Techniques like escape analysis further enhance efficiency by examining object lifetimes; if an object does not escape its creating method or thread, the JIT can eliminate heap allocations, promoting stack-based storage or even scalar replacement to avoid object creation altogether. This analysis, integrated into C2 since Java 6, reduces garbage collection pressure and improves locality.[23][21]
Performance benchmarks illustrate the impact of JIT compilation, particularly after warmup when most code has transitioned to native execution. In the SPECjvm2008 suite, which evaluates JVM throughput across graphics, compression, and scientific workloads, HotSpot achieves scores up to 80–90% of native C equivalents post-compilation, compared to 10–20% during initial interpretation. For instance, the 202.scimark benchmark sees execution time drop by over 10x after JIT warmup, highlighting how tiered compilation mitigates startup overhead while approaching hardware limits for sustained runs.[24]
Garbage Collection Strategies
The Java Virtual Machine (JVM) heap is structured into generations to optimize garbage collection efficiency, with the young generation consisting of an Eden space for new object allocations and two survivor spaces for objects that survive initial collections, while the old generation holds long-lived objects.[25] Class metadata, including method data and constant pools, is managed in the Metaspace, a native memory area introduced in Java 8 to replace the permanent generation and reduce OutOfMemoryError risks.[26] This generational approach assumes most objects die young, allowing frequent minor collections in the young generation and less frequent major collections involving the old generation.[25] JVM garbage collectors employ tracing algorithms rather than reference counting, which avoids pitfalls like circular references that can prevent reclamation of unreachable cycles.[27] Common techniques include mark-sweep-compact, where reachable objects are marked, unreferenced space is swept, and surviving objects are compacted to eliminate fragmentation; and copying, used in the young generation to move live objects from Eden to a survivor space, doubling effective space utilization at the cost of extra copying overhead.[28] These algorithms balance throughput and latency, with compaction ensuring contiguous free space for large allocations.[29] The Serial collector is a single-threaded algorithm suitable for small applications or single-processor environments, performing stop-the-world collections sequentially for both minor and major phases to minimize memory footprint.[30] In contrast, the Parallel collector uses multiple threads for young generation collections to maximize throughput in multi-processor systems, while employing a multi-threaded mark-sweep-compact for the old generation.[30] The Concurrent Mark Sweep (CMS) collector, deprecated in Java 9 and removed in JDK 14, focuses on low-pause times by running most old generation work concurrently with application threads, though it risks fragmentation without compaction.[30] The Garbage-First (G1) collector, the default since Java 9, divides the heap into equal-sized regions and prioritizes collecting those with the most garbage, enabling predictable pause times under tunable goals like maximum pause duration.[30] For ultra-low latency, the Z Garbage Collector (ZGC), introduced in Java 11, performs concurrent mark, relocate, and remap phases using colored pointers to track object movements without halting the application, scaling to terabyte heaps with sub-millisecond pauses. Generational support, added via JEP 439 in JDK 21 and made default via JEP 474 in JDK 23 (September 2024), separates young and old collections for better small-object performance. As of October 2025, ZGC's pointer coloring has evolved to support more nuanced metadata for virtual threads and concurrent operations, building on colored pointers for load/store barriers and maintaining sub-1 ms pause guarantees.[31][32][33][34] Similarly, Shenandoah, available since Java 12, achieves low-pause concurrent collections through region-based management and Brooks pointers for forwarding, emphasizing throughput with minimal latency impact.[35] Tuning involves ergonomics, where the JVM automatically sizes the heap based on available memory, setting initial (-Xms) and maximum (-Xmx) sizes to avoid frequent resizing, and ratios like -XX:NewRatio to proportion young and old generations.[26] Key metrics include throughput (percentage of time not spent in GC, targeted at 95% or higher) and pause times (STW durations, ideally under 200ms for G1), monitored via GC logs enabled with flags like -XX:+PrintGCDetails.[36] GC interacts with just-in-time (JIT) compilation by optimizing allocation sites in compiled code to reduce pressure on young generation collections.[26]Security Features
Bytecode Verifier
The bytecode verifier is a critical security component of the Java Virtual Machine (JVM) that performs static analysis on loaded class files to ensure they conform to the JVM's operational constraints and safety invariants before any code execution occurs. This process, integrated into the linking phase following class loading, examines the bytecode to detect potential violations that could compromise the JVM's integrity, such as type mismatches or malformed structures. By rejecting non-compliant class files, the verifier helps maintain the JVM's promise of a secure execution environment, particularly for untrusted code from external sources. The verification process unfolds in distinct phases, beginning with structural checks on the class file format. These ensure the file adheres to the prescribed layout, including valid magic numbers, constant pool integrity, field and method descriptors, and attribute correctness, while also verifying limits like maximum heap size references and code array bounds. Next, data-flow analysis simulates operand stack and local variable states across all possible execution paths in each method's code attribute, inferring types to confirm operational validity. Finally, linkage verification resolves symbolic references, ensuring that class, field, and method names correspond to accessible and compatible entities in the JVM's namespace. Central to the verifier's role is enforcing type safety through rigorous checks on bytecode operations. It prohibits invalid casts by validating that reference types in checkcast, instanceof, and invoke instructions are compatible, preventing runtime type errors. Array-related safeguards include confirming that array creation uses non-negative lengths and that store operations (e.g., aastore, iastore) match expected element types, thereby avoiding type confusion in array accesses. Opcode misuse is detected and rejected; for instance, applying the iadd instruction to long values is invalid, as it expects two int operands, ensuring arithmetic operations align with operand types like int for iadd versus long for ladd. These checks collectively mitigate risks of type confusion and contribute to preventing exploits such as invalid memory accesses that could lead to buffer overflows. To optimize verification, particularly for complex control flows, class files compiled under Java SE 6 and later incorporate StackMapTable attributes within Code attributes. These tables map verification types for local variables and the operand stack at key offsets, such as the start of basic blocks or targets of branches and exceptions, enabling the verifier to perform type checking at merge points without exhaustive inference across the entire method. This approach reduces computational overhead compared to earlier type-inference-based verification, improving startup times and efficiency in just-in-time compilation scenarios. Upon detecting any violation, the verifier halts processing and throws a VerifyError, a subclass of LinkageError, aborting class initialization and execution to safeguard the JVM. This mechanism is essential for blocking malicious or corrupted bytecode that might otherwise cause undefined behavior. However, as a static analyzer, the verifier has inherent limitations: it cannot anticipate runtime conditions, such as null references leading to NullPointerException or dynamic array index overflows, which require separate runtime checks.Sandboxing and Permissions
The Java Virtual Machine (JVM) employs a sandboxing mechanism to isolate untrusted code, primarily through the Security Manager, which acts as a gatekeeper for sensitive operations such as file I/O and network access.[37] This class, java.lang.SecurityManager, is customizable and enforces a runtime security policy by intercepting potentially hazardous actions before they occur, ensuring that code from untrusted sources cannot compromise the host system.[38] The Security Manager integrates with the bytecode verifier, which performs static checks as a prerequisite to confirm code integrity prior to execution.[39] Permissions in the JVM are managed via policy files that define granular access rights based on the code's origin, such as its signers or codebase URL.[40] These files use entries like java.io.FilePermission to grant or deny specific operations—for instance, allowing read access to a directory while prohibiting writes.[40] The default policy implementation reads from configuration files specified in the security properties, enabling administrators to tailor protections for different deployment scenarios without altering application code.[40] Historically, the applet sandbox imposed strict restrictions on code loaded from remote sources in web browsers, preventing local file system access, network connections to non-origin hosts, and other system interactions to mitigate risks from malicious applets.[41] This model, influential in early Java deployments, relied on unsigned applets being confined to a minimal privilege set, with signed applets requiring user approval for elevated permissions; however, it has been deprecated since Java 9 due to the decline of applet support.[41] In modern Java versions, the Security Manager was deprecated in Java 17 (2021) and permanently disabled in JDK 24, shifting focus toward more robust alternatives like the Java Platform Module System (JPMS) introduced in Java 9.[42][43] JPMS enhances security through strong encapsulation, allowing modules to explicitly control internal access and reduce unintended exposures via reflection or linkage.[44] For exploitation mitigations as of 2025, GraalVM native images provide ahead-of-time compilation with static analysis to eliminate runtime reflection vulnerabilities and minimize the attack surface, while supporting integration with container environments for isolated deployments.[45] In JDK 25 (September 2025), the Java platform introduced the Key Derivation Function (KDF) API as a standard feature for deriving keys from secret material, supporting algorithms like PBKDF2 and HKDF. Additionally, a preview API for PEM encodings of cryptographic objects, such as keys and certificates, was added to facilitate handling of PEM-formatted data natively.[46][47]Implementations and Variants
Oracle HotSpot JVM
The Oracle HotSpot JVM originated from technology developed by Longview Technologies, a startup founded by former Sun Microsystems researchers Urs Hölzle and Lars Bak, which Sun acquired in February 1997 to enhance Java performance through advanced just-in-time (JIT) compilation techniques.[48] This acquisition integrated Longview's innovations, including an "exact" virtual machine design that utilized type maps to enable precise garbage collection by tracking object types and locations without conservative scanning approximations.[49] HotSpot was initially released as an optional add-on for Java Development Kit (JDK) 1.2 in 1999 and became the default JVM implementation in JDK 1.3, released in May 2000, marking a shift toward adaptive optimization for broader adoption in enterprise and desktop applications.[50] Key components of HotSpot include its tiered compilation system, which progresses code execution from interpretation to lightweight client compilation (C1) and then to aggressive server-side optimization (C2), enabling efficient warm-up and peak performance; this feature has been enabled by default in the server VM since Java 7.[51] Additionally, HotSpot integrates Java Mission Control (JMC), a comprehensive monitoring and diagnostics toolset for profiling JVM behavior, analyzing heap usage, and troubleshooting performance issues in production environments without significant overhead.[52] For garbage collection, HotSpot supports multiple strategies configurable via command-line options, such as the parallel collector for throughput-oriented applications, with its type map-based oop (ordinary object pointer) system facilitating accurate root scanning.[53] HotSpot employs several runtime optimizations to minimize overhead and maximize efficiency, including escape analysis, which determines if objects escape method boundaries to enable stack allocation and eliminate unnecessary allocations; biased locking, which optimizes uncontended synchronization by assuming a single thread's access pattern to reduce lock acquisition costs; and string deduplication, introduced in Java 8 update 20, which identifies and shares identical string instances in the heap to reduce memory usage in string-heavy applications.[54][55][56] These features contribute to HotSpot's reputation for high performance in diverse workloads, from servers to desktops. The HotSpot codebase is licensed under the GNU General Public License version 2 (GPLv2) with the Classpath Exception, allowing proprietary applications to link against it without requiring source disclosure.[57] Oracle provides both a commercial Oracle JDK distribution, which includes HotSpot with additional proprietary tools and support under a subscription model for production use in recent versions, and free OpenJDK builds that form the open-source foundation, enabling community contributions while maintaining compatibility.[58] As of 2025, HotSpot continues to evolve through integration with Project Leyden, which previews ahead-of-time (AOT) compilation capabilities in JDK 25 to address startup time and peak performance challenges by generating native executables and optimizing class loading, building on existing features like application class-data sharing.[59][60]Open-Source Implementations
OpenJDK, launched by Sun Microsystems in 2006, stands as the primary open-source reference implementation of the Java Platform, Standard Edition (Java SE) since version 7. It provides a complete, GPL-licensed codebase that underpins the majority of Java distributions worldwide, ensuring compatibility and fostering community contributions through its collaborative development model. Major vendors build upon OpenJDK, such as Eclipse Adoptium's Temurin binaries, which offer TCK-certified, prebuilt OpenJDK releases for broad platform support including x86, ARM, and others.[61] Similarly, Amazon Corretto delivers a no-cost, production-ready OpenJDK variant with long-term support, optimized for AWS environments and used extensively in enterprise services.[62] Historically, early open-source JVM efforts included Kaffe, a GPL-licensed virtual machine initiated in the late 1990s to implement Java specifications independently, though it was discontinued by 2008 due to maintenance challenges. Another notable project, Apache Harmony, emerged in 2004 as an Apache Software Foundation initiative to create a fully open-source Java SE stack; it was discontinued in 2011, with significant portions of its class libraries and tools integrated into OpenJDK to enhance its completeness. Prominent alternatives to the standard OpenJDK HotSpot include IBM's OpenJ9, derived from the proprietary J9 JVM and open-sourced in 2017 under the Eclipse Foundation. OpenJ9 emphasizes a low memory footprint—often 30-50% smaller than HotSpot in containerized scenarios—through features like ahead-of-time (AOT) compilation, which precompiles bytecode to native code for faster execution without runtime JIT overhead. Its shared classes cache further accelerates startup by persisting loaded classes, AOT data, and JIT profiles across JVM instances, reducing redundant loading and enabling sub-second warm-ups in microservices. Azul Systems' Zing JVM, rebranded as part of Azul Platform Prime, targets platform-as-a-service (PaaS) and cloud workloads with its Falcon JIT compiler, an LLVM-based optimizer that generates highly efficient machine code for sustained low-latency performance. Falcon minimizes deoptimizations and warmup times compared to traditional JITs, supporting high-throughput applications on resource-constrained hardware.[63] GraalVM extends the JVM ecosystem with polyglot capabilities, allowing seamless execution of languages like JavaScript, Python, and Ruby alongside Java via its Truffle framework, which provides AST-based interpretation and partial evaluation for dynamic language optimization.[64] For native compilation, GraalVM employs Native Image (evolved from SubstrateVM), an AOT tool that ahead-of-time compiles Java applications into standalone executables with reduced startup times and memory usage, ideal for serverless and edge computing. As of 2025, GraalVM's adoption has surged in cloud-native environments, driven by its ability to produce lightweight images that cut deployment costs by up to 50% in Kubernetes clusters, with GraalVM 25 aligning fully with Java SE 25 features. OpenJDK 25, released in September 2025, upholds TCK compliance across these implementations, incorporating enhancements like stable values while serving as the foundation for ongoing open-source innovation.[9]Supported Languages and Ecosystems
JVM-Based Programming Languages
The Java Virtual Machine (JVM) supports a diverse ecosystem of programming languages that compile to its bytecode, enabling developers to leverage the JVM's performance, libraries, and runtime features while adopting paradigms beyond Java's object-oriented model. These languages span static and dynamic typing, functional programming, and scripting, fostering polyglot applications where multiple languages coexist seamlessly. Among statically typed languages, Scala, released in 2004, combines object-oriented and functional programming on the JVM, emphasizing concise syntax and higher-order functions for scalable software development.[65] Kotlin, first publicly released in 2011, prioritizes conciseness and null safety, reducing boilerplate code compared to Java while maintaining full compatibility with existing JVM ecosystems.[66] Ceylon, introduced by Red Hat as a modular, statically typed language focused on readability and type safety, was discontinued in 2017 after its final release.[67] Dynamic languages on the JVM include Groovy, launched in 2003, which serves as an agile scripting language inspired by Python, Ruby, and Smalltalk, facilitating rapid prototyping and integration with Java code.[68] Clojure, a dialect of Lisp hosted on the JVM since 2007, emphasizes immutability, functional programming, and concurrent data structures to handle complex, stateful applications efficiently.[69] JRuby implements the Ruby language on the JVM, providing high-performance execution of Ruby code with direct access to Java's threading and garbage collection.[70] Polyglot programming is enhanced by theinvokedynamic instruction introduced in Java 7, which enables efficient dynamic method invocation and custom linkage for non-Java languages, reducing overhead in mixed-language environments.[19]
Adoption of these languages has grown in specialized domains; Kotlin became an official language for Android development in 2017, accelerating its use in mobile applications due to seamless integration with Android APIs.[71] Scala powers big data frameworks like Apache Spark, where its functional features enable concise expressions for distributed data processing.
Despite these advantages, JVM-based languages face challenges in interoperability with vast Java libraries, often requiring adaptations for type mismatches or idiomatic differences that can complicate code sharing. Performance tuning for non-Java idioms, such as functional constructs or dynamic dispatch, demands careful optimization to match native Java efficiency; however, as of 2025, virtual threads introduced in Java 21 have improved concurrency handling in these languages by enabling lightweight, scalable threading models that align better with diverse paradigms.[72][73]
Interoperability Standards
The Java Virtual Machine (JVM) supports interoperability through standardized protocols and APIs that facilitate interaction between Java bytecode and native code, as well as between different JVM-based languages and enterprise systems. These standards enable developers to integrate legacy native libraries, mix polyglot codebases, and build modular applications without compromising the JVM's portability or security model. Key mechanisms include native interfaces for low-level access and modular frameworks for dynamic composition, evolving from early bindings like JNI to modern, safer alternatives. The Java Native Interface (JNI), introduced in JDK 1.1, provides a programming interface for writing native methods in languages like C or C++ that can be called from Java code running in the JVM, allowing access to platform-specific features such as hardware acceleration or system APIs.[74] JNI functions, such asGetFieldID for retrieving field identifiers in Java objects, enable bidirectional data exchange but require careful management to avoid issues like memory leaks from unhandled native resource disposal or segmentation faults due to pointer misuse. Despite its power, JNI's complexity— involving manual memory mapping and exception handling—has led to the development of higher-level alternatives that reduce boilerplate while maintaining compatibility with the JVM.
Java Native Access (JNA) serves as a library-based alternative to JNI, allowing Java applications to invoke native shared libraries directly through pure Java code without compiling or linking custom native wrappers.[75] By dynamically loading libraries at runtime and mapping native functions to Java interfaces via annotations, JNA simplifies foreign calls, such as accessing C libraries for file I/O, and avoids JNI's recompilation needs for each platform.[76] However, it still inherits some JNI limitations, like potential performance overhead from reflection-based dispatching.
Project Panama addresses these challenges with the Foreign Function & Memory API (FFM), a standard feature finalized in Java 22 (JEP 454) that enables safe, efficient interoperation with native code by treating foreign functions as method handles and off-heap memory as scoped segments, effectively modernizing and potentially replacing JNI.[77] This API, built on vector API extensions, supports zero-copy data transfer and automatic memory management through arenas, reducing risks like leaks while improving performance for high-throughput scenarios such as numerical computing. By 2025, FFM has stabilized in subsequent JDK releases, integrating tools like jextract for generating bindings from C headers directly into Java modules.[77]
The Java Platform Module System (JPMS), introduced in Java 9, enhances interoperability among JVM languages by enforcing module boundaries that allow explicit exports and requires for mixing code from Java, Kotlin, or Scala in a single application, promoting strong encapsulation and reducing classpath conflicts.[78] Modules declare dependencies via module-info.java, enabling seamless integration of polyglot libraries while the JVM resolves them at runtime without altering bytecode semantics.[79]
For dynamic plugin architectures, the OSGi framework standardizes modular deployment of Java components as bundles, supporting hot-swapping and service discovery to enable runtime interoperability in enterprise environments like application servers.[80] OSGi's service registry allows bundles to publish and consume interfaces dynamically, facilitating plugin ecosystems without full restarts.
Eclipse MicroProfile, a set of specifications for cloud-native Java microservices, promotes enterprise interoperability through APIs like Reactive Streams Operators, which standardize asynchronous data processing across JVM languages and systems.[81] MicroProfile 7.1 was released in June 2025, updating the Telemetry and OpenAPI specifications.[82]
Deployment Environments
Web Browser Integration
Java applets provided an early mechanism for executing JVM bytecode directly within web browsers through a plugin-based architecture, introduced in 1995 alongside the initial release of Java. This approach allowed developers to embed interactive, platform-independent applications in HTML pages using the<applet> tag, leveraging the JVM's sandbox for security isolation.[83] However, applets faced increasing scrutiny due to persistent security vulnerabilities in the Java Plug-in, including exploits that bypassed sandbox restrictions and enabled arbitrary code execution. As a result, Oracle deprecated applet support in JDK 9 in 2017, with full removal of the Applet API targeted for JDK 26 in 2026, though runtime support lingered in Java SE 8 updates until March 2019 with updates up to JDK 8u202.[84][85]
Java Web Start emerged as a successor to applets for deploying richer, desktop-like applications via the Java Network Launch Protocol (JNLP), enabling seamless downloads and execution of JAR files without browser plugins after initial launch.[86] Introduced in 2001, it supported features like automatic updates and offline caching, making it suitable for client-side web-integrated apps that required fuller JVM capabilities.[87] Oracle deprecated Java Web Start in JDK 9 alongside other deployment technologies, removing it entirely in JDK 11 in 2018, as the rise of modular Java applications favored self-contained runtime images created with tools like jlink and jpackage for more flexible distribution.[88]
To address the plugin deprecation, JavaScript bridges like TeaVM and Google Web Toolkit (GWT) enable client-side execution by transpiling JVM bytecode or source code to JavaScript, allowing Java applications to run natively in browsers without native plugins. TeaVM, an ahead-of-time compiler, directly translates Java bytecode to optimized JavaScript or WebAssembly, supporting interoperability through JavaScript object wrappers for seamless integration with browser APIs.[89] In contrast, GWT compiles Java source code to JavaScript and provides JavaScript Native Interface (JSNI) for bidirectional bridges, permitting Java methods to invoke handwritten JavaScript and vice versa for enhanced web functionality.[90] These tools facilitate the migration of legacy Java code to modern web environments, preserving JVM semantics while leveraging the browser's rendering engine.[91]
As of 2025, modern alternatives like CheerpJ offer a full JVM implementation in JavaScript and WebAssembly, enabling the execution of unmodified Java bytecode—including applets and Web Start applications—directly in browsers for legacy migration without recompilation.[92] CheerpJ 4.0, released in April 2025, supports Java 11 with JNI compatibility, while version 4.1 (May 2025) previews Java 17 features; it compiles a subset of the OpenJDK runtime to WebAssembly for efficient performance in environments like Chrome and Firefox.[93][94] This approach addresses gaps in traditional transpilation by emulating the complete JVM stack, including garbage collection and threading, while adhering to browser security models.
The decline of browser plugin support severely limited these integration methods, with Google Chrome removing NPAPI plugin compatibility—including for the Java Plug-in—in version 45 in September 2015, citing security risks and performance issues.[95] Similarly, Mozilla Firefox version 52, released in March 2017, completely blocked NPAPI plugins like Java, redirecting users to alternatives amid widespread vulnerabilities.[96] These changes prompted a shift toward server-side JVM deployments and hybrid client-server architectures, where browser integration focuses on API calls rather than direct bytecode execution.[83]
