framework overview

The sambamba framework is based on the LLVM compiler framework and is used like a regular compiler:

  1. The code of the application is compiled to LLVM Bitcode using the corresponding LLVM frontend. In the illustration above a C/C++ frontend was used taking C or C++ source files. Additional frontends exist for languages like Objective C, C#, Java, Haskell and more.
  2. The produced LLVM Bitcode is then passed through the static components which every analysis registered with our framework can optionally contribute. The purpose of these static parts is to run costly analyses and transformations offline. Each of these static modules can put preliminary results into a static data store.
  3. After every static module has seen and potentially modified the application bitcode, it is linked together with a Just-In-Time compiler, the sambamba runtime system, the collected static analysis data as well as the dynamic parts of the registered sambamba modules into one big binary.
  4. On execution the dynamic components of the registered modules are initialized. They have access to the actual program arguments as well as the method about to be run (most likely the main method). The statically gathered data is made available by the runtime system. Finally the application bitcode is compiled (just in time) to binary code and execution starts.
  5. The dynamic parts of the modules are free to instrument the running code and to register alternative versions of arbitrary methods with the runtime system. Each version of a method is registered together with an execution criterion used to decide dynamically which version to execute.
  6. Information gathered by observing the running application can be stored in a dynamic data store. It is preserved by the framework across different runs of the application. One typical use case is to store information about misspeculation in certain methods in order to prevent frequent rollbacks in future program runs.