tfm-report/Secciones/motivation.tex
2019-12-03 14:12:13 +00:00

130 lines
6.7 KiB
TeX

% !TEX encoding = UTF-8
% !TEX spellcheck = en_US
% !TEX root = ../paper.tex
\chapter{Introduction}
\label{cha:introduction}
\section{Motivation}
\label{sec:motivation}
Program slicing~\cite{Wei81} is a debugging technique that, given a line of
code and a set of variables of a program, simplifies such program so that the only parts
left of it are those that affect or are affected by the values of the selected variables.
\begin{example}[Program slicing in a simple method]
If the left program is sliced on (line 5, variable \texttt{x}), the
result would be the program on the right, with the \texttt{if} block
removed, as it does not affect the value of \texttt{x}.
\label{exa:program-slicing}
\begin{center}
\begin{minipage}{0.49\linewidth}
\begin{lstlisting}[stepnumber=1]
void f(int x) {
if (x < 0)
System.err.println(x);
x++;
System.out.println(x);
}
\end{lstlisting}
\end{minipage}
\begin{minipage}{0.49\linewidth}
\begin{lstlisting}[stepnumber=1]
void f(int x) {
x++;
System.out.println(x);
}
\end{lstlisting}
\end{minipage}
\end{center}
\end{example}
Slices are executable programs whose execution produces the same values
for the specified line and variable as the original program, and they are used to
facilitate debugging of large and complex programs, where the control and data flow may not
be easily understandable.
Though it may seem a really powerful technique, the whole Java language is not
completely covered by it, and that makes it difficult to apply in practical
settings. An area that has been investigated, yet does not have a definitive
solution yet is exception handling. Example~\ref{exa:program-slicing2}
demonstrates how, even using the latest developments in program
slicing~\cite{AllH03}, the sliced version does not include the catch block, and
therefore does not produce a correct slice.
\begin{example}[Program slicing with exceptions]
If the following program is sliced using Allen and Horwitz's proposal~\cite{AllH03} with respect to (line 17, variable \texttt{a}), the
slice is incomplete, as it lacks the \texttt{catch} block from lines 4-6.
\label{exa:program-slicing2}
\begin{center}
\begin{minipage}{0.49\linewidth}
\begin{lstlisting}[stepnumber=1]
void f(int x) throws Exception {
try {
g(x);
} catch (Exception e) {
System.err.println("Error");
}
System.out.println("g() was ok");
g(x + 1);
}
void g(int a) throws Exception {
if (a == 0) {
throw new Exception();
}
System.out.println(a);
}
\end{lstlisting}
\end{minipage}
\begin{minipage}{0.49\linewidth}
\begin{lstlisting}[stepnumber=1]
void f(int x) throws Exception {
try {
g(x);
}
g(x + 1);
}
void g(int a) throws Exception {
if (a == 0) {
throw new Exception();
}
System.out.println(a);
}
\end{lstlisting}
\end{minipage}
\end{center}
When the program is executed as \texttt{f(0)}, the execution log would be: \texttt{1, 2, 3, 13, 14, 15, 4, 5, 8, 10, 13, 14, 17}. In the only execution of line \texttt{17}, variable \texttt{a} has value 1 in that line. However, in the slice produced, the execution log is \texttt{1, 2, 3, 13, 14, 15}. The exception thrown in \texttt{g()} is not caught in \texttt{f()}, so it returns with an exception and line \texttt{17} never executes.
The problem in this example is that the \texttt{catch} block in line \texttt{4} is not included, because ---according to the dependency graph shown below--- it does not influence the execution of line \texttt{17}. Two kinds of dependencies among statements are considered: data dependence (a variable is read that may have gotten its value from a given statement) and control dependence (the instruction controls whether another executes).
In the graph, the slicing criterion is marked in bold, the nodes that represent the slice are filled in grey, and dependencies are displayed as edges, with control dependencies in black and data dependencies in red. Nodes with a dashed outline represent elements that are not statements of the program.
\begin{center}
\includegraphics[width=\linewidth]{img/motivation-example-pdg}
\end{center}
\end{example}
Example~\ref{exa:program-slicing2} showcases an important error in the current slicing procedure for programs that handle errors with exceptions; because the \texttt{catch} block is disregarded. The only way a \texttt{catch} block can be included in the slice is if a statement inside it is needed for another reason. However, Allen and Horwitz did not encounter this problem in their paper~\cite{AllH03}, as the values outputted by method calls are extracted after the \texttt{normal return} and each \texttt{catch}, and in a typical method call with output, the \texttt{catch} is included by default when the outputted value is used. This detail makes the error much smaller, as most \texttt{try-catch} structures are run to obtain a value.
A notable case where a method that may throw an exception is run and no value is recovered (at least from the point of view of program slicing) is when writing to the filesystem or making connections to servers, such as a database or a webservice to store information. In this case, if no confirmation is outputted signaling whether the storage of information was correct, the \texttt{catch} block will be omitted, and the slicer software will produce an incorrect result.
\section{Contributions}
The main contribution of this paper is a complete technique for program slicing programs in the presence of exception handling constructs for Java. This technique extends the previous technique by Allen et al. \cite{AllH03}. It considers all cases considered in that work, but it also provides a solution to cases not considered by them.
For the sake of completeness and in order to understand the process that leaded us to this solution, we will present a brief history of program slicing, specifically those changes that have affected exception handling. Furthermore, we provide a summary of the
different contributions each author has made to the field.
The rest of the paper is structured as follows: chapter~\ref{cha:background} summarizes the theoretical background required in program slicing and exception handling, chapter~\ref{cha:incremental} will analyze each structure used in exception handling, explore the already available solution and propose a new technique that subsumes all of the existing solutions and provides correct slices for each case.
Chapter~\ref{cha:state-art} provides a bird's eye view of the current state of the art, chapter~\ref{cha:solution} provides a summarized description of the new algorithm with all the changes proposed in chapter~\ref{cha:incremental}, and finally, chapter~\ref{cha:conclusion} summarizes the paper and explores future avenues of work.
% vim: set noexpandtab:tabstop=2:shiftwidth=2:softtabstop=2:wrap