Java Virtual Machine

from Wikipedia, the free encyclopedia
Java logo

The Java Virtual Machine (abbreviated to Java VM or JVM ) is the part of the Java Runtime Environment (JRE) for Java programs that is responsible for executing the Java bytecode . Normally, each started Java program is executed in its own virtual machine (VM). The other part of the Java runtime environment is the Java class libraries .

The JVM serves as an interface to the machine and the operating system and is available for most platforms (e.g. Linux , macOS , Palm OS , Solaris , Windows , z / OS , etc.). The JVM is mostly written in the programming languages C or C ++ .

The components of the JVM are

  • the class loader ( classloader and resolver ),
  • memory management and garbage collection ( garbage collection ), and the
  • Execution engine .

Working principle

Bytecode generated by the Java compiler ( platform-independent ) is executed by a platform-dependent Java virtual machine. The generated bytecode files (file extension “.class”) are translated into the local machine language during runtime . The virtual machine works like an interpreter , but is much faster, since z. B. no more syntax checks have to be made.

Security benefits

In addition to the platform independence of the bytecode, the Java Virtual Machine also offers increased security. It monitors the execution of the program at runtime, thus preventing, for example, buffer overflows , which lead to unpredictable behavior such as the program crashing. In the special case of Java, this monitoring is very simple, since Java does not directly support pointers (only implicitly).

Optimization procedure

The execution speed (English performance ) of Java programs to increase, most Java VMs place called JIT compiler on (JITC) immediately during program execution, the bytecode " J ust I n T " Just in time "ime" (, or "Just at the right time") permanently translate into machine code . A further development of this approach is the hotspot optimizer from Sun , which works with dynamic optimization.

Dynamic optimization

Often at the time of compilation not known which specific input a software must process. As a result, the software has to deal with all types of input. The input is therefore saved in variables . After starting the program, however, many variables are no longer changed. As a result, these are constants from a point in time shortly after the start. If the software for the system architecture is only compiled after this point in time (this is the case with Java Hotspot), then these constants can be taken into account. Certain branches that are only dependent on such “half-constants” are then forever unique and therefore do not pose a risk of incorrect branch prediction . Such a program code can therefore run faster than code compiled at an earlier point in time.

Implementations in hardware

Hardware versions are Java processors , microprocessors that use Java bytecode as machine language. They could not prevail against the rapid increase in the performance of standard PCs and JVMs.

Foreclosure of the threads

The Java VM isolates the processes running in it from the operating system (green threads). By default, it maps Java threads to threads of the operating system. Thread management is only carried out by the Java VM in exceptional cases. This means that it is also possible to offer a Java VM with full functionality on an operating system that does not support multithreading.

The Java VM always has full and standard-compliant sovereignty over the Java threads, i. H. the programmer does not need to consider the operating system-specific multi-threading / tasking / processing properties and can always rely on the JRE . The disadvantage is that problems emanating from one thread are assigned to the entire process by the operating system. Common operating systems (such as Linux, Windows) allow control of these "native" threads, if necessary, using third-party software, such as the VisualVM supplied with the JDK . However, standard tools such as the Windows Task Manager do not display system threads.

JVM languages

Besides Java, there are also other languages ​​that can be used as programming languages ​​for JVM programs. The following languages, among others, can run on a JVM:

  • Clojure , a Lisp dialect,
  • Ceylon ,
  • Concurnas, a multi-paradigm programming language for concurrent , distributed, and reactive applications, with Python-like syntax, support for GPU computing, and off-heap memory management.
  • Erjang, an Erlang dialect for the JVM,
  • Free Pascal , which also supports a large part of the Object Pascal constructs under the JVM ,
  • Groovy , a very Java-like, statically and dynamically typed programming language
  • JRuby , an almost Ruby- compatible implementation,
  • Jython (formerly: JPython), a pure Java implementation of the Python programming language,
  • Nice , complements Java with parametric types, anonymous functions, multi-methods, tuples and optional parameters.
  • Scala , a language that combines features of Java with functional programming,
  • Kotlin , a language introduced by JetBrains in 2011

There are also a number of scripting languages that can be called from Java. This includes JavaScript (now standardized as ECMAScript) with the "Rhino" interpreter (a Mozilla project) up to version 7 or with the "Rhino" interpreter from version 8. JavaFX also contained a scripting function in versions 1.x Language mainly for graphic elements, but from version 2.0 it is implemented in pure Java.

Compilation in JavaScript

With the continuous improvement in JavaScript execution speed, combined with the increased use of mobile devices whose web browsers do not support plugins, efforts are being made to target these users by compiling in JavaScript. It is possible to compile either the source code or JVM bytecode to JavaScript.

The compilation of the JVM bytecode, which is universal for all JVM languages, makes it possible to build on the existing compiler of the language and to create bytecode. The main JVM bytecodes for JavaScript compilers are TeaVM, the compiler in the Dragome Web SDK, Bck2Brwsr, and j2js compiler.

Leading JVM language to JavaScript compilers include the Java to JavaScript compiler in Google Web Toolkit , Clojurescript (Clojure) , GrooScript (Apache Groovy) , Scala.js (Scala), and others.

See also

  • Dalvik - a JVM developed by Google for the Android platform
  • HotSpot - the most widely used JVM from Oracle
  • IBM J9
  • JRockit ( BEA Systems , now Oracle )
  • Kaffe - a free GPL JVM implementation
  • Persistent Reusable Java Virtual Machine (PRJVM) - a form of the JVM modified by IBM
  • PreonVM, virtual machine for resource-limited embedded systems
  • SableVM - free LGPL JVM implementation

Web links

Commons : Java Virtual Machine  - collection of images, videos and audio files

Individual evidence

  1. Concurnas: the New Language on the JVM for Concurrent and GPU computing. In: InfoQ.com. C4Media Inc., accessed June 25, 2020 .
  2. The Concurnas Programming Language. Concurnas Ltd., accessed June 25, 2020 .
  3. ^ The Nice programming language. Retrieved August 15, 2019 .
  4. ^ Kotlin: First web presence for JetBrains JVM language , it- Republik.de, accessed July 22, 2012
  5. TeaVM: Build Fast, Modern Web Apps in Java. Retrieved October 23, 2019 .
  6. Dragome Web SDK. Retrieved October 23, 2019 .
  7. Bck2Brwsr - APIDesign. Retrieved October 23, 2019 .
  8. GitHub - decatur / j2js-compiler: A Java Bytecode to JavaScript Cross-Compiler. In: GitHub. Retrieved October 23, 2019 .
  9. List of languages ​​that compile to JS jashkenas / coffeescript Wiki GitHub. Github.com, accessed June 26, 2015 .
  10. PreonVM | Preon32 Series Virtual Machine. Retrieved November 10, 2017