Skip to content

Refactor Garbage Collector to Use VM-Instance State #39

Open

Description

@mukeshv-tech

Priority: P0 – High
Area: Runtime / Memory Management
File: src/runtime/gc.c

Problem

The garbage collector relies heavily on the global VM vm instance.

Functions such as reallocate(), markRoots() and collectGarbage() operate on global VM state, even when a VM pointer is provided.

This creates architectural limitations for multiple VM instances, embedding ProXPL into other applications and potentially supporting independent execution contexts.

Proposed Solution

  • Move GC state and allocation tracking into the VM instance.
  • Pass the relevant VM pointer through allocation and collection functions.
  • Ensure root marking uses the correct VM.
  • Remove unnecessary global VM dependencies.
  • Define clear ownership rules for allocated objects.

Tests

  • Create two VM instances and allocate objects in both.
  • Trigger collection in one VM and verify the other remains unaffected.
  • Test closures, globals, stack roots and open upvalues.
  • Run stress-GC tests.
  • Run AddressSanitizer and UndefinedBehaviorSanitizer tests.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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