slides09.tex
changeset 81 ffac240147e2
parent 80 191daa3ee29e
child 82 06c3ec0b452e
equal deleted inserted replaced
80:191daa3ee29e 81:ffac240147e2
   126 1000 135.4493445
   126 1000 135.4493445
   127 1200 232.134097
   127 1200 232.134097
   128 1400 382.527227
   128 1400 382.527227
   129 \end{filecontents}
   129 \end{filecontents}
   130 
   130 
       
   131 \begin{filecontents}{interpreted2.data}
       
   132 %1 0.00503
       
   133 200 1.005863
       
   134 400 7.8296765
       
   135 600 27.2321885
       
   136 800 65.249271
       
   137 1000 135.4493445
       
   138 1200 232.134097
       
   139 1400 382.527227
       
   140 \end{filecontents}
       
   141 
       
   142 \begin{filecontents}{compiled2.data}
       
   143 200 0.222058
       
   144 400 0.215204
       
   145 600 0.202031
       
   146 800 0.21986
       
   147 1000 0.205934
       
   148 1200 0.1981615
       
   149 1400 0.207116
       
   150 \end{filecontents}
   131 
   151 
   132 \begin{document}
   152 \begin{document}
   133 
   153 
   134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   154 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   135 \mode<presentation>{
   155 \mode<presentation>{
   249 \multicolumn{3}{@{}l@{}}{$\text{eval}(\text{while}\;b\;\text{do}\;cs, E) \dn$}\\
   269 \multicolumn{3}{@{}l@{}}{$\text{eval}(\text{while}\;b\;\text{do}\;cs, E) \dn$}\\
   250 \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)$}\\
   270 \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)$}\\
   251 \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{then}\;
   271 \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{then}\;
   252 \text{eval}(\text{while}\;b\;\text{do}\;cs, \text{eval}(cs,E))$}\\
   272 \text{eval}(\text{while}\;b\;\text{do}\;cs, \text{eval}(cs,E))$}\\
   253 \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{else}\; E$}\\
   273 \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{else}\; E$}\\
   254 $\text{eval}(\text{print}\; x, E)$ & $\dn$ & $\{\;\text{println}(E(x))\; ;\;E\;\}$\\
   274 $\text{eval}(\text{write}\; x, E)$ & $\dn$ & $\{\;\text{println}(E(x))\; ;\;E\;\}$\\
   255 \end{tabular}}
   275 \end{tabular}}
   256 \end{center}
   276 \end{center}
   257 
   277 
   258 \end{frame}}
   278 \end{frame}}
   259 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   279 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   276 \begin{frame}[t]
   296 \begin{frame}[t]
   277 \frametitle{\begin{tabular}{c}Interpreted Code\end{tabular}}
   297 \frametitle{\begin{tabular}{c}Interpreted Code\end{tabular}}
   278 
   298 
   279 \begin{center}
   299 \begin{center}
   280 \begin{tikzpicture}
   300 \begin{tikzpicture}
   281 \begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs]
   301 \begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small]
   282 \addplot+[smooth] file {interpreted.data};
   302 \addplot+[smooth] file {interpreted.data};
   283 \end{axis}
   303 \end{axis}
   284 \end{tikzpicture}
   304 \end{tikzpicture}
   285 \end{center}
   305 \end{center}
   286 
   306 
   294 
   314 
   295 \begin{itemize}
   315 \begin{itemize}
   296 \item introduced in 1995
   316 \item introduced in 1995
   297 \item is a stack-based VM (like Postscript, CLR of .Net)
   317 \item is a stack-based VM (like Postscript, CLR of .Net)
   298 \item contains a JIT compiler
   318 \item contains a JIT compiler
   299 \item many languages take advantage of the infrastructure (JRE)
   319 \item many languages take advantage of JVM's infrastructure (JRE)
   300 \item languages compiled to the JVM: Scala, Clojure\ldots
   320 \item languages compiled to the JVM: Scala, Clojure\ldots
   301 \item garbage collected
   321 \item is garbage collected $\Rightarrow$ no buffer overflows
   302 \end{itemize}
   322 \end{itemize}
   303 
   323 
   304 \end{frame}}
   324 \end{frame}}
   305 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   325 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   306 
   326 
   419 \item lookup: \bl{$\text{iload}\; number$}
   439 \item lookup: \bl{$\text{iload}\; number$}
   420 \item store: \bl{$\text{istore}\; number$}
   440 \item store: \bl{$\text{istore}\; number$}
   421 \end{itemize}\bigskip\pause
   441 \end{itemize}\bigskip\pause
   422 
   442 
   423 during compilation we have to maintain a map between our identifiers and the
   443 during compilation we have to maintain a map between our identifiers and the
   424 java bytecode numbers
   444 Java bytecode numbers
   425 
   445 
   426 \begin{center}
   446 \begin{center}
   427 \bl{$\text{compile}(a, E)$}
   447 \bl{$\text{compile}(a, E)$}
   428 \end{center}
   448 \end{center}
   429 
   449 
   555 \hspace{5mm}if\_icmpeq\;$L_2$\\
   575 \hspace{5mm}if\_icmpeq\;$L_2$\\
   556 \hspace{5mm}iload 1\\
   576 \hspace{5mm}iload 1\\
   557 \hspace{5mm}ldc 1\\
   577 \hspace{5mm}ldc 1\\
   558 \hspace{5mm}iadd\\
   578 \hspace{5mm}iadd\\
   559 \hspace{5mm}if\_icmpeq\;$L_1$\\
   579 \hspace{5mm}if\_icmpeq\;$L_1$\\
   560 $L_1$:
   580 $L_2$:
   561 \end{tabular}}
   581 \end{tabular}}
   562 \end{center}
   582 \end{center}\pause
   563 
   583 
   564 
   584 \begin{textblock}{3.5}(11,12)
       
   585 labels must be unique
       
   586 \end{textblock}
   565 \end{frame}}
   587 \end{frame}}
   566 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   588 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   567 
   589 
   568 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   590 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   569 \mode<presentation>{
   591 \mode<presentation>{
   571 \frametitle{\begin{tabular}{c}Compiling BExps\end{tabular}}
   593 \frametitle{\begin{tabular}{c}Compiling BExps\end{tabular}}
   572 
   594 
   573 {\Large\bl{$a_1 = a_2$}}
   595 {\Large\bl{$a_1 = a_2$}}
   574 
   596 
   575 \begin{center}
   597 \begin{center}
   576 \bl{\begin{tabular}{l}
   598 \bl{\begin{tabular}{lcl}
   577 iload $n_x$\\
   599 $\text{compile}(a_1 = a_2, E, lab)$ & $\dn$\\ 
   578 ldc 1\\
   600 \multicolumn{3}{l}{$\quad\text{compile}(a_1, E) \;@\;\text{compile}(a_2. E)\;@\; \text{if\_icmpne}\;lab$}
   579 iadd\\
       
   580 istore $n_x$\\
       
   581 \end{tabular}}
   601 \end{tabular}}
   582 \end{center}
   602 \end{center}
   583 
   603 
   584 \end{frame}}
   604 \end{frame}}
   585 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   605 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   590 \frametitle{\begin{tabular}{c}Compiling Ifs\end{tabular}}
   610 \frametitle{\begin{tabular}{c}Compiling Ifs\end{tabular}}
   591 
   611 
   592 {\Large\bl{if $b$ then $cs_1$ else $cs_2$}}
   612 {\Large\bl{if $b$ then $cs_1$ else $cs_2$}}
   593 
   613 
   594 \begin{center}
   614 \begin{center}
   595 \bl{\begin{tabular}{l}
   615 \bl{\begin{tabular}{lcl}
   596 iload $n_x$\\
   616 $\text{compile}(\text{if}\;b\;\text{then}\; cs_1\;\text{else}\; cs_2, E)$ & $\dn$\\ 
   597 ldc 1\\
   617 \multicolumn{3}{l}{$\quad l_{ifelse}\;$ \textcolor{black}{(fresh label)}}\\
   598 iadd\\
   618 \multicolumn{3}{l}{$\quad l_{ifend}\;$ \textcolor{black}{(fresh label)}}\\
   599 istore $n_x$\\
   619 \multicolumn{3}{l}{$\quad (is_1, E') = \text{compile}(cs_1, E)$}\\
       
   620 \multicolumn{3}{l}{$\quad (is_2, E'') = \text{compile}(cs_2, E')$}\\
       
   621 \multicolumn{3}{l}{$\quad(\text{compile}(b, E, l_{ifelse})$}\\
       
   622 \multicolumn{3}{l}{$\quad\phantom{(}@\;is_1$}\\
       
   623 \multicolumn{3}{l}{$\quad\phantom{(}@\; \text{goto}\;l_{ifend}$}\\
       
   624 \multicolumn{3}{l}{$\quad\phantom{(}@\;l_{ifelse}:$}\\
       
   625 \multicolumn{3}{l}{$\quad\phantom{(}@\;is_2$}\\
       
   626 \multicolumn{3}{l}{$\quad\phantom{(}@\;l_{ifend}:, E'')$}\\
   600 \end{tabular}}
   627 \end{tabular}}
   601 \end{center}
   628 \end{center}
   602 
   629 
   603 \end{frame}}
   630 \end{frame}}
   604 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   631 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   648 \frametitle{\begin{tabular}{c}Compiling Whiles\end{tabular}}
   675 \frametitle{\begin{tabular}{c}Compiling Whiles\end{tabular}}
   649 
   676 
   650 {\Large\bl{while $b$ do $cs$}}
   677 {\Large\bl{while $b$ do $cs$}}
   651 
   678 
   652 \begin{center}
   679 \begin{center}
   653 \bl{\begin{tabular}{l}
   680 \bl{\begin{tabular}{lcl}
   654 iload $n_x$\\
   681 $\text{compile}(\text{while}\; b\; \text{do} \;cs, E)$ & $\dn$\\ 
   655 ldc 1\\
   682 \multicolumn{3}{l}{$\quad l_{wbegin}\;$ \textcolor{black}{(fresh label)}}\\
   656 iadd\\
   683 \multicolumn{3}{l}{$\quad l_{wend}\;$ \textcolor{black}{(fresh label)}}\\
   657 istore $n_x$\\
   684 \multicolumn{3}{l}{$\quad (is, E') = \text{compile}(cs_1, E)$}\\
       
   685 \multicolumn{3}{l}{$\quad(l_{wbegin}:$}\\
       
   686 \multicolumn{3}{l}{$\quad\phantom{(}@\;\text{compile}(b, E, l_{wend})$}\\
       
   687 \multicolumn{3}{l}{$\quad\phantom{(}@\;is$}\\
       
   688 \multicolumn{3}{l}{$\quad\phantom{(}@\; \text{goto}\;l_{wbegin}$}\\
       
   689 \multicolumn{3}{l}{$\quad\phantom{(}@\;l_{wend}:, E'')$}\\
   658 \end{tabular}}
   690 \end{tabular}}
   659 \end{center}
   691 \end{center}
   660 
   692 
   661 \end{frame}}
   693 \end{frame}}
   662 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
   694 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
   667 \frametitle{\begin{tabular}{c}Compiling Writes\end{tabular}}
   699 \frametitle{\begin{tabular}{c}Compiling Writes\end{tabular}}
   668 
   700 
   669 {\Large\bl{write $x$}}
   701 {\Large\bl{write $x$}}
   670 
   702 
   671 \begin{center}
   703 \begin{center}
   672 \bl{\begin{tabular}{l}
   704 \small\bl{\begin{tabular}{l}
   673 iload $n_x$\\
   705 .method public static write(I)V\\ 
   674 ldc 1\\
   706 \;\;    .limit locals 5 \\
   675 iadd\\
   707 \;\;    .limit stack 5 \\
   676 istore $n_x$\\
   708 \;\;    iload 0 \\
       
   709 \;\;    getstatic java/lang/System/out Ljava/io/PrintStream;\\ 
       
   710 \;\;    swap \\
       
   711 \;\;    invokevirtual java/io/PrintStream/println(I)V \\
       
   712 \;\;    return \\
       
   713 .end method\bigskip\bigskip\\
       
   714 %
       
   715 \normalsize
       
   716 iload $E(x)$\\
       
   717 invokestatic write(I)V\\
   677 \end{tabular}}
   718 \end{tabular}}
   678 \end{center}
   719 \end{center}
   679 
   720 
   680 \end{frame}}
   721 \end{frame}}
   681 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
   722 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
       
   723  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   724 \mode<presentation>{
       
   725 \begin{frame}[c]
       
   726 \frametitle{\begin{tabular}{c}Next Compiler Phases\end{tabular}}
       
   727 
       
   728 \begin{itemize}
       
   729 \item assembly $\Rightarrow$ native code
       
   730 \item labels $\Rightarrow$ absolute or relative addresses
       
   731 
       
   732 \end{itemize}
       
   733 
       
   734 \end{frame}}
       
   735 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
       
   736 
       
   737 
   682 
   738 
   683 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   739 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   684 \mode<presentation>{
   740 \mode<presentation>{
   685 \begin{frame}[t]
   741 \begin{frame}[t]
   686 \frametitle{\begin{tabular}{c}Compiled vs.~Interpreted Code\end{tabular}}
   742 \frametitle{\begin{tabular}{c}Compiled vs.~Interpreted Code\end{tabular}}
   687 
   743 
   688 \begin{center}
   744 \begin{center}
   689 \begin{tikzpicture}
   745 \begin{tikzpicture}
   690 \begin{loglogaxis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs]
   746 \begin{loglogaxis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small]
   691 \addplot+[smooth] file {interpreted.data};
   747 \addplot+[smooth] file {interpreted.data};
   692 \addplot+[smooth] file {compiled.data};
   748 \addplot+[smooth] file {compiled.data};
   693 \end{loglogaxis}
   749 \end{loglogaxis}
   694 \end{tikzpicture}
   750 \end{tikzpicture}
   695 \end{center}
   751 \end{center}
   696 
   752 
   697 \end{frame}}
   753 \end{frame}}
   698 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   754 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   699 
   755 
   700 
   756 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   701 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   757 \mode<presentation>{
   702 \mode<presentation>{
   758 \begin{frame}[t]
   703 \begin{frame}[t]
   759 \frametitle{\begin{tabular}{c}Compiled vs.~Interpreted Code\end{tabular}}
   704 \frametitle{\begin{tabular}{c}Compiled Code\end{tabular}}
       
   705 
   760 
   706 \begin{center}
   761 \begin{center}
   707 \begin{tikzpicture}
   762 \begin{tikzpicture}
   708 \begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs]
   763 \begin{axis}[ylabel=secs,
   709 \addplot+[smooth] file {compiled.data};
   764     xlabel=n,
       
   765     enlargelimits=0.05,
       
   766     ybar interval=0.7, legend style=small]
       
   767 \addplot file {interpreted2.data};
       
   768 \addplot file {compiled2.data};
       
   769 %\legend{interpreted, compiled}
   710 \end{axis}
   770 \end{axis}
   711 \end{tikzpicture}
   771 \end{tikzpicture}
   712 \end{center}
   772 \end{center}
   713 
   773 
   714 \end{frame}}
   774 \end{frame}}
   715 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   775 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
       
   776 
       
   777 
       
   778 
       
   779 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   780 \mode<presentation>{
       
   781 \begin{frame}[t]
       
   782 \frametitle{\begin{tabular}{c}What Next\end{tabular}}
       
   783 
       
   784 \begin{itemize}
       
   785 \item register spilling
       
   786 \item dead code removal
       
   787 \item loop optimisations
       
   788 \item instruction selection
       
   789 \item type checking
       
   790 \item concurrency
       
   791 \item fuzzy testing
       
   792 \item verification\bigskip\\
       
   793 
       
   794 \item GCC, LLVM, tracing JITs
       
   795 \end{itemize}
       
   796 
       
   797 \end{frame}}
       
   798 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
   716 
   799 
   717 
   800 
   718 \end{document}
   801 \end{document}
   719 
   802 
   720 %%% Local Variables:  
   803 %%% Local Variables: