Closed Bug 1251833 Opened 4 years ago Closed 4 years ago

Further simplify allocation from Arenas

Categories

(Core :: JavaScript: GC, defect)

defect
Not set

Tracking

()

RESOLVED FIXED
mozilla47
Tracking Status
firefox47 --- fixed

People

(Reporter: ehoogeveen, Assigned: ehoogeveen)

References

(Blocks 1 open bug)

Details

Attachments

(4 files, 7 obsolete files)

18.91 KB, patch
ehoogeveen
: review+
Details | Diff | Splinter Review
7.24 KB, patch
ehoogeveen
: review+
Details | Diff | Splinter Review
128.70 KB, patch
ehoogeveen
: review+
Details | Diff | Splinter Review
6.97 KB, patch
terrence
: review+
Details | Diff | Splinter Review
Separating this from bug 1250634 since that's a pretty involved change and I don't want to drag it out. I have some more ideas for how to simplify this; in particular, it would be nice to merge ArenaHeader into Arena, since the separation serves no real purpose. This does require some prep work however, even after bug 1250634.
Note to self: Remember to move ArenaCellIterImpl's init() into the constructor.
This patch doesn't really make anything better on its own, but it lays the last groundwork needed to get rid of ArenaHeader. It moves allocation into FreeSpan and moves it up to the top of ArenaHeader so we no longer have to worry about offsets (and can just use |this| with a few debug asserts). Our placeholder is now a FreeSpan instead of an ArenaHeader ;)
Attachment #8724497 - Flags: review?(terrence)
Moving init() into the constructor didn't work out, because we actually can't always know what arena to use during construction. Instead I cleaned up all the iterators a bit, allowing you the consumer to choose between initializing during construction, or initializing later. However, nothing actually uses this - so aside from a bit of a cleanup, and making the assertions more consistent, this patch does nothing but make things slightly more complicated. I think it's still barely an improvement, but I'll let you make the call.
Attachment #8724498 - Flags: review?(terrence)
And the main patch for this bug. Sorry about the size, I thought too late about a way to split it up a little (but it wouldn't have improved it much). This is almost all code motion, s/ArenaHeader/Arena/ and s/aheader/arena/, but there are a few places where we previously accessed ArenaHeaders through Arenas, which is no longer needed. There should be nothing that changes behavior, but I touched up a few functions and extended a few comments (rewrapped a few others).

With this, we only have 2 classes involved in Arena allocation: Arena and FreeSpan. I think this is optimal: reducing it to just Arena would lead to a lot of open coding for the offsets, and I can't think of any step that would be simplified by adding a 3rd class. The only wrinkle is that with no ArenaHeader class, the header size is less well defined; I added a constant (ArenaHeaderSize - they're still header fields of Arena, after all) to HeapAPI.h to get around this.
Attachment #8724500 - Flags: review?(terrence)
The unused variable warning bites me again. I'll just reupload these while no one is looking :P
Attachment #8724497 - Attachment is obsolete: true
Attachment #8724497 - Flags: review?(terrence)
Attachment #8724502 - Flags: review?(terrence)
Attachment #8724500 - Attachment is obsolete: true
Attachment #8724500 - Flags: review?(terrence)
Attachment #8724503 - Flags: review?(terrence)
Removes an ill-conceived change from part 2 that introduced 4 hazards.
Attachment #8724498 - Attachment is obsolete: true
Attachment #8724498 - Flags: review?(terrence)
Attachment #8724537 - Flags: review?(terrence)
Comment on attachment 8724502 [details] [diff] [review]
Part 1: Move allocation into FreeSpan and move firstFreeSpan to the top of Arenas.

Review of attachment 8724502 [details] [diff] [review]:
-----------------------------------------------------------------

Wow, this is starting to actually read like an allocator!

::: js/src/jsgc.h
@@ +593,5 @@
>       * update the arena header after the initial allocation. When starting the
>       * GC we only move the head of the of the list of spans back to the arena
>       * only for the arena that was not fully allocated.
>       */
> +    AllAllocKindArray<FreeSpan*> freeLists;

