-
Notifications
You must be signed in to change notification settings - Fork 119
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
Hook spidermonkey into rust's allocator #72
Conversation
$(SRC_DIR)/mozjs/js/src/configure $(strip $(CONFIGURE_FLAGS)) | ||
cd $(OUT_DIR) && make -f Makefile -j$(NUM_JOBS) | ||
endif | ||
|
||
LDFLAGS := $(OUT_DIR)/fake_rustalloc.o | ||
$(OUT_DIR)/fake_rustalloc.o: rust_mem/fake_rustalloc.cpp | ||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $< -o $@ -c |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do we link this to Rust's jemalloc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't - this is only used to make standalone binaries link successfully in SM. Otherwise, tests and js shell don't link.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So when will things link to Rust's jemalloc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To elaborate a bit more - fake_rustalloc is used for linking C++ binaries that are only used for testing. These binaries are built by SM using a C++ compiler. In these cases, fake_rustalloc just hooks these binaries up to the system allocator. In normal cases however, fake_rustalloc isn't used and rustc properly links SM against rust's allocator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so the cpp and header file below are only used for testing? In case we're using rustc, it will automatically link against jemalloc's malloc
/calloc
/realloc
symbols? Sounds good.
So what's the situation right now? If the linking happens in the final link step, why is SM not using jemalloc (which is being linked against) now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SM is currently using js_malloc/js_realloc/js_free, which redirects to the system malloc/realloc/free. Rust's copy of jemalloc uses je_malloc/jerealloc/je_free naming, so it doesn't automatically override other allocators.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(figured it out after chatting in IRC; only fake_rustalloc is for testing, jscustomallocator is not)
r=me once @asajeffrey gets a chance to play with it |
I'll have a look at this tomorrow. |
Oh okay, maybe the day after tomorrow. |
Got a segfault (posted to irc, crossposting here for posterity):
|
It turns out the allocator API that rust exposes and the one SM wants are more incompatible than expected. Going to see if I can make the SM allocator API fully sized. If so, we can come back to hooking SM into Rust's allocator after the next smup. |
rust-lang/rust#31976 adds support for unsized deallocation. |
@michaelwu - has this gone stale? Will it be finished? |
@perlun I believe that @michaelwu will not be continuing work on this. I would love it if someone saw this through to completion though. |
@metajack - alright. I don't think I feel confident about doing it (yet), but maybe it would be worth for you to enumerate what you believe to be the remaining steps? So someone could more easily bring it forward. |
@perlun I think the first step is to check if the Rust landscape changed since this was opened.
and later
Is that still true or likely to change soon? Maybe the first thing to do to answer those question is to write down what this API is on the SM side so we can starting discussing how to get there. |
From #61:
I find this really surprising since the GC allocates in 2MiB chunks and then uses its own allocator, but I suppose there is still a lot of vm code that is using normal malloc. Anyways, I haven't read through this backlog, but here is the status WRT allocators for my current smup work. I ported from the custom makefile majiggery to using I can look into sharing the same jemalloc some more once I complete the smup. |
And array elements are backed by direct mallocs as well, and that seems to be the case that the benchmark is hitting. |
Many things changed since 2016, on both SpiderMonkey and Rust sides, closing this because I don't think it can be salvaged. |
This is the alternative to #61 . Rust doesn't quite provide all the APIs necessary to do this fully - there is no calloc equivalent, but it's probably fine in most cases.
fake_rustalloc is provided to link the js shell and tests, but isn't used anywhere else.
@asajeffrey - do you mind seeing if this works as well as turning on jemalloc?
r? @Manishearth