![]() |
|||
![]() ![]() |
![]() |
![]()
|
![]() |
The SourceFile StructureThe 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 JVMNow 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, heres 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 LoaderAs 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 Loaders 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:
Execution of a Loaded ClassTo 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 classs 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 JVMs 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.
|
![]() |
|