% !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.

\sergio{Se me hace corta esta definicion y me faltan algunas utilidades del program slicing, por que se usa? Realmente no se usa solo en depuracion. Tiene mas usos, esto ademas da referencias a poner si queremos.}

\sergio{Carpeta SAC 2017 (paper-poster 3 paginas): ``Program slicing is a technique for program analysis and transformation whose main objective is to extract from a program those statements (the slice) that 
influence or are influenced by the values of one or more variables at some point of interest, often called slicing criterion [13, 12, 1, 9]. This technique has been adapted to practically all programming languages, and it has many applications such as debugging [3], program specialization [8], software maintenance [5], code obfuscation [7], etc.".} 

\sergio{Cogeria algo de aqui para hacer una definicion mas completa, ademas ya usamos terminologia de slicing como \textit{slice} y \textit{slicing criterion}.}
\josep{De acuerdo con Sergio. Un par de cosas más: Entra muy a saco la introducción con una definición. :-) Por otra parte, tal y como está definido (para el lector profano), parece que un slice es todo lo que afecta O es afectado por el slicing criterion. Es decir, como si el "O" formara parte de la definición. Yo hablaría aquí solo de backward slicing, y dejaría forward para luego (igual que has dejado dynamic para luego).}

\begin{example}[Program slicing \josep{\deleted{in}\added{applied to}} a simple method]
	\sergio{Consider the code shown below / in Figure XX, containing a simple method written in Java.}  If the left program is sliced on (line 5, variable \texttt{x}),\sergio{Si hemos usado ya slice y slicing criterion aqui podemos decir que el slicing criterion es tal y el slice es cual y empezar a usar la terminologia correcta de manera mas natural.} 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 \sergio{OJO!, cuidao con ese jardin que luego esta el weak slice.}\josep{puedes evitar el jard\'in empezando la frase así: ``In its more general form, slices are..."}
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. \josep{en realidad los executable slices no suelen usarse en debugging. M\'as bien en Program specialization...}



Though it may seem a really powerful technique, \josep{many languages lack of a mature program slicer or one that covers the whole language. For instance,} the whole Java \sergio{Primera aparicion de Java, mencionar que el ejemplo es Java porque sino parece que te aparece Java out of the blue.} language is not
completely covered by it, and that makes it difficult to apply in practical
settings.

\sergio{Propongo algo asi para conectar program slicing y las exceptions:}

\sergio{Though it may seem a really powerful technique, the amount of analysis that need to be done to properly obtain a correct slice is very considerable. Many situations of the Java language lead to several scenarios (podriamos poner algun ejemplo de cosas chungas, rollo recursividad, arrays, objetos... para que se vea que no todo tiene una solucion unica ni perfecta, sino que muchas propuestas son mejorables.) that are quite difficult to analyse, which is the reason because there does not exist a universal solution for all the existent problems in the field of program slicing. Conversely, many different approaches are usually proposed to solution the same slicing problem.} 

\sergio{Se que hay mucha verborrea, pero es para hacer la lectura menos agresiva xD.}\josep{Carlos va directo al grano, no se anda con rodeos. :-). Pero, efectivamente es necesario (luego no, pero aqu\'i en a introducci\'on s\'i) darle un poco de cremita al lector. Esto es la motivaci\'on y de momento no ha habido motivaci\'on. Echo en falta decirle que la t\'ecnica ha sido aplicada y estudiada en pr\'acticamente todos los lenguajes de programaci\'on y que es una t\'ecnica de optimizaci\'on que usan los compiladores y muchas t\'ecnicas de an\'alisis est\'atico. Que se aplica en debugging, program compehension, paralelizaci\'on, eliminaci\'on de c\'odigo muerto, etc. falta motivar que este area es importante, no es solo una paja mental y una vuelta de tuerca mas... todo esto para los profanos (e.g., el tribunal ;-))}

\sergio{Inside all this slicing problems, there is } An area that has been investigated, \sergio{but? (por evitar el yet ... yet)}yet does not have a definitive
solution yet\sergio{,} \deleted{is}\josep{el is no hay que borrarlo} exception handling. Example~\ref{exa:program-slicing2}
demonstrates\josep{shows} how, even using the latest developments \josep{to handle exceptions in} in \sergio{exception handling slicing }program
slicing~\cite{AllH03}, the sliced version does not include the catch block \sergio{this approach is not able to include the catch block in the obtained slice}, and
therefore does not produce a correct slice.

\begin{example}[Program slicing with exceptions]
	\added{Consider}\deleted{If} the following program \josep{on the left that has been sliced (on the right) using}\deleted{is} sliced using Allen and Horwitz's proposal~\cite{AllH03} with respect to (line 17, variable \texttt{a})\added{. As \josep{it} can be appreciated, t}\deleted{, t}he
	slice is incomplete, \josep{because}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}
\sergio{Captions? para referirnos a ellas por separado como programa original (izquierda) y slice (derecha)?. Indicar en ella el SC en negrita en el codigo o de otro color o algo para destacarlo.}

	When the program is executed \josep{from the call}as \texttt{f(0)}, the execution log \sergio{hay que decir que esto es la lista de instrucciones que se ejecutan y en el orden en el que lo hacen.}\josep{en program slicing se llama execution history, y puedes poner una cita a Corel y Lasky} 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 \josep{computed by \cite{} and} shown \josep{in Figure~\ref{}}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 (\josep{an} the instruction controls whether another \josep{instruction} executes).
	In the graph, the \josep{node associated with the} slicing criterion is marked in bold, the nodes that represent the slice are filled in grey\josep{demasiado clarito. En mi ordenador no se ve}, 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}
		\josep{transforma todas las figuras en figuras reales (referenciables) y con caption}
		\josep{Yo ver\'ia m\'as claro el grafo conectando llamada y llamado}
	\end{center}
\end{example}

Example~\ref{exa:program-slicing2} \josep{is a contribution of this work because it} showcases an important error in the current slicing procedure for programs that handle errors with exceptions\josep{\deleted{; because}\added{where}} 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\josep{tackle? account for?} 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. \sergio{Anyadir el nodo \textit{out} para que lo que has explicado aqui quede mas comprensible. Viendo que existe el nodo \textit{out}, pero que nadie el SC no lo necesita.}

\added{There is also another }\deleted{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)\added{. It occurs}\deleted{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 \deleted{will be}\added{is} omitted, and the \josep{program} slicer \josep{\deleted{software}} \deleted{will} produce\added{s} an incorrect result.

\section{Contributions}

The main contribution of this paper\sergio{paper?research?work?}\josep{work o research} is a 
\added{new approach for program slicing with exception handling for Java programs.} \deleted{complete technique for program slicing programs in the presence of exception handling constructs for Java}. \added{Our approach}\deleted{This technique} extends the previous technique \added{proposed} by Allen et al. \cite{AllH03}. It \added{is able to properly slice}\deleted{considers} all cases considered in \deleted{that}\added{their} work, but it also provides a solution to \sergio{some other} cases not \deleted{considered}\added{contemplated}\josep{considered} by them.

For the sake of completeness and in order to understand the process that leaded us to this solution, we \josep{\deleted{will present}\josep{first summarize the fundamentals o background}} a brief history\sergio{background?} of program slicing \added{terminology}, specifically those changes that have affected exception handling.\sergio{delving deeper in the progress of program slicing techniques related to 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} \josep{analyzes}will analyze each structure used in exception handling, explore\josep{s} the already available solution and propose\josep{s} a new technique that subsumes all of the existing solutions and provides correct slices for each case.\josep{frase demasiado larga}
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} \josep{concludes?}summarizes the paper\sergio{work?} and explores future avenues of work\sergio{possible improvements?}.

% vim: set noexpandtab:tabstop=2:shiftwidth=2:softtabstop=2:wrap
