Multi-threaded VM
Last updated at 2:30 am UTC on 27 October 2007
The goal is to make the Interpreter multithreaded, while protecting ObjectMemory and Primitives with Semaphores. I have a quad-core chip and so I want 4 Interpreter threads. Only one of them can be inside of ObjectMemory at a time and that could be for purposes of allocation, mutation, or GC. It's possible that a simple mutex semaphore would suffice, initially. Ultimately, I don't think having a single ObjectMemory will scale to 10's of "processors", but will probably need to be multithreaded with one per Interpreter thread. For now it's 1 ObjectMemory and N Interpreters.
- Recruit for a 3 team approach: the Image Team, the VM Team and the CrossCompiler Team
- Discuss the target language(s) (C, C++, ...),
- Discuss the VM design
The Image Team
- Change the behaviour of ProcessorScheduler to behave in the same way as the multi-threaded VM. Currently code can assume that a lower priority process won't run while a higher priority process is busy; this assumption would no longer exist in the multi-threaded VM.
- Pick up several concurrency issues in the image.
The VM Team
- Duplicate Interpreter and ObjectMemory into MultithreadedInterpreter and ProtectedObjectMemory (why rename these? Just keep them in a separate package. -gulik). Create a new class, ProtectedPrimitives.
- Reassign functions to the appropriate classes. Primitives to ProtectedPrimitives, and so on. Change refs to variables in other classes into calls to accessors in other classes. Ditto function calls.
- Protect ProtectedObjectMemory and ProtectedPrimitives with Semaphores to guard against concurrent access.
- Implement a MultithreadedVMSimulator and simulate the new VM.
The CrossCompiler Team
- Understand CCodeGenerator and TParseNode hierarchy.
- Consider having retargetable CodeGeneration. The structure of the parse tree will be the same, reflecting an OO design, but the backend could use a visitor pattern, or something, to generate C++ or C or something else that is fast.
- Duplicate/Extend the CCodeGenerator and the TParseNode hierarchy to build from input classes and generate code.
- Cross-compile, compile and run