Java Language Environment
- Java language environment has four key features:
The Java virtual machine (JVM), which provides portability of Java programs.
An impure interpretive scheme, whose flexibility exploited to provide a capability for the inclusion of program modules dynamically, i.e., during interpretation.
A Java bytecode verifier, which provides security by ensuring that dynamically loaded program modules do not interfere with the operation of the program and the operating system.
An optional Java just-in-time (JIT) compiler, which provides efficient execution.
- Shows a schematic of the Java language environment. The Java compiler converts a source language program into the Java bytecode, which is a program in the machine language of the Java virtual machine.
- The Java virtual machine implemented by a software layer on a computer, which itself called the Java virtual machine for simplicity. This scheme provides portability as the Java bytecode can be ‘executed’ on any computer that implements the Java virtual machine.
The Java virtual machine essentially interprets the bytecode form of a program. The Java compiler and the Java virtual machine thus implement the impure interpretation scheme.
- Use of an interpretive scheme allows certain elements of a program to be specified during interpretation. This feature exploited to provide a capability for including program modules called Java class files during interpretation of a Java program.
- The class loader invoked whenever a new class file is to be dynamically included in the program. The class loader locates the desired class file and passes it to the Java bytecode verifier.
- The Java bytecode verifier checks whether
The program forges pointers, thereby potentially accessing invalid data or performing branches to invalid locations.
program violates access restrictions, e.g., by accessing private data.
the program has type-mismatches whereby it may access data in an invalid manner.
The program may have stack overflows or underflows during execution.
- The Java language environment provides the two compilation schemes shown in the lower half of Figure. The Java Just-In-Time compiler compiles parts of the Java bytecode that are consuming a significant fraction of the execution time into the machine language of the computer to improve their execution efficiency. It implemented using the scheme of dynamic compilation.
- After the just-in-time compiler has compiled some part of the program. Some parts of the Java source program has been converted into the machine language while the remainder of the program still exists in the bytecode form. Hence the Java virtual machine uses a mixed- mode execution approach.
- The other compilation option uses the Java native code compiler shown in the lower part of Figure It simply compiles the complete Java program into the machine language of a computer. This scheme provides fast execution of the Java program; however, it cannot provide any of the benefits of interpretation or just-in-time compilation.