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

Add MMTKBuilder and allow all options to be set from command line #625

Merged
merged 14 commits into from
Jul 20, 2022

Conversation

qinsoon
Copy link
Member

@qinsoon qinsoon commented Jul 15, 2022

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:

@qinsoon
Copy link
Member Author

qinsoon commented Jul 19, 2022

binding-refs
OPENJDK_BINDING_REPO=qinsoon/mmtk-openjdk
OPENJDK_BINDING_REF=mmtk-builder
JIKESRVM_BINDING_REPO=qinsoon/mmtk-jikesrvm
JIKESRVM_BINDING_REF=mmtk-builder
V8_BINDING_REPO=qinsoon/mmtk-v8
V8_BINDING_REF=mmtk-builder

@qinsoon qinsoon changed the title Allow setting plan as command line options Add MMTKBuilder and allow all options to be set from command line Jul 19, 2022
@qinsoon qinsoon marked this pull request as ready for review July 19, 2022 06:49
@qinsoon qinsoon requested a review from wks July 19, 2022 06:49
Copy link
Collaborator

@wks wks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having MMTKBuilder to enable safe instantiation of MMTK is a significant improvement.

The main problem of this PR, I think, is the handling of Options. We previously used UnsafeCell because we update the options after MMTK is instantiated. With the builder introduced, it is safe to update options before instantiating MMTK. It is no longer necessary to use UnsafeCell.

src/mmtk.rs Outdated Show resolved Hide resolved
pub fn process<VM: VMBinding>(mmtk: &'static MMTK<VM>, name: &str, value: &str) -> bool {
unsafe { mmtk.options.process(name, value) }
pub fn process(builder: &MMTKBuilder, name: &str, value: &str) -> bool {
unsafe { builder.set_option(name, value) }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we remove UnsafeOptionsWrapper, this can be made safe. But the builder parameter will need to be &mut, which is reasonable because the MMTk instance has not been created, yet.

I suggest the mmtk-core define process and process_bulk that accept &mut MMTKBuilder. The binding should initialise MMTk using a single thread, or use Mutex<MMTKBuilder>.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made this change as well. I am using Mutex<MMTKBuilder>. As we still use lazy static variables for MMTK and we need the builder to initialize MMTK, we cannot have a non-static MMTKBuilder. We may need to find a better pattern for this.

Comment on lines 8 to 9
mmtk_set_heap_size(1024*1024*1024);
mmtk_gc_init();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mmtk_set_heap_size in the example may give the reader a false impression that the heap size can be changed during execution, which is not true. Without a concrete implementation as in dummyvm, the reader may not realise that it sets an option in the builder before creating an MMTk instance.

For the purpose of example, I think it is OK to keep the old code mmtk_gc_init(1024 * 1024 * 1024); because the C API doesn't have to correspond one-to-one with what memory_manager provides. Conceptually, a C function mmtk_gc_init could both set the option and create the instance. We can also change the name to mmtk_init or init_mmtk to avoid confusion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I changed it to mmtk_init(heap_size) (gc_init() is renamed to mmtk_init() -- I think it is a good idea, as it avoids the confusion with initialize_collection()). As for the C API, in this PR, I moved examples/mmtk.h to docs/header/mmtk.h. This is meant to be the canonical header, and the C signatures in the header tries to be one-to-one mapped from the Rust API. The DummyVM binding uses a header in vmbindings/dummyvm/api/mmtk.h, which is different from the canonical version.

vmbindings/dummyvm/src/api.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@wks wks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly good. Only some small problems.

examples/allocation_benchmark.c Outdated Show resolved Hide resolved
vmbindings/dummyvm/src/api.rs Outdated Show resolved Hide resolved
@@ -5,7 +5,7 @@

int main() {
volatile uint64_t * tmp;
mmtk_gc_init(1024*1024*1024);
mmtk_init(24*1024*1024);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is 24 (twenty four) megabytes, but the loop below attempted to allocate 800 megabytes of objects. Is this intentional? Did you mean 1024*1024*1024?

Copy link
Collaborator

@wks wks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow the plan to be set as a command-line flag
2 participants