[virtmach] Threaded vs Bytecode VM

Stephen Pelc sfp@mpeltd.demon.co.uk
Thu, 20 Apr 2000 12:16:02 +0100


> What are the tradeoffs of using a threaded vs bytecoded VM?  Certainly
> there is the initial stage of translating the BCs into threaded
> instructions, but that's a once-off cost.  Maybe a larger memory footprint
> to hold the threaded instructions and, being pointers the impact would only
> get worse on on 64bit architectures.   Anything else?

We've implemented VMs with
a) interpreters
b) translation to threaded
c) direct compilation

My observations are all from stack-based VMs hosted on 
processors ranging from 8051, 68xxx, H8/300H, ARM/StrongARM and 
Pentium. The applications for these VMs have been written in C, 
Forth, and VM assembler.

>From a performance/size point of view, translation (b) is rarely 
worthwhile. Interpretation requires lots of look-up tables if 
you use multi-byte opcodes. Interpreters will probably give half 
the performance of a threaded system, and compilation will give 
very much better run-time performance. If you use full blown 
compilation (c), the performance can be 30 times that of 
interpretation (a). Properly optimising compilation can produce 
code that is less than 10-20% larger than threaded code, and 
sometimes smaller, depending of course on the VM architecture 
and target CPU.

Which you choose will depend very heavily on the application 
area. If you run a lot of one-shot applications, the compilation 
time may exceed the run time.

--
Stephen Pelc, sfp@mpeltd.demon.co.uk
MicroProcessor Engineering Ltd - More Real, Less Time
133 Hill Lane, Southampton SO15 5AF, England
tel: +44 1703 631441, fax: +44 1703 339691
web: http://www.mpeltd.demon.co.uk