\o/
Attachment #8724502 - Flags: review?(terrence) → review+
Comment on attachment 8724537 [details] [diff] [review]
Part 2: Clean up the various iterators a bit.

Review of attachment 8724537 [details] [diff] [review]:
-----------------------------------------------------------------

This is a huge improvement, ship it.
Attachment #8724537 - Flags: review?(terrence) → review+
Comment on attachment 8724503 [details] [diff] [review]
Part 3: Merge ArenaHeader into Arena.

Review of attachment 8724503 [details] [diff] [review]:
-----------------------------------------------------------------

This is even more awesome than I thought it would be.

::: js/src/gc/GCRuntime.h
@@ +1176,5 @@
>  
>      /*
>       * List head of arenas allocated during the sweep phase.
>       */
> +    js::gc::Arena* arenasAllocatedDuringSweep;

I think also remove the js::gc:: while you're here as it's not used elsewhere in the class. I'd guess it is from the days when all this was directly on the JSRuntime.

::: js/src/gc/Heap.h
@@ +416,5 @@
> + * +---------------+---------+----+----+-----+----+
> + * | header fields | padding | T0 | T1 | ... | Tn |
> + * +---------------+---------+----+----+-----+----+
> + * <-------------------------> = first thing offset
> + */

Great! It's much more effective to have this right at the top.

@@ +428,5 @@
> +     * The first span of free things in the arena. Most of these spans are
> +     * stored as offsets in free regions of the data array, and most operations
> +     * on FreeSpans take an Arena pointer for safety. However, the FreeSpans
> +     * used for allocation are stored here, at the start of an Arena, and use
> +     * their own address to grab the next span within the same Arena.

\o/ Full of win!

::: js/src/gc/Marking.cpp
@@ +1942,2 @@
>  {
> +    DispatchTraceKindTyped(PushArenaFunctor(), 

Remove the whitespace at the end of this line.
Attachment #8724503 - Flags: review?(terrence) → review+
Carrying forward r+ - updated to match the latest patch in bug 1250634.
Attachment #8724502 - Attachment is obsolete: true
Attachment #8724862 - Flags: review+
Carrying forward r+ - updated to match the latest patch in bug 1250634.
Attachment #8724537 - Attachment is obsolete: true
Attachment #8724863 - Flags: review+
Carrying forward r+ - updated to match the latest patch in bug 1250634.

Thanks for the fast reviews!

(In reply to Terrence Cole [:terrence] from comment #11)
> > +    js::gc::Arena* arenasAllocatedDuringSweep;
> 
> I think also remove the js::gc:: while you're here as it's not used
> elsewhere in the class. I'd guess it is from the days when all this was
> directly on the JSRuntime.

Bonus patch incoming.

> ::: js/src/gc/Marking.cpp
> @@ +1942,2 @@
> >  {
> > +    DispatchTraceKindTyped(PushArenaFunctor(), 
> 
> Remove the whitespace at the end of this line.

Always one. Fixed!
Attachment #8724503 - Attachment is obsolete: true
Attachment #8724866 - Flags: review+
As discussed on IRC. This compiles for me locally, but I'll send it off to try to make sure it doesn't magically break the build somewhere.
Attachment #8724867 - Flags: review?(terrence)
Comment on attachment 8724867 [details] [diff] [review]
Part 4: Remove some unneeded qualification from GCRuntime and friends.

Er, hold off, this broke everything.
Attachment #8724867 - Attachment is obsolete: true
Attachment #8724867 - Flags: review?(terrence)
js::GCHelperState needed the qualification to be marked as a friend class. MSVC didn't care. Hopefully that's all it needs:

https://treeherder.mozilla.org/#/jobs?repo=try&revision=62684449db41
Attachment #8724882 - Flags: review?(terrence)
Comment on attachment 8724882 [details] [diff] [review]
Part 4 v2: Remove some unneeded qualification from GCRuntime and friends.

Review of attachment 8724882 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks!
Attachment #8724882 - Flags: review?(terrence) → review+
Status: NEW → ASSIGNED
Keywords: checkin-needed
Blocks: 1192301
You need to log in before you can comment on or make changes to this bug.