All Topics  
Java Virtual Machine

 

   Email Print
   Bookmark   Link






 

Java Virtual Machine



 
 
A Java Virtual Machine (JVM) is a set of computer software programs and data structures which use a virtual machine
Virtual machine

In computer science, a virtual machine is a software implementation of a machine that executes programs like a real machine.Definitions...
 model for the execution of other computer programs and scripts
Scripting language

A scripting language, script language or extension language, is a programming language that allows some control of a single or many Application software....
. The model used by a JVM accepts a form of computer intermediate language
Intermediate language

In computer science, an intermediate language is the language of an abstract machine designed to aid in the analysis of computer programs. The term comes from their use in compilers, where a compiler first translates the source code of a program into a form more suitable for code-improving transformations, as an intermediate step before gener...
 commonly referred to as Java bytecode
Java bytecode

Java bytecode is the form of instructions that the Java virtual machine executes. Each bytecode instruction or opcode is one byte in length; however, not all of the possible 256 instructions are used....
. This language conceptually represents the instruction set of a stack-oriented
Stack-oriented programming language

A stack-oriented programming language is one that relies on a stack machine model for passing parameters. Several programming languages fit this description, notably Forth and PostScript, and also many Assembly languages ....
, capability architecture. As of 2006, there are an estimated 4 billion JVM-enabled devices worldwide.

Java Virtual Machines operate on Java bytecode, which is normally (but not necessarily) generated from Java
Java (programming language)

Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java ....
 source code; a JVM can also be used to implement programming languages other than Java.






Discussion
Ask a question about 'Java Virtual Machine'
Start a new discussion about 'Java Virtual Machine'
Answer questions from other users
Full Discussion Forum



Encyclopedia


A Java Virtual Machine (JVM) is a set of computer software programs and data structures which use a virtual machine
Virtual machine

In computer science, a virtual machine is a software implementation of a machine that executes programs like a real machine.Definitions...
 model for the execution of other computer programs and scripts
Scripting language

A scripting language, script language or extension language, is a programming language that allows some control of a single or many Application software....
. The model used by a JVM accepts a form of computer intermediate language
Intermediate language

In computer science, an intermediate language is the language of an abstract machine designed to aid in the analysis of computer programs. The term comes from their use in compilers, where a compiler first translates the source code of a program into a form more suitable for code-improving transformations, as an intermediate step before gener...
 commonly referred to as Java bytecode
Java bytecode

Java bytecode is the form of instructions that the Java virtual machine executes. Each bytecode instruction or opcode is one byte in length; however, not all of the possible 256 instructions are used....
. This language conceptually represents the instruction set of a stack-oriented
Stack-oriented programming language

A stack-oriented programming language is one that relies on a stack machine model for passing parameters. Several programming languages fit this description, notably Forth and PostScript, and also many Assembly languages ....
, capability architecture. As of 2006, there are an estimated 4 billion JVM-enabled devices worldwide.

Java Virtual Machines operate on Java bytecode, which is normally (but not necessarily) generated from Java
Java (programming language)

Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java ....
 source code; a JVM can also be used to implement programming languages other than Java. For example, Ada
Ada (programming language)

Ada is a structured programming, statically typed, Imperative programming, and Object-oriented programming high-level language computer programming programming language, extended from Pascal and other languages....
 source code can be compiled to Java bytecode, which may then be executed by a JVM. JVMs can also be released by other companies besides Sun (the developer of Java) — JVMs using the "Java" trademark may be developed by other companies as long as they adhere to the JVM specification published by Sun (and related contractual obligations).

The JVM is a crucial component of the Java Platform. Because JVMs are available for many hardware and software platforms
Platform (computing)

In computing, a platform describes some sort of hardware architecture or software framework , that allows Computer software to run. Typical platforms include a computer's Computer architecture, operating system, programming languages and related runtime libraries or graphical user interface....
, Java can be both middleware
Middleware

Middleware is computer software that connects software components or applications. The software consists of a set of enabling services that allow multiple processes running on one or more machines to interact across a network....
 and a platform in its own right — hence the trademark write once, run anywhere
Write once, run anywhere

