The Java Runtime Environment And JVM Tasks

The Java Runtime Environment



Java software source files are compiled in the sense that they are converted into a set of bytecodes from the text format in which you write them. The bytecodes are stored in .class files.

At runtime, the bytecodes that make up a Java software program are loaded, checked, and run in an interpreter. In the case of applets, you can download the bytecodes, and then they are interpreted by the JVM built into the browser. The interpreter has two functions: it executes bytecodes and it makes the appropriate calls to the underlying hardware.

In some Java technology runtime environments, a portion of the verified bytecode is compiled to native machine code and executed directly on the hardware platform. This enables the Java software code to run close to the speed of C or C++ with a small delay at load time to enable the code to be compiled to the native machine code.


Note – Sun Microsystems has enhanced the JVM machine by adding new performance-enabling technologies. One of these technologies is called the Java HotSpotTM virtual machine and has the potential to enable the Java programming language to run as fast as compiled C++ code.

JVM Tasks

The following section provides a more comprehensive discussion of the three main tasks performed by the JVM:

● Loads code – Performed by the class loader

● Verifies code – Performed by the bytecode verifier

● Executes code – Performed by the runtime interpreter

The Class Loader

The class loader loads all classes needed for the execution of a program. The class loader adds security by separating the namespaces for the classes of the local file system from those imported from network sources. This limits any Trojan Horse applications, because local classes are always loaded first.

After all of the classes have been loaded, the memory layout of the executable file is determined. At this point, specific memory addresses are assigned to symbolic references and the lookup table is created. Because memory layout occurs at runtime, the Java technology interpreter adds protection agains unauthorized access into the restricted areas of code.

The Bytecode Verifier

Java software code passes several tests before running on your machine. The JVM puts the code through a bytecode verifier that tests the format of code fragments and checks code fragments for illegal code, which is code that forges pointers, violates access rights on objects, or attempts to change object type.

Note – All class files imported across the network pass through the bytecode verifier.
Verification Process

The bytecode verifier makes four passes on the code in a program. It ensures that the code adheres to the JVM specifications and does not violate system integrity. If the verifier completes all four passes without returning an error message, then the following is ensured:

● The classes adhere to the class file format of the JVM specification.

● There are no access restriction violations.

● The code causes no operand stack overflows or underflows.

● The types of parameters for all operational codes are correct.

● No illegal data conversions, such as converting integers to object references, have occurred.