Java virtual machine
Designer | Sun Microsystems |
---|---|
Bits | 32-bit |
Introduced | 1994 |
Version | 20.0.1[1] |
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
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 in the implementation of this specification of the Java virtual machine.<"-Xmx 2048m-XX;2Gb=250m">Bill Venners, Inside the Java Virtual Machine Archived 2021-01-25 at the Wayback Machine Chapter 5</ref>
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.Cite error: A <ref>
tag is missing the closing </ref>
(see the help page).
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%.[2]
JavaScript JVMs and interpreters
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.[3]
Transpilation to JavaScript
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,[4] the compiler contained in Dragome Web SDK,[5] Bck2Brwsr,[6] and j2js-compiler.[7]
Leading transpilers from JVM languages to JavaScript include the Java-to-JavaScript transpiler contained in Google Web Toolkit, Clojurescript (Clojure), GrooScript (Apache Groovy), Scala.js (Scala) and others.[8]
See also
- Common Language Runtime
- List of Java virtual machines
- List of JVM languages
- Comparison of Java virtual machines
- Comparison of application virtualization software
- Automated exception handling
- Java performance
- Java processor
- K virtual machine (KVM)
References
- ^ yan (2023-06-24). "JDK 20 Release Notes". Oracle Corporation. Archived from the original on 2021-07-09. Retrieved 2023-06-24.
- ^ "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
- ^ "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