Java virtual machine: Difference between revisions

Content deleted Content added
mNo edit summary
No edit summary
Line 5:
Programs written in Java are compiled into a standardized portable binary format, which typically comes in the form of files with the [[class (file format)|.class]] extension. A program may consist of many classes, in which case, every class will be in a different file. The first 4 bytes in hexadecimal of each class must be CA FE BA BE. Class files may be packaged together in a [[jar (file format)|.jar]] file, with the exact same format as a [[zip (file format)|.zip]] file, optionally with a few extra special files added.
 
This binary is then interpretedexecuted atby the JVM [[runtime]] bywhich acarries out [[emulation]] of the JVM. The[[instruction mainset]] interpretationby loop[[interpreter|interpreting]] isit describedor by theapplying followinga pseudo[[just-codein-time]] Compiler (JIT).
 
The JVM has a [[Stack (computing)|stack]] based architecture. Each [[Thread (computer programming)|thread]] has its own program counter.
do {
Each [[Thread (computer programming)|thread]] has its own program counter.
fetch an opcode;
 
if (operands) fetch operands;
Code verification is applied to bytecode class files by the runtime at program load time. This means that only a limited amount of bytecode sequences form valid programs, e.g. a JUMP (branch) instruction can only target an instruction within the same function. 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 face of the codeverified 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 architectures registers. In fact, code verification makes JVM different to a classic stack architecture whose efficient emulation with a JIT compiler is more complicated and typically carried out by a more slow interpreter.
execute the action for the opcode;
 
} while (there is more to do);
Code verification also ensures that arbitrary bitpatterns cannot get used as an address. [[Memory protection]] is achieved without the need for an [[MMU]]. Thus, JVM is an efficient way of getting memory protection on simple silicon that got no MMU.
 
The JVM has a [[Stack (computing)|stack]] based architecture. Each [[Thread (computer programming)|thread]] has its own program counter.
 
The JVM has instructions for the following groups of tasks
Line 26:
 
 
The aim is binary compatiblity. Each particular host [[operating system]] needs aits JVMown specificallyimplementation forof the JVM itruntime. These JVMs interpreteinterpret the byte code semantically the same way., Butbut the actual implementation may be different.
More complicated than just the emulation of bytecode is compatible and efficient implementation of the java core [[API]] which got to be mapped to each host operating system.
 
The specification for the JVM is published in book form and [[HTML]] and anybody is allowed to write an implementation of it. The preface states: