tuned
authorChristian Urban <christian dot urban at kcl dot ac dot uk>
Wed, 28 Nov 2012 00:06:03 +0000
changeset 81 ffac240147e2
parent 80 191daa3ee29e
child 82 06c3ec0b452e
tuned
compile.scala
slides09.pdf
slides09.tex
--- a/compile.scala	Mon Nov 26 01:11:55 2012 +0000
+++ b/compile.scala	Wed Nov 28 00:06:03 2012 +0000
@@ -311,8 +311,8 @@
   println(n + " " + time_needed(2, ("java " + class_name + "/" + class_name).!!))
 }
 
-List(1, 5000, 10000, 50000, 100000, 250000, 500000, 750000, 1000000).map(compile_test(_))
-
+//List(1, 5000, 10000, 50000, 100000, 250000, 500000, 750000, 1000000).map(compile_test(_))
+List(1, 200, 400, 600, 800, 1000, 1200, 1400, 1600).map(compile_test(_))
 
 
 // javabyte code assmbler
Binary file slides09.pdf has changed
--- a/slides09.tex	Mon Nov 26 01:11:55 2012 +0000
+++ b/slides09.tex	Wed Nov 28 00:06:03 2012 +0000
@@ -128,6 +128,26 @@
 1400 382.527227
 \end{filecontents}
 
+\begin{filecontents}{interpreted2.data}
+%1 0.00503
+200 1.005863
+400 7.8296765
+600 27.2321885
+800 65.249271
+1000 135.4493445
+1200 232.134097
+1400 382.527227
+\end{filecontents}
+
+\begin{filecontents}{compiled2.data}
+200 0.222058
+400 0.215204
+600 0.202031
+800 0.21986
+1000 0.205934
+1200 0.1981615
+1400 0.207116
+\end{filecontents}
 
 \begin{document}
 
@@ -251,7 +271,7 @@
 \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{then}\;
 \text{eval}(\text{while}\;b\;\text{do}\;cs, \text{eval}(cs,E))$}\\
 \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{else}\; E$}\\
-$\text{eval}(\text{print}\; x, E)$ & $\dn$ & $\{\;\text{println}(E(x))\; ;\;E\;\}$\\
+$\text{eval}(\text{write}\; x, E)$ & $\dn$ & $\{\;\text{println}(E(x))\; ;\;E\;\}$\\
 \end{tabular}}
 \end{center}
 
@@ -278,7 +298,7 @@
 
 \begin{center}
 \begin{tikzpicture}
-\begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs]
+\begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small]
 \addplot+[smooth] file {interpreted.data};
 \end{axis}
 \end{tikzpicture}
@@ -296,9 +316,9 @@
 \item introduced in 1995
 \item is a stack-based VM (like Postscript, CLR of .Net)
 \item contains a JIT compiler
-\item many languages take advantage of the infrastructure (JRE)
+\item many languages take advantage of JVM's infrastructure (JRE)
 \item languages compiled to the JVM: Scala, Clojure\ldots
-\item garbage collected
+\item is garbage collected $\Rightarrow$ no buffer overflows
 \end{itemize}
 
 \end{frame}}
@@ -421,7 +441,7 @@
 \end{itemize}\bigskip\pause
 
 during compilation we have to maintain a map between our identifiers and the
-java bytecode numbers
+Java bytecode numbers
 
 \begin{center}
 \bl{$\text{compile}(a, E)$}
@@ -557,11 +577,13 @@
 \hspace{5mm}ldc 1\\
 \hspace{5mm}iadd\\
 \hspace{5mm}if\_icmpeq\;$L_1$\\
-$L_1$:
+$L_2$:
 \end{tabular}}
-\end{center}
+\end{center}\pause
 
-
+\begin{textblock}{3.5}(11,12)
+labels must be unique
+\end{textblock}
 \end{frame}}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 
@@ -573,11 +595,9 @@
 {\Large\bl{$a_1 = a_2$}}
 
 \begin{center}