"Write once, run anywhere" , or sometimes Write once, run everywhere , is a slogan created by Sun Microsystems to illustrate the cross-platform benefits of the Java ....
. The use of the same bytecode for all platforms allows Java to be described as "compile once, run anywhere", as opposed to "write once, compile anywhere", which describes cross-platform compiled language
Compiled language

A compiled language is a programming language whose programming language implementations are typically compilers , and not interpreter s .The term is somewhat vague; in principle any language can be implemented with a compiler or with an interpreter....
s. The JVM also enables such unique features as Automated Exception Handling
Automated Exception Handling

Automated Exception Handling is a computing term referring to the computerized handling of errors. Runtime engines such as those for the Java language or Microsoft .Net lend themselves to an automated mode of exception or error handling....
 which provides 'root-cause' debugging information for every software error (exception
Exception handling

Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions - special conditions that change the normal flow of execution....
) independent of the source code.

The JVM is distributed along with a set of standard class libraries which implement the Java API
Application programming interface

An application programming interface is a set of subroutine, data structures, class and/or Protocol provided by library and/or operating system Service s in order to support the building of applications....
 (Application Programming Interface). The virtual machine and API have to be consistent with each other and are therefore bundled together as the Java Runtime Environment.

Execution environment


Programs intended to run on a JVM must be compiled into a standardized portable binary format, which typically comes in the form of .class
Class (file format)

In the Java , source files are compiled into class files which have a .class extension. Since Java is a platform-independent language, source code is compiled into an output file known as Byte-code, which it stores in a .class file....
 files. A program may consist of many classes in different files. For easier distribution of large programs, multiple class files may be packaged together in a .jar
JAR (file format)

In computing, a JAR file aggregates many files into one. Software developers generally use .jar files to distribute Java platform class and associated metadata....
 file (short for Java archive).

The JVM runtime
Runtime

In computer science, runtime or run time describes the operation of a computer program, the duration of its execution, from beginning to termination ....
 executes .class or .jar files, emulating the JVM instruction set
Instruction set

An instruction set is a list of all the instruction , and all their variations, that a processor can execute.Instructions include:* Arithmetic such as add and subtract...
 by interpreting
Interpreter (computing)

In computer science, an interpreter normally means a computer program that execution , i.e. performs, instructions written in a programming language....
 it, or using a just-in-time compiler
Just-in-time compilation

In computing, just-in-time compilation , also known as dynamic translation, is a technique for improving the runtime performance of a computer program....
 (JIT) such as Sun's HotSpot. JIT compiling, not interpreting, is used in most JVMs today to achieve greater speed. Ahead-of-time compilers
AOT compiler

An Ahead-of-Time compiler is a compiler that implements Ahead of Time Compilation. This refers to the act of compiling an intermediate language, such as Java bytecode, .NET Common Intermediate Language , or IBM System/38 or IBM System i "Technology Independent Machine Interface" code, into a system-dependent binary....
 that enable the developer to precompile class files into native code for a particular platform also exist.

Like most virtual machines, the Java Virtual Machine has a stack
Stack machine

In computer science, a stack machine is a model of computation in which the computer's memory takes the form of one or more stack s. The term also refers to an actual computer implementing or simulating the idealized stack machine....
-based architecture akin to a microcontroller/microprocessor.

The JVM, which is the instance of the JRE (Java Runtime Environment), comes into action when a Java program is executed. When execution is complete, this instance is garbage-collected. JIT is the part of the JVM that is used to speed up the execution time. JIT compiles parts of the byte code that have similar functionality at the same time, and hence reduces the amount of time needed for compilation.

Support for dynamic Languages


