Camil Demetrescu edited approach.tex  over 8 years ago

Commit id: 10ee0d09afbd2de4c33e567625d7fb34231e8141

deletions | additions      

       

\subsection{Overview}  \label{ss:overview}  Consider the generic OSR scenario shown in Figure~\ref{fi:osr-dynamics}. A base function \textsf{f} \fbase\  is executed and it can either terminate normally (dashed lines), or an OSR event may transfer control to a variant \textsf{f'}. \fvariant.  The decision of whether an OSR should be fired at a given point \textsf{L} is based on an {\em OSR condition}. A typical example is a guard testing whether a function \textsf{f} \fbase\  has become unsafe and execution needs to fall back to a safe version \textsf{f'}. \fvariant.  This scenario includes deoptimization of functions generated with aggressive speculative optimizations. Another example is a profile counter reaching a certain hotness threshold, which indicates that \textsf{f} is taking longer than expected and is worth optimizing. This is a frequent scenario in JIT-based virtual machines. Classical OSR implementations adjust the stack so that execution can continue in \textsf{f'} \fvariant\  with the current frame \mynote{add citations}. This requires manipulating the program at machine code level and is highly ABI- and compiler-dependent. A simpler approach, which we follow in this article, consists of creating a new frame every time an OSR is fired, essentially regarding an OSR transition as a function call \mynote{cite WebKit and McVM}. Our implementation targets two general scenarios: 1) {\bf resolved OSR}: \textsf{f'} \fvariant\  is known before executing \textsf{f}, \fbase,  as in the deoptimization example discussed above; 2) {\bf open OSR}: \textsf{f'} \fvariant\  is generated when the OSR is fired, supporting deferred compilation strategies. In both cases, for and OSR to be fired at a certain point \textsf{L}, the base function needs to be instrumented before its execution with code that checks the OSR condition. We denote with \textsf{f$_{\textsf{OSRfrom}}$} \fosrfrom\  the OSR-instrumented version of \textsf{f}. \fbase.  If the condition is satisfied, control is transferred to \textsf{f'} \fvariant\  via a function call. In the first scenario, shown in Figure~\ref{fi:overview-osr-final}, the OSR invokes an instrumented version of \textsf{f'}, \fvariant,  which we call \textsf{f'$_{OSRto}$}. This is possible since \textsf{f'} \fvariant\  is known when \textsf{f} \fbase\  is instrumented. %and returns the same value when it has terminated. The assumption is that the called function produces the same side-effects and return values that one would obtain by \textsf{f} if no OSR were performed.