Skip to content

VM-specific memory management #62

@maxcai314

Description

@maxcai314

Some of the goals of this project are to: (todo: those should probably be explicitly stated in the README)

  1. Allow VMs to be shut down at any time (by the scheduler, once all threads yield)
  2. 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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions