views:

542

answers:

5

I'd like to use a virtual machine like NekoVM into a small device but to build it, it requires Boehm GC, however there is no port of that GC to that small device so I was wondering if there is any alternative to it, something that could be done exclusively with C code?

+1  A: 

Perhaps you'd be better off with Lua, which has a very small but powerful virtual machine, has its own garbage collector built in, and runs on any platform that supports ANSI Standard C. With just a little effort you can even build Lua on a machine that lacks standard input and standard output. I have seen Lua running on an embedded device that was a small LCD touch screen with an embedded CPU stuck on the back. Neko is good work, but I think you'll find Lua every bit as satisfying.

Norman Ramsey
I am aware that Lua has its own garbage collector, but if you look into NekoVM they use libgc and do not a GC like Lua because it is not as good as libgc. I'm looking for a general purpose GC like libgc that i could replace on nekoVM
Paulo Lopes
Hans has literally spent more than 20 years improving libgc. It is not realistic to expect to find a drop-in replacement for a high-performance collector. It is also not sensible to expect high-performance GC on a small device. Your question asked for 'a VM like NekoVM'. Lua qualifies.
Norman Ramsey
Hans may have spent more than 20 years improving libgc but its performance is awful compared to most accurate garbage collectors.
Jon Harrop
+3  A: 

I'd say your best option would be to port the GC to your platform, for which there are instructions (libgc porting instructions).

Additionally, it should be possible to swap out the GC implementation (NekoVM FAQ), see vm/alloc.c file.

EDIT:

Hopefully useful additional links: (untested)

Hasturkun
+1  A: 

To support this there is a VMKit (LLVM) presentation where they show Boehm GC as a probable bottleneck for performance.

Paulo Lopes
Yeah, I would actually start using VMKit if they just had a better GC. The Boehm GC is just overly slow when you are running a safe language.
Zifre
@Zifre: FWIW, writing an accurate GC is really easy. The implementation I did in HLVM is only about 100 lines of code...
Jon Harrop
A: 

I could suggest TinyGC (tinygc.sf.net) - an independent lightweight implementation of the BoehmGC targeting small devices. It is fully API-compatible (even more, binary compatible) with BoehmGC v7+ but only a small subset of the API is implemented (but sufficient for Java/GCJ-like memory management) and there is no automatic threads and static data roots registration. The latter, however, may require some efforts to make NekoVM work with it (i.e., call GC_register_my_thread() and GC_add_roots()).

ivmai
A: 

My advice is to write an accurate GC for Neko if one does not already exist. I wouldn't touch Boehm's GC with a barge pole...

Jon Harrop