Closed Bug 1475226 Opened 6 years ago Closed 6 years ago

Use JSContext for malloc allocation rather than Zone where possible

Categories

(Core :: JavaScript: GC, enhancement)

61 Branch
enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla63
Tracking Status
firefox63 --- fixed

People

(Reporter: jonco, Assigned: jonco)

References

Details

Attachments

(1 file)

Both JSContext and Zone are MallocProviders and provide various pod_malloc style methods.  Currently we use the Zone ones in most places, but this has a few drawbacks:

 - it's different to GC thing allocation where we pass the context to indicate the zone
 - it doesn't report failure to the context which we want in most places
 - we have to call zone() on the context to get the Zone anyway

This patch makes most allocations use the context instead, which the exception of places where there isn't a current context (e.g. the GC) and long lived data structures associated with a Zone (e.g. a JS Map object).
Attachment #8991610 - Flags: review?(sphink)
Comment on attachment 8991610 [details] [diff] [review]
allocate-on-context

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

I can't argue with the number of lines removed by this patch!

The only thing that makes me nervous is whether the cx is in the right zone, but it looks like you've covered that in various places with asserts or AutoRealm.

::: js/src/gc/Allocator.cpp
@@ +110,5 @@
>                                 size_t nDynamicSlots)
>  {
>      HeapSlot* slots = nullptr;
>      if (nDynamicSlots) {
> +        slots = cx->maybe_pod_malloc<HeapSlot>(nDynamicSlots);

This one doesn't seem right. If CanGC, it would report OOM twice.

If NoGC, then it will now report OOM -- but ReportOutOfMemory(cx) cannot GC, so I'm not sure why that's a problem?

::: js/src/gc/Nursery-inl.h
@@ +114,5 @@
>  static inline T*
>  AllocateObjectBuffer(JSContext* cx, JSObject* obj, uint32_t count)
>  {
>      if (cx->helperThread())
> +        return cx->pod_malloc<T>(count);

Hm, it looks like this is a bugfix? It doesn't seem like it would have reported OOM before, but should.
Attachment #8991610 - Flags: review?(sphink) → review+
(In reply to Steve Fink [:sfink] [:s:] from comment #1)

> The only thing that makes me nervous is whether the cx is in the right zone,
> but it looks like you've covered that in various places with asserts

Oh, I actually meant to make those assertSameCompartment.  I'll update that.

> > +        slots = cx->maybe_pod_malloc<HeapSlot>(nDynamicSlots);
> 
> This one doesn't seem right. If CanGC, it would report OOM twice.

The 'maybe' versions don't report on failure, so this should have the same behaviour as before.

> Hm, it looks like this is a bugfix? It doesn't seem like it would have
> reported OOM before, but should.

Yes, this is a fix.
Pushed by jcoppeard@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/76de95da94dd
Use JSContext for malloc allocation rather than Zone where possible r=sfink
https://hg.mozilla.org/mozilla-central/rev/76de95da94dd
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla63
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: