Monday, October 12, 2009

On Reentrancer

Reentrancer is an Eclipse based refactoring tool that deals with reentrancy related problems in Java programs. The main refactoring steps are as follows:

- Handling library globals. Since removing access to Library globals is kind of hard to achieve, Reentrancer only reports possibly problematic accesses to global library state and leaves it to the programmer to handle them.

- Static fields are replaced by getter and setter methods and every access to these fields are replaced by calls to these accessor methods. This step is mainly designed to support the lazy initialization step. Since the transformation does not preserve static initializer semantics in all cases, Reentrancer have formulated preconditions that ensure that the initializers in an input program are safe for refactoring. Reentrancer's analyses for checking the refactoring preconditions are implemented based on the WALA framework, which is primarily used to compute call graphs from static initializers to discover their transitive callees.

- Reentracer then replaces static initializers with explicit lazy initialization. Static initializer methods are an impediment to reentrancy because they are only executed once, upon the first use of the declaring class. With the help of thread local state, the lazy initialization step will be executed once per thread. Since lazy initialization may alter the point at which initialization code executes thus potentially altering program behavior, Reentrancer performs a static analysis to reveal such cases and issues warnings to the programmer if needed.

- In the next step, global state is replaced with thread-local state with the effect that each thread will get its own copy of this state. This is accomplished by wrapping each appropriate static field in a java.lang.ThreadLocal object and using the methods ThreadLocal.get() and ThreadLocal.set() to read/write the value of the wrapped object.

- The final transformation creates a fresh thread for each execution of the application, thus ensuring that each execution observes gets a different copy of the static fields (now made thread local) and the lazy initialization is executed once per thread.

Reentrancer has been evaluated by observing its behavior on several single-threaded, non-reentrant benchmarks. For each individual benchmark, the reentrancy problems have been first confirmed to exist, either by observing failures when running existing tests in parallel or by writing new tests that exposed problems. After refactoring and checking that the preconditions are still met, the refactored version was run in parallel on a dual-core processor, which yielded performance benefits.

In the recent years, significant advances have been made in the area of automated tool support for refactoring. However, Reentrancer is the first enabling semi-automatic refactoring support for making existing Java programs reentrant.

No comments:

Post a Comment