FazBrowse Wikipedia Viewer | Main Page |
Search Wikipedia:
|
Viewing: https://en.wikipedia.org/wiki/Java_virtual_machine

Java virtual machine

Contents
    Garbage collectors
    Bytecode verifier
        Secure execution of remote code
    Bytecode interpreter and Just-in-Time compiler
    Java Native Interface

{{cite web |title=JEP 479: Remove the Windows 32-bit x86 Port |url=https://openjdk.org/jeps/479 |website=OpenJDK}}</ref> and JDK 25 (Linux).<ref>{{cite web |title=JEP 503: Remove the 32-bit x86 Port |url=https://openjdk.org/jeps/503 |website=OpenJDK}}</ref>}}"},"introduced":{"wt":"{{Start date and age|1994}}"},"version":{"wt":"{{wikidata|property|preferred|references|edit|Q251|P348|P548=Q2804309}}"},"design":{"wt":""},"type":{"wt":"[[Stack machine|Stack]] and [[Load–store architecture|register–register]]"},"encoding":{"wt":"Variable"},"branching":{"wt":"Compare and branch"},"endianness":{"wt":"[[Endianness#Big-endian|Big]]"},"page size":{"wt":""},"extensions":{"wt":""},"open":{"wt":"Yes"},"registers":{"wt":""},"gpr":{"wt":"Per-method operand stack (up to 65535 operands) plus per-method local variables (up to 65535)"},"fpr":{"wt":""}},"i":0}}]}'>
Java virtual machine
DesignerSun Microsystems
Bits32-bit, 64-bit
Introduced1994;32 years ago (1994)
VersionJava SE 26 As of 2006, changes to the specification to support changes proposed to the class file format (JSR 202) are being done as a maintenance release of JSR 924. The specification for the JVM was published as the blue book, 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

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.

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, 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. 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.

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.

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)

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. Some JVM implementations do not include an interpreter, but consist only of a just-in-time compiler.

Java Native Interface

edit
    "JDK 26".
  1. ↑ Bill Venners, Inside the Java Virtual Machine Archived 2021-01-25 at the Wayback Machine Chapter 5
  2. ↑ Tene, Gil; Iyengar, Balaji; Wolf, Michael (2011). "C4: the continuously concurrent compacting collector" (PDF). ISMM '11: Proceedings of the international symposium on Memory management. doi:10.1145/1993478. ISBN 978-1-45030263-0. Archived (PDF) from the original on 2017-08-09.
  3. ↑ "Chapter 2. The Structure of the Java Virtual Machine". Archived from the original on 2021-09-15. Retrieved 2021-09-15.
  4. ↑ "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.
  5. ↑ "The Verification process". The Java Virtual Machine Specification. Sun Microsystems. 1999. Archived from the original on 2011-03-21. Retrieved 2009-05-31.
  6. ↑ 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.{{cite book}}: Cite uses deprecated parameter |citeseerx= (help)
  7. ↑ "Historical yearly trends in the usage of client-side programming languages, June 2015". W3techs.com. Retrieved 2015-06-26.
  8. ↑ "Dragome Web SDK". Dragome.com. Archived from the original on 2015-08-01. Retrieved 2015-06-26.
  9. ↑ "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.

View original on Wikipedia | Back | FazBrowse Home