Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor scheduler #532

Closed
3 tasks done
wks opened this issue Jan 29, 2022 · 1 comment
Closed
3 tasks done

Refactor scheduler #532

wks opened this issue Jan 29, 2022 · 1 comment
Assignees
Labels
A-interface Area: Interface/API A-work-queue Area: Work queue C-refactoring Category: Refactoring P-normal Priority: Normal.

Comments

@wks
Copy link
Collaborator

wks commented Jan 29, 2022

TODO list

Problem

Currently, the GCWorkScheduler serves multiple purposes.

  1. It owns the GCWorker for the GC controller thread. This part should be owned by the GC controller thread.
  2. It serves as the communication hub between mutators, the controller and workers.
    • Mutators may add work packets in write barrier.
    • workers poll work from the scheduler
    • the controller queries worker states, and also get coordinator work from the scheduler
      This part should be shared between threads.

On the other hand, there is currently no "context" object for the GC controller thread.

  • ControllerCollectorContext contains the run() method for the GC controller, but it also serves as the communication hub for triggering GC.
  • It depends on the GCWorker in the scheduler. It spends most of its lifetime in GCWorkScheduler::wait_for_completion. Even its communication channel is owned by GCWorkScheduler.channel.1.

And the ControllerCollectorContext -- which apparently has nothing to do with a "plan" --** is buried deep inside mmtk.plan.base().controller_collector_context**. We consider a "plan" to be a description of a GC algorithm, but BasePlan holds mostly the global GC states. Understandably, the controller thread itself is one of such global state, but it is really plan-agnostic.

The initialisation process is complicated. When initialising, all GC algorithms pass a scheduler object to the init() function of the ControllerCollectorContext. GCWorkScheduler also uses many Option<T> fields and initializes itself unsafely.

These phenomena are a result of porting MMTk from Java to Rust. Java's programming style promotes shared states and inter-referenced objects, while Rust emphasises ownership. This requires us to think more carefully about the ownership of data.

Goal

The goal is to ensure each thread owns the data that it accesses exclusively, and ensure shared data are properly identified, shared and synchronised. Threads we concern include:

  • The GC controller
  • GC workers (already fixed)

Mutators and VM-specific non-mutator threads (such as OpenJDK's "VM Thread") are not part of our concern.

Data structures we concern include:

  • ControllerCollectorContext
  • GCWorkScheduler
  • MMTK
@wks
Copy link
Collaborator Author

wks commented Nov 22, 2023

PR #949 moved the reference of GCRequester from BasePlan to the MMTK struct, solving the last TODO item. We are closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-interface Area: Interface/API A-work-queue Area: Work queue C-refactoring Category: Refactoring P-normal Priority: Normal.
Projects
None yet
Development

No branches or pull requests

2 participants