Brought to you by EarthWeb
ITKnowledge Logo Login Graphic Click Here!
Click Here!
ITKnowledge
Find:
 
EXPERT SEARCH ----- nav

EarthWeb Direct

EarthWeb sites: other sites

Previous Table of Contents Next


The SourceFile Structure

The SourceFile structure consists of three 2-byte values. attribute_name_index indexes into the constant_pool to the entry containing the SourceFile string. attribute_length must contain a value of 2. sourcefile_index indexes into the constant_pool to the entry containing the source file name.

Executing a Class in the JVM

Now that you have an understanding of the JVM and the Class file format, it is time to connect the dots. You have learned the architecture of both the JVM and the Class file, but you have not yet seen how the two interact. The JVM is designed to execute JVM instructions, and the Class file is designed to provide the JVM with all the required executable information. When the two interact, a Java class is executed.

The information needed to piece together the details of a Class file execution can be found in the previous sections of this chapter. However, without studying each element of the JVM in detail, the proper execution sequence might not be clear. For this reason, here’s a summary of the execution of a Class file: the Class Loader finds, verifies, and loads the class into the JVM for execution, then signals for execution to begin.

Although this summarized version of a Class file execution is streamlined, and correct, it leaves a few questions unanswered, such as the following: What is the Class Loader? What does it find and how does it do so? How does it signal the JVM to begin execution? The next two sections will discuss each of these questions in turn, beginning with a look at the Class Loader.

The Class Loader

As the name implies, the Class Loader mechanism loads classes into the JVM. All executable code placed into the JVM for execution arrives there by means of a Class Loader. However, the Class Loader’s function is not as simple and trivial as you might assume. Quite to the contrary, the Class Loader is in many ways a complex, adaptable, and intelligent facility without which the JVM cannot live.

The Java runtime environment is a single entity containing subsections that each provide separate and distinct pieces for functionality. The Class Loader is likewise partitioned into subsections, each providing a specialized piece of the Class Loader puzzle. The following is a list of each of the Class Loader Internal Units and their associated performance tasks:

  Class File Retrieval Unit—The Class File Retrieval Unit is responsible for the retrieval of stored class files. This involves resolving the class name to the accessible class storage environment, checking with the Class Cache Unit to see if the Class Cache Unit is already in the system, and presenting the class as a stream of bytes to the Class Verification Unit.
  Class Cache Unit—The Class Cache Unit works in tandem with the Class File Retrieval Unit to optimize the load time of requested class files. The JVM specification makes no assumption about the cache algorithm used in the Class Cache Unit. The cache algorithm, in fact, has been an area of optimization for the various Java runtime environment implementations.
  Class Verification Unit—Once the class has been loaded, the Class Verification Unit verifies the validity of the loaded class. Validity checks include, but are not limited to, class file format integrity, binary compatibility of the class file and the JVM, and security violations.
  Class Linker Unit—After the class has been deemed safe by the Class Verification Unit, it is passed to the Class Linker Unit to retrieve any needed supporting classes. The Class Linker Unit analyzes the class’s hierarchy, and dependencies, and makes subsequent calls to the Class File Retrieval Unit to load any required classes.
  Class Initializer Unit—At the point the Class Initializer Unit receives a class, it is ready to be loaded into the JVM for execution. The role of the Class Initializer Unit is to properly load the class regions into the JVM for execution, as shown in Figure 1.6.


Figure 1.6  Class Loader internals.

Execution of a Loaded Class

To summarize the task of the Class Loader, it finds, verifies, and loads the class into the JVM for execution. At this point, the JVM Method region is loaded with all of the class’s methods, the JVM Stack is loaded with class initialization, and the registers are set to the initial class execution state. All that is left is for the Class Loader to signal the JVM to begin execution.

Previously in this chapter, the operating differences between a register-based architecture and JVM’s stack-based model were discussed. At the point of class execution, the JVM follows the exact model specified in that section for popping operands off the stack and pushing them onto it for execution, as shown in Figure 1.5.

A final note about Class file execution and the JVM has to do with threads. The concept of threads was not explored in this chapter with respect to the JVM, and will not be discussed until Chapter 5, “Java API.” However, you should keep in the back of your mind that the JVM architecture and Class file execution procedure discussed in this chapter can be scaled to handle an almost infinite number of simultaneously executing threads.


Previous Table of Contents Next
HomeAbout UsSearchSubscribeAdvertising InfoContact UsFAQs
Use of this site is subject to certain Terms & Conditions.
Copyright (c) 1996-1999 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.