Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upHook 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 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
michaelwu
Feb 12, 2016
Author
Contributor
We don't - this is only used to make standalone binaries link successfully in SM. Otherwise, tests and js shell don't link.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
michaelwu
Feb 12, 2016
Author
Contributor
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.
This comment has been minimized.
This comment has been minimized.
Manishearth
Feb 12, 2016
Member
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?
This comment has been minimized.
This comment has been minimized.
michaelwu
Feb 12, 2016
Author
Contributor
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.
This comment has been minimized.
This comment has been minimized.
Manishearth
Feb 12, 2016
Member
(figured it out after chatting in IRC; only fake_rustalloc is for testing, jscustomallocator is not)
| static inline void* js_calloc(size_t bytes) | ||
| { | ||
| void* buf = __rust_allocate(bytes, 0); | ||
| if (bytes && buf) { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
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. |
perlun
commented
May 31, 2016
|
@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. |
perlun
commented
Jun 1, 2016
|
@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. |
tschneidereit
commented
Dec 23, 2016
|
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. |
michaelwu commentedFeb 12, 2016
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