Although the JVM was primarily aimed at running compiled Java programs, other languages can now run on top of it, such as:
  • Ruby
    Ruby (programming language)

    Ruby is a dynamic programming language, reflection , general purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features....
    , with JRuby
    JRuby

    JRuby is a Java implementation of the Ruby , being developed by the JRuby team.JRuby is free software released under a three-way Common Public License/GNU General Public License/GNU Lesser General Public License license....
  • JavaScript
    JavaScript

    JavaScript is a scripting language widely used for client-side web development. It was the originating Programming language dialect of the ECMAScript standard....
    , with Rhino
    Rhino (JavaScript engine)

    Rhino is an open source JavaScript engine. It is developed entirely in Java and managed by the Mozilla Foundation. The Foundation also provides an implementation of JavaScript in C known as SpiderMonkey ....
  • Python
    Python (programming language)

    Python is a general-purpose high-level programming language. Its design philosophy emphasizes code readability. Python's core syntax and semantics are Minimalism , while the standard library is large and comprehensive....
    , with Jython
    Jython

    Jython, successor of JPython, is an implementation of the Python written in Java ....
  • Groovy
  • Scala
  • Clojure
    Clojure

    Clojure is a modern dialect of the Lisp programming language. It is a general-purpose language sporting interactive development, and it encourages a functional programming style that enables simplified Thread programming....


The JVM has currently no built-in support for Dynamically typed languages
Type system

In computer science, a type system may be defined as "a tractable syntactic method for proving the absence of certain program behaviors by classifying phrases according to the kinds of values they compute."....
: the existing JVM instruction set
Java bytecode

Java bytecode is the form of instructions that the Java virtual machine executes. Each bytecode instruction or opcode is one byte in length; however, not all of the possible 256 instructions are used....
 is statically typed
Type system

In computer science, a type system may be defined as "a tractable syntactic method for proving the absence of certain program behaviors by classifying phrases according to the kinds of values they compute."....
. The JVM has a limited support for dynamically modifying existing classes and methods. It currently only works in a debugging environment
Java Platform Debugger Architecture

The Java Platform Debugger Architecture is a collection of APIs to debugging Java code.* Java Debugger Interface - defines a high-level Java language interface which developers can easily use to write remote debugger application tools....
.

Built-in support for dynamic languages is currently planned for Java 7
Java version history

The Java has undergone several changes since Java Development Kit 1.0 as well as numerous additions of classes and packages to the standard library ....
.

Bytecode verifier


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 functions 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 lead 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
Java Virtual Machine heap

The Java Virtual Machine heap is the area of memory used by the Java Virtual Machine for dynamic memory allocation.The heap is split up into "generations":...
, 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 which 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
Branch (computer science)

A branch is a point in a computer program where the flow of control is altered. The term branch is usually used when referring to a program written in machine code or assembly language; in a high-level programming language, branches usually take the form of conditional statements, subroutine calls or GOTO statements....
 can only target an instruction within the same function or method
Subroutine

In computer science, a subroutine or subprogram is a portion of computer code within a larger computer program, which performs a specific task and is relatively independent of the remaining code....
. Because of this, the fact that 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 need to be allocated to the target architecture's registers. In fact, code verification makes the JVM different from a classic stack architecture whose efficient emulation with a JIT compiler is more complicated and typically carried out by a slower interpreter.

Code verification also ensures that arbitrary bit patterns cannot get used as an address. Memory protection
Memory protection

Memory protection is a way to control memory usage on a computer, and is core to virtually every modern operating system. The main purpose of memory protection is to prevent a process running on an operating system from accessing memory beyond that allocated to it....
 is achieved without the need for a Memory management unit
Memory management unit

A memory management unit , sometimes called paged memory management unit , is a computer hardware component responsible for handling accesses to computer memory requested by the central processing unit ....
 (MMU). Thus, JVM is an efficient way of getting memory protection on simple architectures that lack an MMU. This is analogous to managed code
Managed code

Managed code is Source code that executes under the management of a virtual machine, unlike unmanaged code, which is executed directly by the computer's Central processing unit....
 in Microsoft's .NET Common Language Runtime
Common Language Runtime

The Common Language Runtime is a core component of Microsoft .NET Framework initiative. It is Microsoft's implementation of the Common Language Infrastructure standard, which defines an execution environment for program code....
, and conceptually similar to capability architectures such as the Plessey 250, and IBM System/38
System/38

The System/38 was a midrange computer Server Platform manufactured and sold by the IBM Corporation. The system offered a number of innovative features, and was the brainchild of IBM engineer Frank Soltis....
.

