Home : Course Map : Chapter 1 : Java : Supplements :
Advanced Virtual Machines
JavaTech
Course Map
Chapter 1
Introduction
History
What is Java?
Versions
Java 5.0
Features

Java Process
Tools
Documentation
Compatibility
Getting Started
Simple Applet
Simple Application
Starters
Exercises

    Supplements
Interpret/Compile

Making WebPages
Plug-in
Java 5.0 Features
The JVM
Advanced JVMs
Alt. Compilers
Alt. JVMs
Java Deployment

     About JavaTech
     Codes List
     Exercises
     Feedback
     References
     Resources
     Tips
     Topic Index
     Course Guide
     What's New

The interpretation approach to program execution provides for transportable code but usually at the cost of slower execution. Advances in Java Virtual Machine (JVM) design, however, have greatly enhanced Java performance and Java programs can now reach speeds approaching that of C/C++ for many applications.

The figure below illustrates the essential steps in running a Java program. First is shown the bytecode for a multiplication of two floating point numbers.

The most basic VM would simply interpret each line of the bytecode sequentially. (Of course, it will occasionally jump to a different section of code when it executes a jump command.) If written in C, it might use a long switch statement with a case for each possible bytecode instruction.

Alternatively, a JVM that includes a Just-In-Time (JIT) compiler will instead convert the instructions to native machine language the first time it encounters these instructions. That is, it compiles on the fly or just-in-time to execute the instructions.

Note that here compile refers to the conversion of bytecode to local machine code, not the conversion of Java source code to bytecode.

In the first pass this compilation will slow the program somewhat. However, for code sections that run repetitively, such as a loop in a math computation, the native code executes on the subsequent passes and thus provides the full performance capabilities of the platform.

Sun's Hotspot JVM takes an even more sophisticated approach. It dynamically monitors, or profiles, a program's performance as it is running and looks for sections of the code where execution slows significantly. When it finds such a section, it will optimize that code and compile it to native machine language for faster execution. In such cases, the optimization may result in speeds that actually exceed those for C programs.

A crude but effective approach, at least as far as speed is concerned, is to compile the bytecode directly to local machine code. So-called native code compilers and ahead-of -time compilers will provide very fast performance but, of course, at the price of eliminating the platform independence of the code and preventing dynamic binding.

 

References & Web Resources

 

Latest update: Oct. 5.05

            Tech
Java in Science
    & Engineering
Benefits
Shortcomings
RealWorld Examples

           Physics
Java in Physics
SimulationTypes
Simulate&Analyze
Sim. in Experiments
  Demo 1: Event
  Demo 2: Continuous
  Demo 3: Static

Learn by Coding
Exercises

  Part I Part II Part III
Java Core 1  2  3  4  5  6  7  8  9  10  11  12 13 14 15 16 17
18 19 20
21
22 23 24
Supplements

1  2  3  4  5  6  7  8  9  10  11  12

Tech 1  2  3  4  5  6  7  8  9  10  11  12
Physics 1  2  3  4  5  6  7  8  9  10  11  12

Java is a trademark of Sun Microsystems, Inc.