Chapter 3 Design of Dynamic SPM Allocation
3.3 Components of Execution Environment in Our Design
3.3.4 Method Reallocator
Table 3-2 New Profits are Stored, and Cache Miss Frequencies are Reset to 0, after Profit Calculation
Method Cache Miss the main memory or to the SPM. When a JIT-compiled method is selected to evict from the SPM by the SPM space manager, the method reallocator needs to reallocate the method to the main memory. When it is decided that a JIT-compiled method is to be reallocated to the SPM by the method information profiler, the method reallocator has to reallocate the method to the SPM.
Reallocation of JIT-compiled methods can be divided into promotion and demotion as depicted in Figure 3-7. Promotion represents reallocation of a JIT-compiled method from the main memory to the SPM. On the contrary, demotion represents reallocation of a JIT-compiled method from the SPM to the main memory.
The process of promoting a JIT-compiled method from the main memory to the SPM chiefly involves the following four steps:
i. The SPM space manager is invoked to allocate an SPM free space for the promoted method.
34
ii. The JIT-compiled code of the promoted method is copied from the code buffer in the main memory to the SPM.
iii. The pointer to the start of the compiled code kept in the promoted method’s method block in the method table is fixed up in order to maintain the accuracy of program execution. The way to locate the pointer to the start of the compiled code stored in the method block is to utilize the pointer to the promoted method’s method descriptor kept in the method information table and thus the pointer can be located.
iv. The location of the promoted method recorded in the method information table is modified to “SPM”.
Figure 3-7 Promotion and Demotion
The process of demoting a JIT-compiled method from the SPM to the main memory mainly involves the following three steps:
i. The JIT-compiled code of the demoted method is copied from the SPM to the code buffer in the main memory.
ii. The pointer to the start of the compiled code stored in the demoted method’s method block in the method table is fixed up in order to maintain the accuracy of program execution. The pointer to the demoted method’s method descriptor kept in the method information table is used to locate the pointer to the start of the compiled code stored in the method block in the method table.
iii. The location of the demoted method recorded in the method information table is
35
modified to “main memory”.
Due to the copying of JIT-compiled code in the processes of promotion and demotion, promotion or demotion of a JIT-compiled method must bring additional runtime overhead. We have devised an approach in order to reduce the overall demotion overhead incurred by copying demoted methods’ compiled code from the SPM to the main memory throughout program execution. The essence of this approach is that as long as it can be guaranteed that the code buffer space occupied by a promoted method is able to be freed up when the code buffer lacks free space, the JIT-compiled code of a promoted method may remain in the code buffer after promotion. As a result, a demoted method’s JIT-compiled code probably needn’t be copied from the SPM to the main memory during demotion, and thus the overall demotion overhead can be reduced.
To this end, the decompilation mechanism in the original execution environment merely requires slight modification, and the code buffer space occupied by a promoted method will be able to be freed up when decompilation is performed. Besides, a new piece of information is added to the method information table for keeping track of the starting address of each promoted method’s compiled code in the main memory, as shown in Table 3-3. If a JIT-compiled method in the main memory gets decompiled, the starting address of the method’s compiled code in the main memory recorded in the method information table will be changed to 0. For an example, see Table 3-3, where method 3’s starting address of the compiled code in the main memory is 0, signifying that method 3 has been decompiled, and its JIT-compiled code has not existed in the code buffer in the main memory.
During demotion of a JIT-compiled method from the SPM to the main memory, the method reallocator will check the starting address of the demoted method’s compiled code in the main memory recorded in the method information table. If it is 0, indicating the JIT-compiled code of the demoted method hasn’t existed in the code buffer in the main memory, the method reallocator still has to copy the JIT-compiled code from the SPM to the
36
main memory. If it is not 0, indicating the JIT-compiled code of the demoted method still stays in the code buffer in the main memory, the method reallocator need not copy the JIT-compiled code from the SPM to the main memory and simply needs to make use of the starting address of the demoted method’s compiled code in the main memory recorded in the method information table to fix up the pointer to the start of the compiled code stored in the method block in the method table. And thus the overhead incurred by copying the JIT-compiled code from the SPM to the main memory can be altogether eliminated.
Table 3-3 Method 3 has been Decompiled, and Its “Starting Address of Compiled Code in Main Memory” is 0
Method Cache Miss
37