-
Notifications
You must be signed in to change notification settings - Fork 68
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
Refactoring MMTK instantiation #541
Comments
This sounds good. And we have multiple issues tracking this or related issues: Here are some of my thoughts:
|
PS I think this should be allowed (at least for certain options -- maybe not all). I ran into this while I was working on the nursery space refactoring. In the original JikesRVM, MMTk temporarily sets the "force full heap gc" to true to force generational plans to perform a full heap GC in |
This PR adds `MMTKBuilder`, and changes APIs around initializing MMTk. The change allows all the options to be set from command line, including heap size, plan, GC threads, etc. This PR closes #623. This PR is also an initial step for #541. For #541, we may need further changes. * Add `MMTKBuilder` * `gc_init()` now takes a reference to `MMTKBuilder` as its argument, and returns a boxed pointer to the new MMTk instance created. * `gc_init()` is renamed to `mmtk_init()`. * `gc_init()` no longer requires a `heap_size` argument. `heap_size` now is an option. * allow options for `plan`, `threads`, `vm_space_size` to be set by command line * move `examples/mmtk.h` to `docs/header/mmtk.h`. Building C code in `examples` no longer uses this header file. Related PRs: * mmtk/mmtk-openjdk#166 * mmtk/openjdk#12 * mmtk/mmtk-jikesrvm#118 * mmtk/mmtk-v8#64
With We still have not managed to allow multiple MMTk instances in one process. Let's track that in a different issue, and close this one.
|
Problem
Currently, the
MMTK
instance is usually created statically.The practice of using static singletons is https://github.com/mmtk/mmtk-core/issues/58brought from Java JikesRVM, but this is not idiomatic in Rust. Such practice forced two-phase initialisation and forced bad and unsafe practices, including:
Option<T>
for late-initialised fields, and force casting&
to&mut
to initialise shared data.MMTK::options
is anUnsafeOptionsWrapper
, allowing unsafe update to the shared "supposedly-immutable"MMTK
singleton.MMTKBuilder
that creates anMMTK
instance with immutableoptions
field.SFTMap
,VMMap
andMmapper
. Making MMTK a static singleton makes such dependencies hard to manage.static
oflazy_static!
, butMMTK
is created after them. Therefore the dependencies are clearer.Sub-issues:
Related issues:
Proposal
Introduce a
MMTKBuilder
type that builds theMMTK
instance.Following the convention of some builder types in the Rust standard library, such as
std::thread::Builder
andstd::fs:DirBuilder
, theMMTKBuilder
should be used like the following:The
MMTKBuilder
should contain mutable fields so that the user can specify options gradually. But once theMMTK
instance is created, the options will be read-only. This meansUnsafeOptionWrapper
will no longer be necessary.By the time
MMTKBuilder.create()
is called, the options should contain all relevant information to create and initialise plans. Because of this, thegc_init
methods of many types (such asPlan
,Space
, etc.) may no longer be necessary, and can be replaced by anew
method.Q/A
Could options be changed at run time? If any options can be changed at run time, it will need proper synchronisation, and the changes to such options must be timely notified to related components. For example, if it is allowed to adjust the number of GC threads at run time, the GC controller thread should be notified about this change, and spawn/kill threads at appropriate time.
The text was updated successfully, but these errors were encountered: