-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Some of the goals of this project are to: (todo: those should probably be explicitly stated in the README)
- Allow VMs to be shut down at any time (by the scheduler, once all threads yield)
- Allow multiple VMs to be spawned from the same process
By extension, this must mean that all heap allocations by any given VM can be tracked and appropriately freed during shutdown, to avoid memory leaks.
With the current async system, it becomes extremely difficult to implicitly remember to keep track of all our allocations, by enforcing that all allocations are tracked somewhere on the VM outside of the current async scope, and that they only get freed exactly once.
Since raw malloc operations are actually fairly rare in our system, we can implement the following solution without a major performance hit, while guaranteeïng ease of use:
void *vm_malloc(bjvm_vm *vm, size_t __size) {
// normal malloc, but you just push to a set of things that this VM is responsible for
}
void vm_free(bjvm_vm *vm, void *data) {
// normal free, but also remove it from the set of things owned by this VM
}This allows us to easily interoperate between implementations that use a raw malloc call for all allocations, or create a specific VM heap (if we want to ever restrict the amount of memory a VM has).