Last Comment Bug 727202 - GeckoAppShell.allocateDirectBuffer and freeDirectBuffer don't use jemalloc to allocate/free buffers
: GeckoAppShell.allocateDirectBuffer and freeDirectBuffer don't use jemalloc to...
Status: RESOLVED FIXED
:
Product: Core
Classification: Components
Component: mozglue (show other bugs)
: unspecified
: ARM Android
: -- normal (vote)
: mozilla13
Assigned To: Mike Hommey [:glandium]
:
Mentors:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-02-14 12:22 PST by Brad Lassey [:blassey] (use needinfo?)
Modified: 2012-02-17 05:45 PST (History)
3 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
Wrap malloc and free to use jemalloc in GeckoAppShell.{allocate,free}DirectBuffer (1.09 KB, patch)
2012-02-15 07:59 PST, Mike Hommey [:glandium]
blassey.bugs: review+
Details | Diff | Review

Description Brad Lassey [:blassey] (use needinfo?) 2012-02-14 12:22:28 PST
I noticed this issue when working on bug 726930 because my code malloc'd the buffer directly then called GeckoAppShell.freeDirectBuffer() to free it and that crashed because of the mismatched allocator.
Comment 1 Mike Hommey [:glandium] 2012-02-15 07:54:25 PST
Sadly, generalization can't be done in mozglue, because some things that we free() are allocated by the android libc. So in the end, this will need to be a localized fix.
Comment 2 Mike Hommey [:glandium] 2012-02-15 07:59:57 PST
Created attachment 597412 [details] [diff] [review]
Wrap malloc and free to use jemalloc in GeckoAppShell.{allocate,free}DirectBuffer
Comment 3 Brad Lassey [:blassey] (use needinfo?) 2012-02-15 11:54:01 PST
Comment on attachment 597412 [details] [diff] [review]
Wrap malloc and free to use jemalloc in GeckoAppShell.{allocate,free}DirectBuffer

Mike, I think I'd slightly prefer using the --wrap flags so nothing else allocates using the standard allocators. Is there any reason not to do that?
Comment 4 Mike Hommey [:glandium] 2012-02-15 13:28:39 PST
One reason is that --wrap only works when the wrapped function is in an external library. mozglue/android and jemalloc are in the same library.
The other reason is in comment 1.
Comment 5 Brad Lassey [:blassey] (use needinfo?) 2012-02-15 14:11:21 PST
(In reply to Mike Hommey [:glandium] from comment #4)
> One reason is that --wrap only works when the wrapped function is in an
> external library. mozglue/android and jemalloc are in the same library.
> The other reason is in comment 1.

Right, I failed to read comment 1 before commenting. So, ignore comment 3.
Comment 6 Mike Hommey [:glandium] 2012-02-15 23:42:34 PST
Not that eventually, mozalloc will be folded in mozglue, at which point using operator new and delete in mozglue will use jemalloc. When that happens, we can remove this hack and replace malloc and free with new and delete.
Comment 7 Mike Hommey [:glandium] 2012-02-15 23:42:53 PST
(In reply to Mike Hommey [:glandium] from comment #6)
> Not that eventually,(...)

Note, not not
Comment 9 Ed Morley [:emorley] 2012-02-17 05:45:03 PST
https://hg.mozilla.org/mozilla-central/rev/7e90fe61000f

Note You need to log in before you can comment on or make changes to this bug.