Bytecode instructions


The JVM has instruction
Instruction (computer science)

In computer science, an instruction is a single operation of a central processing unit defined by an instruction set architecture. In a broader sense, an "instruction" may be any representation of an element of an executable program, such as a bytecode....
s for the following groups of tasks:

  • Load and store
  • Arithmetic
    Arithmetic

    Arithmetic or arithmetics is the oldest and most elementary branch of mathematics, used by almost everyone, for tasks ranging from simple day-to-day counting to advanced science and business calculations....
  • Type conversion
    Type conversion

    In computer science, type conversion or typecasting refers to changing an entity of one data type into another. This is done to take advantage of certain features of type hierarchies....
  • Object creation and manipulation
    Dynamic memory allocation

    In computer science, dynamic memory allocation is the allocation of computer storage storage for use in a computer program during the runtime of that program....
  • Operand stack management (push / pop)
    Stack (data structure)

    In computer science, a stack is an abstract data type and data structure based on the principle of LIFO . Stacks are used extensively at every level of a modern computer system....
  • Control transfer (branching)
    Branch (computer science)

    A branch is a point in a computer program where the flow of control is altered. The term branch is usually used when referring to a program written in machine code or assembly language; in a high-level programming language, branches usually take the form of conditional statements, subroutine calls or GOTO statements....
  • Method invocation and return
    Subroutine

    In computer science, a subroutine or subprogram is a portion of computer code within a larger computer program, which performs a specific task and is relatively independent of the remaining code....
  • Throwing exceptions
    Exception handling

    Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions - special conditions that change the normal flow of execution....
  • Monitor-based concurrency
    Monitor (synchronization)

    In concurrent programming, a monitor is an Object intended to be used safely by more than one Thread .The defining characteristic of a monitor is that its methods are executed with mutual exclusion....


The aim is binary compatibility. Each particular host operating system
Operating system

An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer....
 needs its own implementation of the JVM and runtime. These JVMs interpret the byte code semantically the same way, but the actual implementation may be different. More complicated than just the emulation of bytecode is compatible and efficient implementation of the Java core API
Java Class Library

The Java Class Library is a set of Library #Dynamic linking that Java applications can call at runtime. Because the Java Platform is not dependent on any specific operating system, applications cannot rely on any of the existing libraries....
 which has to be mapped to each host operating system.

Secure execution of remote code


A virtual machine architecture allows very fine-grained control over the actions that code within the machine is permitted to take. This is designed to allow safe execution of untrusted code from remote sources, a model used by Java applet
Java applet

A Java applet is an applet delivered to the users in the form of Java bytecode. Java applets can run in a Web browser using a Java Virtual Machine , or in Sun Microsystems's AppletViewer, a stand-alone tool for testing applets....
s. Applets run within a VM incorporated into a user's browser, executing code downloaded from a remote HTTP server. The remote code runs in a restricted "sandbox", which is designed to protect the user from misbehaving or malicious code. Publishers can purchase a certificate with which to digitally sign
Digital signature

A digital signature or digital signature scheme is a type of asymmetric key algorithm. For messages sent through an insecure channel, a properly implemented digital signature gives the receiver reason to believe the message was sent by the claimed sender....
 applets as "safe", giving them permission to ask the user to break out of the sandbox and access the local file system and network...

C to bytecode compilers


From the point of view of a compiler
Compiler

A compiler is a computer program that transforms source code written in a programming language into another computer language . The most common reason for wanting to transform source code is to create an executable program....
, the Java Virtual Machine
Java Virtual Machine

A Java Virtual Machine is a set of computer software programs and data structures which use a virtual machine model for the execution of other computer programs and Scripting language....
 is just another processor with an instruction set, Java bytecode
Java bytecode

Java bytecode is the form of instructions that the Java virtual machine executes. Each bytecode instruction or opcode is one byte in length; however, not all of the possible 256 instructions are used....
, for which code can be generated. The JVM was originally designed to execute programs written in the Java language. However, the JVM provides an execution environment in the form of a bytecode instruction set and a runtime system that is general enough that it can be used as the target for compiler
Compiler

