• 沒有找到結果。

Chapter 4. Design of Java Dynamic Class

4.5. Method Invocation Mechanism

This section introduces the method invocation mechanism of the Java core.

There are two types of Java method invocations. One is static class method invocation and the other one is dynamic instance method invocation. Static method invocation such as invokestatic references to class method directly. Dynamic method invocation such as invokevirtual and invokespecial depend on their object references.

Nevertheless, the proposed Java core executes them with the same procedure. The proposed class loader recognizes these method invocation types and inserts special parameters to indicate the object reference at parsing time. Moreover the invokespecial can be used under three conditions. First, the method is used for instance initialization. Second, the method is a private method. Third, the method is invoked from a “Super” keyword. Current version can support bytecode such as invokestatic, invokespecial, and invokevirtual. The complete method invocation procedure can be described by the state machine in Fig. 18. In a normal class file, a method invocation bytecode is followed by the class and method reference ID‟s of the class name string and method name string that are used for computing the target address of the method. With the proposed dynamic resolution mechanism, the invocation bytecode in the class runtime image (translated by the class loader) is

Fig. 19 illustrates how the operand can be used to access the target method address through indirect references. There is no need to perform any string comparisons as in traditional JVM dynamic resolution process..

Fig. 18. State machine of method invocation mechanism.

Fig. 19. Method invocation resolution steps.

Fig. 18 describes the state machine of method invocation mechanism. The state

Normal

Type 1 : The class which contains this class had been parsed and place in the external DDR Memory

Type 2 : The class had been parsed and place in the Internal Method Area Cache

Type 3 : Need interrupt to load and parse class from jar file store at CF Card

Image File Start TOC

Const Pool Data

Method Code Space

(1) Method informa tion , cross table field address

Offset to const pool da ta

(2)

Cross Reference Ta ble Access

Hardware Java Core Invoke + opera nd (Toc index ma pping)

Cla ss ma na ge Logic Circuit Decision Logic : Cla ss ha d

machine is controlled by dynamic resolution controller of Java core. The method invocation mechanism can be divided into four stages roughly. Java core can find referenced class and referenced method bytecode information by following this state machine.

Fig. 20. Reference pointer and method information access

The first stage of method invocation state machine is to find the reference pointer in bytecode image. The first 4 states of state machine are the first stage. Java core will exchange the program counter to obtain the reference pointer from these four stages.

The second stage will access the cross reference table by reference pointer from first stage. And the method invocation state machine performs this behavior at “Offset access” state. As the Fig. 20 shown, the field of cross reference table referenced is a 32-bits data field. The up 16-bits of this field indicate the referenced class‟s global index. The low 16-bits of this field indicate the method offset of referenced method.

The method offset stands for the method bytecode address offset of its bytecode image. In this stage we can judge whether this referenced class has ever loaded or not by the method offset. If the referenced method has correct method offset, we can

Image File Start TOC

Const Pool Data

Method Code Space Method [i] informa tion , Reference Pointer

Offset to const pool da ta

Access Cross Reference Table

Cross reference table

Class [x]

Attributes Class name, global index, image address, etc

Method[i] Name Global index & method1 offset

Field Data[i] Name Indirectly pointer

referenced class which not loaded before, Java core enters the bad index and waits for the RISC core service as above sections. The Java core enters the third stage until the RISC service finish. If the referenced class has loaded before, the Java core enters third stage directly.

Fig. 21. The cache mechanism of third stage

Java core will get sufficient method information from RISC core service or cross reference table. The third stage enables our bytecode cache mechanism. Java core can query the cache table by the global index which is upper bits of method information field. The Java core follows the cache mechanism and checks method area cache block index at first. If the referenced class has allocated to method area, the cache table will register the start block index. If the referenced class has not allocated to method area, Java core can load its bytecode image with other information such as start address in external memory and the image size.

Cache Management Table In Java Core

Global Index Tag Image Size 1stCache Block

Start Index

Fig. 22. Adjust Java core to access referenced method bytecode

After the referenced class has loaded into method area, Java core adjust its stack frame and program counter as the Fig. 22 shown. The method offset from cross reference table helps the Java core to update program counter. Then Java core continues to execute new method as usual.

Then this final section continuously describes the stack status during method invocation mechanism. The Fig. 23 describes the stack status of method invocation which the method invoked has two local variables and no argument. The Fig. 24 is also the method invocation with one argument and two local variables. The Fig. 25 and Fig. 26 are then method return which one is “Void return” and another is “Integer return.”

Block 1 Block 2 Block 3

Block 4

Block 32

Image 1

Image 2

Empty

Block index & Method Offset

Java Program Counter

Bytecode start address of referenced method

Method Bytecode

Fig. 23. Method invocation stack variation – no arguments, 2 local variables.

Fig. 24. Method invocation stack variation – 1 argument, 2 locals.

Stack 1 Stack 2

Update VP ,SP ,next class with 2 locals

Stack 1 Stack 2

Update VP ,SP ,next class with 2 locals

Stack 1 Stack 2

Fig. 25. Method invocation stack variation – Method Return without value (void).

Fig. 26. Method Invocation Stack Variation – Method Return with value

“ireturn.”

相關文件