-\bl{\begin{tabular}{l}
-iload $n_x$\\
-ldc 1\\
-iadd\\
-istore $n_x$\\
+\bl{\begin{tabular}{lcl}
+$\text{compile}(a_1 = a_2, E, lab)$ & $\dn$\\ 
+\multicolumn{3}{l}{$\quad\text{compile}(a_1, E) \;@\;\text{compile}(a_2. E)\;@\; \text{if\_icmpne}\;lab$}
 \end{tabular}}
 \end{center}
 
@@ -592,11 +612,18 @@
 {\Large\bl{if $b$ then $cs_1$ else $cs_2$}}
 
 \begin{center}
-\bl{\begin{tabular}{l}
-iload $n_x$\\
-ldc 1\\
-iadd\\
-istore $n_x$\\
+\bl{\begin{tabular}{lcl}
+$\text{compile}(\text{if}\;b\;\text{then}\; cs_1\;\text{else}\; cs_2, E)$ & $\dn$\\ 
+\multicolumn{3}{l}{$\quad l_{ifelse}\;$ \textcolor{black}{(fresh label)}}\\
+\multicolumn{3}{l}{$\quad l_{ifend}\;$ \textcolor{black}{(fresh label)}}\\
+\multicolumn{3}{l}{$\quad (is_1, E') = \text{compile}(cs_1, E)$}\\
+\multicolumn{3}{l}{$\quad (is_2, E'') = \text{compile}(cs_2, E')$}\\
+\multicolumn{3}{l}{$\quad(\text{compile}(b, E, l_{ifelse})$}\\
+\multicolumn{3}{l}{$\quad\phantom{(}@\;is_1$}\\
+\multicolumn{3}{l}{$\quad\phantom{(}@\; \text{goto}\;l_{ifend}$}\\
+\multicolumn{3}{l}{$\quad\phantom{(}@\;l_{ifelse}:$}\\
+\multicolumn{3}{l}{$\quad\phantom{(}@\;is_2$}\\
+\multicolumn{3}{l}{$\quad\phantom{(}@\;l_{ifend}:, E'')$}\\
 \end{tabular}}
 \end{center}
 
@@ -650,11 +677,16 @@
 {\Large\bl{while $b$ do $cs$}}
 
 \begin{center}
-\bl{\begin{tabular}{l}
-iload $n_x$\\
-ldc 1\\
-iadd\\
-istore $n_x$\\
+\bl{\begin{tabular}{lcl}
+$\text{compile}(\text{while}\; b\; \text{do} \;cs, E)$ & $\dn$\\ 
+\multicolumn{3}{l}{$\quad l_{wbegin}\;$ \textcolor{black}{(fresh label)}}\\
+\multicolumn{3}{l}{$\quad l_{wend}\;$ \textcolor{black}{(fresh label)}}\\
+\multicolumn{3}{l}{$\quad (is, E') = \text{compile}(cs_1, E)$}\\
+\multicolumn{3}{l}{$\quad(l_{wbegin}:$}\\
+\multicolumn{3}{l}{$\quad\phantom{(}@\;\text{compile}(b, E, l_{wend})$}\\
+\multicolumn{3}{l}{$\quad\phantom{(}@\;is$}\\
+\multicolumn{3}{l}{$\quad\phantom{(}@\; \text{goto}\;l_{wbegin}$}\\
+\multicolumn{3}{l}{$\quad\phantom{(}@\;l_{wend}:, E'')$}\\
 \end{tabular}}
 \end{center}
 
@@ -669,16 +701,40 @@
 {\Large\bl{write $x$}}
 
 \begin{center}
-\bl{\begin{tabular}{l}
-iload $n_x$\\
-ldc 1\\
-iadd\\
-istore $n_x$\\
+\small\bl{\begin{tabular}{l}
+.method public static write(I)V\\ 
+\;\;    .limit locals 5 \\
+\;\;    .limit stack 5 \\
+\;\;    iload 0 \\
+\;\;    getstatic java/lang/System/out Ljava/io/PrintStream;\\ 
+\;\;    swap \\
+\;\;    invokevirtual java/io/PrintStream/println(I)V \\
+\;\;    return \\
+.end method\bigskip\bigskip\\
+%
+\normalsize
+iload $E(x)$\\
+invokestatic write(I)V\\
 \end{tabular}}
 \end{center}
 
 \end{frame}}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[c]
+\frametitle{\begin{tabular}{c}Next Compiler Phases\end{tabular}}
+
+\begin{itemize}
+\item assembly $\Rightarrow$ native code
+\item labels $\Rightarrow$ absolute or relative addresses
+
+\end{itemize}
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
+
+
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \mode<presentation>{
@@ -687,7 +743,7 @@
 
 \begin{center}
 \begin{tikzpicture}
-\begin{loglogaxis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs]
+\begin{loglogaxis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small]
 \addplot+[smooth] file {interpreted.data};
 \addplot+[smooth] file {compiled.data};
 \end{loglogaxis}
@@ -697,22 +753,47 @@
 \end{frame}}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 
-
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \mode<presentation>{
 \begin{frame}[t]
-\frametitle{\begin{tabular}{c}Compiled Code\end{tabular}}
+\frametitle{\begin{tabular}{c}Compiled vs.~Interpreted Code\end{tabular}}
 
 \begin{center}
 \begin{tikzpicture}
-\begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs]
-\addplot+[smooth] file {compiled.data};
+\begin{axis}[ylabel=secs,
+    xlabel=n,
    enlargelimits=0.05,
    ybar interval=0.7, legend style=small]
+\addplot file {interpreted2.data};
+\addplot file {compiled2.data};
+%\legend{interpreted, compiled}
 \end{axis}
 \end{tikzpicture}
 \end{center}
 
 \end{frame}}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
+
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\mode<presentation>{
+\begin{frame}[t]
+\frametitle{\begin{tabular}{c}What Next\end{tabular}}
+
+\begin{itemize}
+\item register spilling
+\item dead code removal
+\item loop optimisations
+\item instruction selection
+\item type checking
+\item concurrency
+\item fuzzy testing
+\item verification\bigskip\\
+
+\item GCC, LLVM, tracing JITs
+\end{itemize}
+
+\end{frame}}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
 
 
 \end{document}