Monday, July 9, 2012

Speeding up the VM

The last couple weeks I've been focusing on speeding up the Objeck VM based upon CLBG benchmarks.  As a result the memory manager has been refactored to more efficiently manage static variables.  Memory references are now managed in a b-tree versus a binary tree.

The interpreter, which is written in C++, has been re-factored such that frequently executed code uses local variables instead of instance variables. While this change seems subtle benchmarks of purely interpreted code show speeds ups of 30% to 40%.  The interpreter is now caching precomputed jump offsets.

With regards to compiler optimizations, the biggest performance increases can be attributed to method inlining.  Method  inlining is the first optimization in the pipeline thus making other optimizations more effective. In addition, inlined code makes more effective use of the JIT compiler since calls out of native machine code are avoided.

The VM will continue to be tweaked is more benchmarking is done.

Wednesday, June 20, 2012

Mandelbrot Benchmarks

Was up late last night implementing a multi-threaded version of the Mandelbrot benchmark.  While implementing this benchmark I discovered a compiler bug that impacts classes derived from the Thread class.  This issue has been resolved and a new release will be pushed out later this week.  Initial Mandelbrot benchmarks looks promising preliminary results are below...




Language Iterations Time (secs.)
Java server 1.7.0 4,096 0m1.377s
Objeck 3.1.2 4,096 0m4.959s
Erlang HiPE 5.8.3 4,096 1m53.115s
JRuby 1.5.1 4,096 1m54.893s

Test box: Linux ubuntu 3.0.0-21-generic, i7-2760QM CPU @ 2.40GHz


Updated benchmarks are here...

Sunday, June 17, 2012

Garbage Collection

The Objeck memory managers are hybrid mark-and-sweep garbage collectors.  Garbage collection (GC) starts when the run time system reaches a memory allocation threshold.  The process starts by scanning all valid roots and accounting for memory that's in use.  An example of a sub-root is a method frame that's part of a call stack.  Only frames that are part of a call stack need to be accounted for as they contain references to memory blocks that may be in use.  

The Objeck GC is not a generational garbage collector so all memory references must be traced.  Each root is scanned in it's own GC thread resulting in a list of blocks that are in use.  Once we have a list of all blocks currently in use we need to identify those blocks that aren't being used (allocated_memory -  referenced_memory = garbage).  Once garbage has been identified we can safely free those unused blocks.  Unlike some mark-and-sweep garbage collectors Objeck does not manage a pre-allocated heap of memory instead it relies on the operating system to do so.  The memory managers call malloc and free to allocate and deallocate memory thus avoiding the need to manage a free list and compact memory (when fragmentation occurs).  

A future enhancement to the GC will be support for generational pools.  Depending upon the amount of memory freed during an observed number of collection cycles the memory allocation threshold is adjusted up or down to prevent thrashing.  This method of delegation has works well as modern operating systems (and C runtime libraries) maintain a wroking cache of free memory blocks.



Saturday, June 16, 2012

Finding and Fixing Bugs...

Spent the last two weeks in Beaverton, Oregon on a business trip so I had sometime to work on developing a web framework for Objeck.  During this process, 33% of my time was spent implementing the framework while 66% f my time was spent fixing undiscovered bugs and writing unit tests.  Running Objeck in an Apache container expose defects that were previously undiscovered.

The take away from this exercise is that exposing a runtime system to different execution environments is a good way to flush out bugs and learn about runtime characteristics such as memory footprint, garbage collection, execution speed, etc.  Implementing a web framework and stress testing the system using CLBG programs has been a rewarding exercise.