<== Previous | Contents | Next ==>

How Adaptive Optimization Works

The basic concepts involved in how the Strongtalk VM works have been published or discussed publically in the past, and are discussed here. The basic idea is very simple: a two-phase execution system is used, with the first phase determining which code is frequently executed. The second, optimizing phase is invoked only for frequently executed code.

This takes advantage of a well-known property of programs: most programs spend the vast majority of their time executing a very small portion of their code. By only optimizing performance critical code, extensive inlining and optimization can be done, which would cause too much overhead in code space and compilation time if it were done on the whole program.

The first step: Instrumented Interpretation

Just as in other Smalltalks, source code is compiled into a portable byte-code format that is kept in the image. When the code is first executed, it is interpreted, as in an interpreted Smalltalk. But the similarities end there. The interpreted code is instrumented in several ways, to determine the execution characteristics of each section of code. This is done with two measurement techiques:

The smaller the number of receiver classes invoked by a send (called the arity), the easier it is to optimize it using inlining in the second phase. An important associated technique called customization is used to help reduce the arity of sends, so that more of them can be optimized. Customization works by making copies of performance-critical methods for each concrete subclass, just as if inheritance were treated as a form of code copying. Many sends can become monomorphic after customization. For example, a self-send in a superclass method would not ordinarily be monomorphic, because self can be any one of a number of different subclasses. But if a copy of the method is made for every subclass, then each copy only ever has one class for self, and thus all self sends become monomorphic.

How Adaptive Optimization Works (cont.) ==>