As with many other programming languages, java uses a compiler to convert human-readable source code into executable programs. The java compiler generates architecture-independent bytecodes. The bytecodes can be executed only by a Java Virtual Machine (VM), which is an idealized java architecture, usually implemented in software rather than hardware. Java bytecode files are called class files because they contain a single Java class. The vast majority of Java programs will be composed of more than one class file.
To execute Java bytecodes, the VM uses a class loader to fetch the bytecodes from a disk or a network. Each class file is fed to a bytecode verifier that ensures the class is formatted correctly and will not corrupt memory when it is executed. The bytecode verification phase adds to the time it takes to load a class, but it actually allows the program to run faster because the class verification is performed only once, not continuously as the program runs.
The execution unit of the VM carried out the instruction specified in the bytecodes. The simplest execution unit is an interpreter, which is a program that reads the bytecodes, interprets their meaning, and then performs the associated function. Interpreters are generally much slower than native code compilers because they continuously need to look up the meaning of each bytecode during execution.
Fortunately there is an elegant alternative to interpreting code, called Just-in-Time (JIT) compilation. The JIT compilers convert the bytecodes to native code instructions on the user's machine immediately before execution. Traditional native code compilers run on the developer's machine, are used by programmers, and produce non portable executables. JIT compilers run on the user's machine and are transparent to the user; the resulting native code instructions do not need to be ported because they are already at their destination.
No comments:
Post a Comment