Browse Prior Art Database

NOPing of null tests involving a static of an uninitialized declared type

IP.com Disclosure Number: IPCOM000239912D
Publication Date: 2014-Dec-12
Document File: 3 page(s) / 46K

Publishing Venue

The IP.com Prior Art Database

Abstract

Disclosed is a technique to use runtime assumptions and code patching in a Just in Time (JIT) compiler to optimize a common usage pattern related to static variables. The core novelty is the use of an optimization for static variables based on No Operation instruction (NOPing) and runtime assumptions.

This text was extracted from a PDF file.
This is the abbreviated version, containing approximately 47% of the total text.

Page 01 of 3

NOPing of null tests involving a static of an uninitialized declared type

A Just in Time (JIT) compiler typically has a runtime assumptions framework that it uses for performing speculative optimizations. An example is guarded devirtualization, in which a virtual call is converted to a direct call conditional upon a new class being loaded and the relevant virtual method being overridden by that new class. One way to check for a newly loaded class overriding the devirtualized method is to explicitly load and test the "method is overridden" bit that is maintained by the virtual machine (e.g., Java virtual machine) in the generated code before the code for the devirtualized direct call. If the devirtualized method is overridden, then control should go to the original virtual call, which does the slow dispatch via the virtual function table.

Runtime assumptions can help avoid the explicit load and test of the "method is overridden" test. Instead of generating code to perform the load and test , the JIT compiler can register a runtime assumption at compile time and just generate a No Operation (NOP) instruction before the devirtualized call. The runtime assumption controls whether the JIT compiler patches the NOP before the devirtualized call in case the JIT compiler detects a new class that overrides the devirtualized method . This works because the JIT compiler is notified by the virtual machine before any new class is initialized and made available for use by the running program. If/when the NOP is patched, the code is changed to branch unconditionally to the slow virtual call dispatch.

The novel contribution is a technique to use runtime assumptions and code patching in a JIT compiler to optimize a common usage pattern related to static variables . An application using this pattern can be changed to take advantage of the JIT compiler optimization (if it needs to be changed). This kind of an optimization for static variables based on NOPing and runtime assumptions has not been proposed before in any published work.

The novel technique allows a JIT compiler to replace a static variable load and test by an NOP instruction until the declared class of the static variable is initialized by the Java virtual machine. If/when the declared class is initialized, code is patched to branch unconditionally to perform the load and test of the static variable (the original code that was optimized). The code patching is controlled using the JIT compiler's runtime assumptions framework.

The usage pattern being optimized is the following: if (TraceControllerClass.traceEnabled()) {

Code related to tracing }

where the TraceController code
static Boolean _traceEnabled;
static Boolean traceEnabled() { return _traceEnabled; }

This is typically interspersed across the codebase. In this example, TraceControllerClass._traceEnabled is a Boolean static variable that controls

whether tracing is to be done. When desired, the user simply specifies at some point d...