#acl All:read = Welcome to the Wiki of the seminar '''Java vs. C++''' in the winter semester 2010 / 2011 = This seminar is given by [[http://ad.informatik.uni-freiburg.de/staff/bast|Prof. Dr. Hannah Bast]], assisted by [[http://ad.informatik.uni-freiburg.de/staff/buchholb|Björn Buchhold]](buchholb@informatik.....). The seminar takes place every Wednesday, 2:15 pm - 3:45 pm, in the seminar room 01-018 in building 101. Our first session is on Wednesday, October 20, 2010. The last session is on Wednesday, February 9, 2011. On Wednesday December 29, 2010 and on Wednesday January 5, 2011 there is no session due to the christmas break. That's 15 sessions altogether. All sessions are recorded (video + audio). The seminar is about the ''performance'' differences between Java and C++, in particular, running time and space consumption. It's NOT about the differences in syntax, language features, ease of programming, etc. The sessions will be recorded, and the slides as well the recordings will be put online after each presentation: see the links below. Hier ist der [[attachment:evaluation-java-vs-cplusplus-ws1011.pdf|Evaluationsbogen]] für die Veranstaltung. Sie können den ausgefüllten Bogen entweder hier auf diese Wikiseite hochladen (vorher ausloggen, sonst nicht anonym!), oder persönlich bei [[http://ad.informatik.uni-freiburg.de/staff/bast|Hannah Bast]] oder [[http://ad.informatik.uni-freiburg.de/staff/buchholb|Björn Buchhold]] abgeben. == Information and materials for each session == 1. Wednesday October 20, 2010: '''Introduction and Overview''', Hannah Bast, [[attachment:session-1.pdf|slides]], [[attachment:session-1.avi|recording as AVI (not cut)]]. 1. Wednesday October 27, 2010: '''Machine code generation in C++''', Hannah Bast,[[attachment:session-2.pdf|slides]], [[attachment:session-2.avi|recording as AVI (not cut)]]. * '''Topics:''' x86 Assembler (history, registers, instructions, stack, function calls, some simple programs, MXX 128-bit streaming registers). * '''Remember 1:''' Write an array of 256 million ints = 1 GB. C++ unoptimized (gcc -O 0): 1.1s, Java: 0.8s, Hand-written assembler code: 0.6s, C++ optimized (gcc -O 3): 0.4s. * '''Remember 2:''' C++ unoptimized (gcc -O 0) translates the code line by line to machine code (just like Java without JIT). * '''Remember 3:''' Almost all PCs / notebooks / servers today use x86. Mobile phones etc. use RISC. 1. Wednesday November 3, 2010: The Java Virtual Machine (Robin Schirrmeister),[[attachment:jvm.pdf|slides as pdf]], [[attachment:jvm.odp|slides as odp]][[attachment:session-3.wmv|recording as WMV]],[[attachment:JasminFaculty.j|faculty function written in jasmin]]. * '''Topics:''' Introduction to the Java Virtual Machine and Problems with benchmarking Java. * The JVM is a virtual machine that can be used to run programs from any language that has a compiler to Java Bytecode. * The JVM was designed with a focus on portability and security of the programs running on it. * Due to the complex features of modern JVM implementations and their optimization techniques, correctly benchmarking a '''long-running''' Java program is difficult. * When Benchmarking you need to run the benchmarked program many times to avoid measuring JVM startup time, JIT compile time, etc. One Benchmark Framework taking care of this can be found at http://www.ibm.com/developerworks/library/j-benchmark2/index.html 1. Wednesday November 10, 2010: Compiler optimization in C++ (Jens Hoffmann), [[attachment:cpp_compiler_opt.pdf|slides as pdf]] [[attachment:session-4.wmv|recording as WMV]]. 1. Wednesday November 17, 2010: NO SESSION. 1. Wednesday November 24, 2010: Java Just-in-Time Compilation (Jan Kelch), [[attachment:JavaJITC.pdf|slides as pdf]] [[attachment:session-5.wmv|recording as WMV]]. 1. Wednesday December 1, 2010: Memory management in C++ (Simon Rettberg), [[attachment:memory_management_c++.pdf|slides as pdf]][[attachment:session-6.wmv|recording as WMV]]. 1. Wednesday December 8, 2010: Memory management in Java (Arda Akcay), [[attachment:session-7.wmv|recording as WMV]]. 1. Wednesday December 15, 2010: GCJ (Thomas Liebetraut), [[attachment:GCJ|slides as pdf]] [[attachment:session-8.wmv|recording as WMV]]. * '''Topics:''' Building blocks of a Java runtime environment, history if different Java implementations, GCJ's mode of operation, comparison Hotspot/GIJ/GCJ * GCJ (GNU Compiler for Java) bytecode and Oracle's javac bytecode are very similar, so no performance differenz when using the same VM * GIJ (GNU Interpreter for Java) is a LOT slower than Hotspot, especially when it comes to memory de-allocation * GCJ to native code is somewhat faster than JITting (even with Hotspot), but has the same major problems with de-allocation as GIJ * C++ with all optimizations still faster 1. Wednesday December 22, 2010: RTL optimization (Alexander Nutz) [[attachment:session9-RTL-pres.pdf|slides as pdf]] [[attachment:session-9.wmv|recording as WMV]] [[attachment:session9-rtl-Examples.zip|code examples]]. * '''Topics:''' RTL in GCC: compiler internal representations: AST, CFG ; RTL as GCC's intermediate representation ; optimizations done in RTL * AST (abstract syntax tree) is the representation a compiler works on, CFG (control flow graph) is used for many analyses * For hardware-independent optimizations RTL is gradually replaced by Tree-SSA but it is still necessary for hardware-dependent optimizations like register allocation and still many optimizations are done in it * When trying to read RTL (all passes can be output by -fdump-rtl-all) the sixth argument of each (insn ...) is the interesting one (LISP-like syntax) 1. Wednesday January 12, 2011: Arrays Java vs. C++ (Simon Skilevis, Ammar Qaseem) [[attachment:Array in C++.pptx|c++ slides as powerpoint]] [[attachment:Array in c++.pdf|c++ slides as pdf]] [[attachment:javaArray.ppt|java slides as powerpoint]] . * '''Topics ( C++ ): '''1D Array Representation and Space Overhead of 1D Array . * 2D Array Representation ( Row-mapping representation,Column-mapping representation,and Array-of-array representation) and Space Overhead of each way. * Buffer Overflow ( no Bounds Checking ): C and C++ provide no built-in protection against accessing or overwriting data in any part of memory and solution for this problem. * Dynamic memory allocation( new and delete operator). * STL-Vector as dynamic array and advantages of Vectors. * '''Topics ( Java ): ''' 1. Wednesday January 19, 2011: Strings Java vs. C++ (Michael Pereira, Christoph Hofmann) [[attachment:c++ slides as pdf|c++ slides as pdf]] [[attachment:Strings in Java - Annotated|Java slides as pdf]] [[attachment:session-11.wmv|recording as WMV]]. * '''Topics ( C++ ): ''' String Implementations (STL, CString), Sting Optimizations (Small String, Reserve, Copy-On-Write, Call-By-Reference), String Functions (find, Multibyte) * '''Remember 1:''' The STL brings many optimizations and functions to String and should be prefered over the old cstring * '''Remember 2:''' String Optimizations really can increase performance. Some are already implemented by Libraries (small string opt. by boost, copy on write by qt) or can be implemented by yourself. * '''Remember 3:''' Use reserve when working with large strings or concatenation and call-by-reference when passing strings to functions to really improve performance. * '''Topics ( Java ): ''' 1. Wednesday January 26, 2011: NO SESSION. 1. Wednesday February 2, 2011: Threads Java vs. C++ (Niklas Meinzer). [[attachment:Niklas Meinzer - Threads.pdf|slides]] [[attachment:ThreadTestSources.zip|live demo sources]] * '''Topics: ''' Basics of Multithreading: Properties of Processes and Threads * Threads in Java: Thread creation, Mutual exclusion and wait-notify thread coordination * pthreads: C-style thread library: properties and usage * boost::threads: C++ style thread library: properties and usage * Performance tests: Thread creation and Locking * '''Note:''' During the live demo of my talk there was a discrepancy between the results of the single locking test for java and the locking test series. This was due to the fact that the single locking test created 10 threads and not only one as intended. I have corrected this mistake in the source code and the results are now identical. The data on the slides however uses the data from the locking test series program and is thus accurate. 1. Wednesday February 9, 2011: Graphical User Interfaces Java cs. C++ (Daniel Brand, Franz Dietrich). [[attachment:slides-Java-vs-c++.pdf|slides]] * Performance completely depends on hardware acceleration * Native look and feel vs. emulation ( AWT, SWT, Gtk <-> Swing) * Complex vs. simple layouting (SWT, Gtk <-> Swing) * Avoid Swing under Linux when performance matters (might get better in future with accelerated backend) * Layers on Linux: Gtk -> Cairo -> xlib -> Driver * You can't tell for sure which of them is better (depends on the needs and system you want to run it on) Interesting additional topics: smart pointers / auto pointers / scoped pointers in C++.