A compiler is a computer program that transforms source code written in a programming language into another computer language . The most common reason for wanting to transform source code is to create an executable program....
s of other languages
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
.

Because of its close association with Java the JVM performs the runtime checks mandated by the Java specification. This can make it technically difficult to translate C
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
 code (which is much more lax with regard to runtime checking) to the JVM and expect it to run without issuing any warnings.

It can be easier to translate some language, such as C, to machine language first before converting to Java bytecode. This has been shown to be the case with project and accompanying paper.

Compilers targeting many different languages, including Ada
Ada (programming language)

Ada is a structured programming, statically typed, Imperative programming, and Object-oriented programming high-level language computer programming programming language, extended from Pascal and other languages....
 and COBOL
COBOL

COBOL is one of the oldest programming languages still in active use. Its name is an acronym for COmmon Business-Oriented Language, defining its primary domain in business, finance, and administrative systems for companies and governments....
, have been written.

Licensing


Starting with J2SE
Java Platform, Standard Edition

Java Platform, Standard Edition or Java SE is a widely used Platform for programming in the Java language. It is the Java Platform used to deploy porting Application software for general use....
 5.0, changes to the JVM specification have been developed under the Java Community Process
Java Community Process

The Java Community Process or JCP, established in 1998, is a formalized process that allows interested parties to get involved in the definition of future versions and features of the Java platform....
 as JSR 924. , changes to specification to support changes proposed to the class file format
Class (file format)

In the Java , source files are compiled into class files which have a .class extension. Since Java is a platform-independent language, source code is compiled into an output file known as Byte-code, which it stores in a .class file....
 (JSR 202) are being done as a maintenance release of JSR 924. The specification for the JVM is published in book form, known as "blue book". The preface states:
We intend that this specification should sufficiently document the Java Virtual Machine to make possible compatible clean-room implementations. Sun provides tests which verify the proper operation of implementations of the Java Virtual Machine.


Sun's JVM is called HotSpot
Hotspot

A hot spot is a region of high or special activity within a larger area of low or normal activity. It may refer to:...
. Clean-room
Clean room design

Clean room design is the method of copying a design by reverse engineering and then recreating it without infringing any of the copyrights and trade secrets associated with the original design....
 Java implementations include Kaffe
Kaffe

Kaffe is a clean room design of a Java Virtual Machine. It comes with a subset of the Java Platform, Standard Edition , Java API, and tools needed to provide a Java platform runtime environment....
 and IBM J9
IBM J9

J9 is a Java Virtual Machine developed by IBM. The J9 VM is the basis of multiple IBM Java offerings, including IBM WebSphere, as well as the basis of all IBM Java Development kits since version 5....
. Sun retains control over the Java trademark, which it uses to certify implementation suites as fully compatible with Sun's specification.

See also


  • List of Java virtual machines
    List of Java virtual machines

    This article provides non-exhaustive lists of J2SE Java virtual machines . It does not include a large number of Java Platform, Micro Edition vendors....
  • Comparison of application virtual machines
    Comparison of Application Virtual Machines

    This comparison lists some software virtual machines that implement the concept of application virtualization, typically for the purpose of allowing application bytecode to be portably run on many different computer architectures and operating systems....
  • Automated Exception Handling
    Automated Exception Handling

    Automated Exception Handling is a computing term referring to the computerized handling of errors. Runtime engines such as those for the Java language or Microsoft .Net lend themselves to an automated mode of exception or error handling....
  • Java performance
    Java performance

    Programs written in Java have had a reputation for being slower and requiring more memory than those written in compiled languages such as C or C++ ....
  • List of JVM languages
    List of JVM languages

    This list of JVM Languages comprises computer programming languages that are used to produce software that runs on the Java Virtual Machine. Some of these languages are interpreted language by a Java , and some are compiled to Java bytecode and Just-in-time compilation during execution as regular Java programs to improve performance....
  • Java Virtual Machine heap
    Java Virtual Machine heap

    The Java Virtual Machine heap is the area of memory used by the Java Virtual Machine for dynamic memory allocation.The heap is split up into "generations":...


External links