X hits on this document

PDF document

Program Transformations for Light-Weight CPU Accounting and Control in the Java Virtual Machine A ... - page 9 / 40





9 / 40


that actually require it, so that execution paths that do not contain method invocations may appear as being leaf methods on their own. Other optimizations, such as Feeley’s balanced polling [18], could be applied as well.

3. In order to ensure that triggerConsume() is also invoked just before the thread terminates, the run() method of each class that implements the Runnable interface is rewritten according to Figure 3. Hence, it is certain that the very last amount of CPU consumed is reported correctly, after which the thread will terminate.

public void run(ThreadCPUAccount cpu) { ThreadCPUAccount cpu = ThreadCPUAccount.getCurrentAccount();

try { ... // Here is th

e original code.

} finally {cpu.triggerConsume();}


Figure 3. The rewritten run() method.

4. Finally, the instructions that update the consumption counter are inserted in the beginning of each accounting block, which we define as the longest possible sequence of bytecode instructions where only the first instruction may be the target of a branch and only the last instruction may change the control flow (e.g., a branch or jump). Thus, in contrast to the classical notion of basic block, method invo- cations do not end a block, as this yields larger accounting blocks without harming correctness.4 In order to reduce the accounting overhead, the conditionals inserted for polling are not considered as distinct accounting blocks.

3.2. Rewriting Example

Figure 4 illustrates how a method is transformed according to the proposed, unoptimized accounting scheme. For the sake of readability, in this article we show all transformations on Java code, whereas in reality they take place at the JVM bytecode level.

In this example, a polling conditional might seem necessary as a final instruction at the end of method f(int), in order to protect against the risk of executing more than MAXPATH instructions since the last invoked method. However, this is not required, because all execution

4 The accuracy of this solution is actually slightly degraded when exceptions are thrown at run-time, as explained in Section 7.2.

Document info
Document views152
Page views152
Page last viewedSun Jan 22 08:24:08 UTC 2017