Last Comment Bug 820132 - New DMD reports that some image allocs are unreported
: New DMD reports that some image allocs are unreported
Status: RESOLVED FIXED
[MemShrink:P2]
:
Product: Core
Classification: Components
Component: ImageLib (show other bugs)
: Trunk
: ARM Gonk (Firefox OS)
: -- normal with 1 vote (vote)
: mozilla20
Assigned To: Nicholas Nethercote [:njn]
:
Mentors:
Depends on:
Blocks: DarkMatter
  Show dependency treegraph
 
Reported: 2012-12-10 13:41 PST by Justin Lebar (not reading bugmail)
Modified: 2012-12-20 13:44 PST (History)
5 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
Measure imgFrame::mOptSurface's size where possible, instead of calculating it. (4.39 KB, patch)
2012-12-18 19:16 PST, Nicholas Nethercote [:njn]
no flags Details | Diff | Splinter Review
Measure imgFrame::mOptSurface's size where possible, instead of calculating it. (4.39 KB, patch)
2012-12-18 21:59 PST, Nicholas Nethercote [:njn]
joe: review+
justin.lebar+bug: feedback+
Details | Diff | Splinter Review

Description Justin Lebar (not reading bugmail) 2012-12-10 13:41:29 PST
In the main B2G process with the gallery app open (see attachment 690543 [details]), I see:

> Unreported: ~16 blocks in block group 2 of 533
>  ~1,536,000 bytes (~1,518,728 requested / ~17,272 slop)
>  6.36% of the heap (14.95% cumulative);  12.53% of unreported (29.44% cumulative)
>  Allocated at
>        malloc /Users/jlebar/code/moz/ff-git/src/memory/build/replace_malloc.c:152 (0x4020b2ae libmozglue.so+0x42ae)
>        moz_malloc /Users/jlebar/code/moz/ff-git/src/memory/mozalloc/mozalloc.cpp:65 (0x40e5adf2 libxul.so+0xc37df2)
>        gfxImageSurface /Users/jlebar/code/moz/ff-git/src/gfx/thebes/gfxImageSurface.cpp:110 (0x419ae7b6 libxul.so+0xa877b6)
>        nsRefPtr<gfxASurface>::assign_with_AddRef(gfxASurface*) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsAutoPtr.h:846 (0x419c3ac0 libxul.so+0xa9cac0)
>        gfxPlatform::OptimizeImage(gfxImageSurface*, gfxASurface::gfxImageFormat) /Users/jlebar/code/moz/ff-git/src/gfx/thebes/gfxPlatform.cpp:464 (0x419bbbe4 libxul.so+0xa94be4)
>        nsRefPtr<gfxASurface>::assign_assuming_AddRef(gfxASurface*) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsAutoPtr.h:861 (0x4126637a libxul.so+0x33f37a)
>        mozilla::image::RasterImage::DecodingComplete() /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsError.h:155 (0x41261f3a libxul.so+0x33af3a)
>        nsCOMPtr<imgIDecoderObserver>::get() const /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsCOMPtr.h:764 (0x4125fa90 libxul.so+0x338a90)
>        mozilla::image::nsPNGDecoder::end_callback(png_struct_def*, png_info_def*) /Users/jlebar/code/moz/ff-git/src/image/decoders/nsPNGDecoder.cpp:860 (0x4126f3fe libxul.so+0x3483fe)
>        MOZ_PNG_push_have_end /Users/jlebar/code/moz/ff-git/src/media/libpng/pngpread.c:1454 (0x40e35ce6 libxul.so+0xc12ce6)
>        MOZ_PNG_push_read_chunk /Users/jlebar/code/moz/ff-git/src/media/libpng/pngpread.c:358 (0x40e36824 libxul.so+0xc13824)
>        MOZ_PNG_proc_some_data /Users/jlebar/code/moz/ff-git/src/media/libpng/pngpread.c:122 (0x40e36a72 libxul.so+0xc13a72)
>        MOZ_PNG_process_data /Users/jlebar/code/moz/ff-git/src/media/libpng/pngpread.c:38 (0x40e36ac0 libxul.so+0xc13ac0)
>        mozilla::image::nsPNGDecoder::WriteInternal(char const*, unsigned int) /Users/jlebar/code/moz/ff-git/src/image/decoders/nsPNGDecoder.cpp:352 (0x4056b2da libxul.so+0x3482da)
>        mozilla::image::Decoder::Write(char const*, unsigned int) /Users/jlebar/code/moz/ff-git/src/image/src/Decoder.cpp:80 (0x4055b9c0 libxul.so+0x3389c0)
>        mozilla::image::RasterImage::WriteToDecoder(char const*, unsigned int) /Users/jlebar/code/moz/ff-git/src/image/src/RasterImage.cpp:2649 (0x4055d976 libxul.so+0x33a976)
>        mozilla::image::RasterImage::DecodeSomeData(unsigned int) /Users/jlebar/code/moz/ff-git/src/image/src/RasterImage.cpp:3168 (0x4055da0c libxul.so+0x33aa0c)
>        mozilla::image::RasterImage::DecodeWorker::DecodeSomeOfImage(mozilla::image::RasterImage*, mozilla::image::RasterImage::DecodeWorker::DecodeType) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsError.h:155 (0x4055e172 libxul.so+0x33b172)
>        mozilla::image::RasterImage::DecodeWorker::DecodeUntilSizeAvailable(mozilla::image::RasterImage*) /Users/jlebar/code/moz/ff-git/src/image/src/RasterImage.cpp:3429 (0x4055e2c8 libxul.so+0x33b2c8)
>        mozilla::image::RasterImage::SourceDataComplete() /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsError.h:155 (0x4055f32e libxul.so+0x33c32e)
>        imgRequest::OnStopRequest(nsIRequest*, nsISupports*, tag_nsresult) /Users/jlebar/code/moz/ff-git/src/image/src/imgRequest.cpp:656 (0x40567202 libxul.so+0x344202)
>        ProxyListener::OnStopRequest(nsIRequest*, nsISupports*, tag_nsresult) /Users/jlebar/code/moz/ff-git/src/image/src/imgLoader.cpp:2063 (0x405628b4 libxul.so+0x33f8b4)
>        nsCOMPtr<nsIStreamListener>::operator=(nsIStreamListener*) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsCOMPtr.h:624 (0x40542c76 libxul.so+0x31fc76)
>        nsCOMPtr<nsIStreamListener>::operator=(nsIStreamListener*) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsCOMPtr.h:624 (0x404ad460 libxul.so+0x28a460)
Comment 1 Justin Lebar (not reading bugmail) 2012-12-10 13:45:33 PST
Also the following trace, which I suspect is the same.

> Unreported: 1 block in block group 6 of 533
>  614,400 bytes (614,400 requested / 0 slop)
>  2.55% of the heap (27.36% cumulative);  5.01% of unreported (53.86% cumulative)
>  Allocated at
>        malloc /Users/jlebar/code/moz/ff-git/src/memory/build/replace_malloc.c:152 (0x4020b2ae libmozglue.so+0x42ae)
>        moz_malloc /Users/jlebar/code/moz/ff-git/src/memory/mozalloc/mozalloc.cpp:65 (0x40e5adf2 libxul.so+0xc37df2)
>        gfxImageSurface /Users/jlebar/code/moz/ff-git/src/gfx/thebes/gfxImageSurface.cpp:110 (0x419ae7b6 libxul.so+0xa877b6)
>        nsRefPtr<gfxASurface>::assign_with_AddRef(gfxASurface*) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsAutoPtr.h:846 (0x419c3ac0 libxul.so+0xa9cac0)
>        gfxPlatform::OptimizeImage(gfxImageSurface*, gfxASurface::gfxImageFormat) /Users/jlebar/code/moz/ff-git/src/gfx/thebes/gfxPlatform.cpp:464 (0x419bbbe4 libxul.so+0xa94be4)
>        nsRefPtr<gfxASurface>::assign_assuming_AddRef(gfxASurface*) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsAutoPtr.h:861 (0x4126637a libxul.so+0x33f37a)
>        mozilla::image::RasterImage::DecodingComplete() /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsError.h:155 (0x41261f3a libxul.so+0x33af3a)
>        nsCOMPtr<imgIDecoderObserver>::get() const /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsCOMPtr.h:764 (0x4125fa90 libxul.so+0x338a90)
>        mozilla::image::nsPNGDecoder::end_callback(png_struct_def*, png_info_def*) /Users/jlebar/code/moz/ff-git/src/image/decoders/nsPNGDecoder.cpp:860 (0x4126f3fe libxul.so+0x3483fe)
>        MOZ_PNG_push_have_end /Users/jlebar/code/moz/ff-git/src/media/libpng/pngpread.c:1454 (0x40e35ce6 libxul.so+0xc12ce6)
>        MOZ_PNG_push_read_chunk /Users/jlebar/code/moz/ff-git/src/media/libpng/pngpread.c:358 (0x40e36824 libxul.so+0xc13824)
>        MOZ_PNG_proc_some_data /Users/jlebar/code/moz/ff-git/src/media/libpng/pngpread.c:122 (0x40e36a72 libxul.so+0xc13a72)
>        MOZ_PNG_process_data /Users/jlebar/code/moz/ff-git/src/media/libpng/pngpread.c:38 (0x40e36ac0 libxul.so+0xc13ac0)
>        mozilla::image::nsPNGDecoder::WriteInternal(char const*, unsigned int) /Users/jlebar/code/moz/ff-git/src/image/decoders/nsPNGDecoder.cpp:352 (0x4056b2da libxul.so+0x3482da)
>        mozilla::image::Decoder::Write(char const*, unsigned int) /Users/jlebar/code/moz/ff-git/src/image/src/Decoder.cpp:80 (0x4055b9c0 libxul.so+0x3389c0)
>        mozilla::image::RasterImage::WriteToDecoder(char const*, unsigned int) /Users/jlebar/code/moz/ff-git/src/image/src/RasterImage.cpp:2649 (0x4055d976 libxul.so+0x33a976)
>        mozilla::image::RasterImage::DecodeSomeData(unsigned int) /Users/jlebar/code/moz/ff-git/src/image/src/RasterImage.cpp:3168 (0x4055da0c libxul.so+0x33aa0c)
>        mozilla::image::RasterImage::DecodeWorker::DecodeSomeOfImage(mozilla::image::RasterImage*, mozilla::image::RasterImage::DecodeWorker::DecodeType) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsError.h:155 (0x4055e172 libxul.so+0x33b172)
>        mozilla::image::RasterImage::DecodeWorker::DecodeABitOf(mozilla::image::RasterImage*) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsAutoPtr.h:1005 (0x4055e414 libxul.so+0x33b414)
>        ~SamplerStackFramePrintfRAII /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/sps_sampler.h:221 (0x4126296c libxul.so+0x33b96c)
>        mozilla::image::RasterImage::StartDecoding() /Users/jlebar/code/moz/ff-git/src/image/src/RasterImage.cpp:2706 (0x41260314 libxul.so+0x339314)
>        imgRequest::StartDecoding() /Users/jlebar/code/moz/ff-git/src/image/src/imgRequest.cpp:538 (0x4126a87e libxul.so+0x34387e)
>        imgRequestProxy::StartDecoding() /Users/jlebar/code/moz/ff-git/src/image/src/imgRequestProxy.cpp:361 (0x4126d27e libxul.so+0x34627e)
>        nsStyleImage::StartDecoding() const /Users/jlebar/code/moz/ff-git/src/layout/style/nsStyleStruct.cpp:1618 (0x41352b42 libxul.so+0x42bb42)
Comment 2 Justin Lebar (not reading bugmail) 2012-12-10 13:54:53 PST
> Unreported: 1 block in block group 8 of 533
>  307,200 bytes (307,200 requested / 0 slop)
>  1.27% of the heap (30.80% cumulative);  2.51% of unreported (60.64% cumulative)
>  Allocated at
>        malloc /Users/jlebar/code/moz/ff-git/src/memory/build/replace_malloc.c:152 (0x4020b2ae libmozglue.so+0x42ae)
>        moz_malloc /Users/jlebar/code/moz/ff-git/src/memory/mozalloc/mozalloc.cpp:65 (0x40e5adf2 libxul.so+0xc37df2)
>        gfxImageSurface /Users/jlebar/code/moz/ff-git/src/gfx/thebes/gfxImageSurface.cpp:110 (0x419ae7b6 libxul.so+0xa877b6)
>        nsRefPtr<gfxASurface>::assign_with_AddRef(gfxASurface*) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsAutoPtr.h:846 (0x419c3ac0 libxul.so+0xa9cac0)
>        gfxPlatform::OptimizeImage(gfxImageSurface*, gfxASurface::gfxImageFormat) /Users/jlebar/code/moz/ff-git/src/gfx/thebes/gfxPlatform.cpp:464 (0x419bbbe4 libxul.so+0xa94be4)
>        nsRefPtr<gfxASurface>::assign_assuming_AddRef(gfxASurface*) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsAutoPtr.h:861 (0x4126637a libxul.so+0x33f37a)
>        mozilla::image::RasterImage::DecodingComplete() /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsError.h:155 (0x41261f3a libxul.so+0x33af3a)
>        nsCOMPtr<imgIDecoderObserver>::get() const /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsCOMPtr.h:764 (0x4125fa90 libxul.so+0x338a90)
>        mozilla::image::nsPNGDecoder::end_callback(png_struct_def*, png_info_def*) /Users/jlebar/code/moz/ff-git/src/image/decoders/nsPNGDecoder.cpp:860 (0x4126f3fe libxul.so+0x3483fe)
>        MOZ_PNG_push_have_end /Users/jlebar/code/moz/ff-git/src/media/libpng/pngpread.c:1454 (0x40e35ce6 libxul.so+0xc12ce6)
>        MOZ_PNG_push_read_chunk /Users/jlebar/code/moz/ff-git/src/media/libpng/pngpread.c:358 (0x40e36824 libxul.so+0xc13824)
>        MOZ_PNG_proc_some_data /Users/jlebar/code/moz/ff-git/src/media/libpng/pngpread.c:122 (0x40e36a72 libxul.so+0xc13a72)
>        MOZ_PNG_process_data /Users/jlebar/code/moz/ff-git/src/media/libpng/pngpread.c:38 (0x40e36ac0 libxul.so+0xc13ac0)
>        mozilla::image::nsPNGDecoder::WriteInternal(char const*, unsigned int) /Users/jlebar/code/moz/ff-git/src/image/decoders/nsPNGDecoder.cpp:352 (0x4056b2da libxul.so+0x3482da)
>        mozilla::image::Decoder::Write(char const*, unsigned int) /Users/jlebar/code/moz/ff-git/src/image/src/Decoder.cpp:80 (0x4055b9c0 libxul.so+0x3389c0)
>        mozilla::image::RasterImage::WriteToDecoder(char const*, unsigned int) /Users/jlebar/code/moz/ff-git/src/image/src/RasterImage.cpp:2649 (0x4055d976 libxul.so+0x33a976)
>        mozilla::image::RasterImage::DecodeSomeData(unsigned int) /Users/jlebar/code/moz/ff-git/src/image/src/RasterImage.cpp:3168 (0x4055da0c libxul.so+0x33aa0c)
>        mozilla::image::RasterImage::DecodeWorker::DecodeSomeOfImage(mozilla::image::RasterImage*, mozilla::image::RasterImage::DecodeWorker::DecodeType) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsError.h:155 (0x4055e172 libxul.so+0x33b172)
>        nsRefPtr<mozilla::image::RasterImage>::get() const /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsAutoPtr.h:1005 (0x4126232e libxul.so+0x33b32e)
>        nsThread::ProcessNextEvent(bool, bool*) /Users/jlebar/code/moz/ff-git/src/xpcom/threads/nsThread.cpp:627 (0x40c63c1e libxul.so+0xa40c1e)
>        NS_ProcessNextEvent_P(nsIThread*, bool) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsError.h:155 (0x40c43dfa libxul.so+0xa20dfa)
>        mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /Users/jlebar/code/moz/ff-git/src/ipc/glue/MessagePump.cpp:83 (0x40b62008 libxul.so+0x93f008)
>        MessageLoop::RunInternal() /Users/jlebar/code/moz/ff-git/src/ipc/chromium/src/base/message_loop.cc:216 (0x40c85d40 libxul.so+0xa62d40)
>        ~AutoRunState /Users/jlebar/code/moz/ff-git/src/ipc/chromium/src/base/message_loop.cc:502 (0x40c85df6 libxul.so+0xa62df6)
> 
> Unreported: 1 block in block group 9 of 533
>  307,200 bytes (307,200 requested / 0 slop)
>  1.27% of the heap (32.08% cumulative);  2.51% of unreported (63.15% cumulative)
>  Allocated at
>        malloc /Users/jlebar/code/moz/ff-git/src/memory/build/replace_malloc.c:152 (0x4020b2ae libmozglue.so+0x42ae)
>        moz_malloc /Users/jlebar/code/moz/ff-git/src/memory/mozalloc/mozalloc.cpp:65 (0x40e5adf2 libxul.so+0xc37df2)
>        gfxImageSurface /Users/jlebar/code/moz/ff-git/src/gfx/thebes/gfxImageSurface.cpp:110 (0x419ae7b6 libxul.so+0xa877b6)
>        nsRefPtr<gfxASurface>::assign_with_AddRef(gfxASurface*) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsAutoPtr.h:846 (0x419c3ac0 libxul.so+0xa9cac0)
>        gfxPlatform::OptimizeImage(gfxImageSurface*, gfxASurface::gfxImageFormat) /Users/jlebar/code/moz/ff-git/src/gfx/thebes/gfxPlatform.cpp:464 (0x419bbbe4 libxul.so+0xa94be4)
>        nsRefPtr<gfxASurface>::assign_assuming_AddRef(gfxASurface*) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsAutoPtr.h:861 (0x4126637a libxul.so+0x33f37a)
>        mozilla::image::RasterImage::DecodingComplete() /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsError.h:155 (0x41261f3a libxul.so+0x33af3a)
>        nsCOMPtr<imgIDecoderObserver>::get() const /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsCOMPtr.h:764 (0x4125fa90 libxul.so+0x338a90)
>        mozilla::image::nsJPEGDecoder::NotifyDone() /Users/jlebar/code/moz/ff-git/src/image/decoders/nsJPEGDecoder.cpp:549 (0x4126fda6 libxul.so+0x348da6)
>        mozilla::image::term_source(jpeg_decompress_struct*) /Users/jlebar/code/moz/ff-git/src/image/decoders/nsJPEGDecoder.cpp:867 (0x4126fdb0 libxul.so+0x348db0)
>        jpeg_finish_decompress /Users/jlebar/code/moz/ff-git/src/media/libjpeg/jdapimin.c:393 (0x41b3ebb0 libxul.so+0xc17bb0)
>        mozilla::image::nsJPEGDecoder::WriteInternal(char const*, unsigned int) /Users/jlebar/code/moz/ff-git/src/image/decoders/nsJPEGDecoder.cpp:518 (0x4127035a libxul.so+0x34935a)
>        mozilla::image::Decoder::Write(char const*, unsigned int) /Users/jlebar/code/moz/ff-git/src/image/src/Decoder.cpp:80 (0x4055b9c0 libxul.so+0x3389c0)
>        mozilla::image::RasterImage::WriteToDecoder(char const*, unsigned int) /Users/jlebar/code/moz/ff-git/src/image/src/RasterImage.cpp:2649 (0x4055d976 libxul.so+0x33a976)
>        mozilla::image::RasterImage::DecodeSomeData(unsigned int) /Users/jlebar/code/moz/ff-git/src/image/src/RasterImage.cpp:3168 (0x4055da0c libxul.so+0x33aa0c)
>        mozilla::image::RasterImage::DecodeWorker::DecodeSomeOfImage(mozilla::image::RasterImage*, mozilla::image::RasterImage::DecodeWorker::DecodeType) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsError.h:155 (0x4055e172 libxul.so+0x33b172)
>        mozilla::image::RasterImage::DecodeWorker::DecodeABitOf(mozilla::image::RasterImage*) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsAutoPtr.h:1005 (0x4055e414 libxul.so+0x33b414)
>        ~SamplerStackFramePrintfRAII /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/sps_sampler.h:221 (0x4126296c libxul.so+0x33b96c)
>        mozilla::image::RasterImage::StartDecoding() /Users/jlebar/code/moz/ff-git/src/image/src/RasterImage.cpp:2706 (0x41260314 libxul.so+0x339314)
>        imgRequest::StartDecoding() /Users/jlebar/code/moz/ff-git/src/image/src/imgRequest.cpp:538 (0x4126a87e libxul.so+0x34387e)
>        imgRequestProxy::StartDecoding() /Users/jlebar/code/moz/ff-git/src/image/src/imgRequestProxy.cpp:361 (0x4126d27e libxul.so+0x34627e)
>        nsDocument::AddImage(imgIRequest*) /Users/jlebar/code/moz/ff-git/src/content/base/src/nsDocument.cpp:8004 (0x413bc482 libxul.so+0x495482)
>        nsStyleContentData::TrackImage(nsPresContext*) /Users/jlebar/code/moz/ff-git/src/layout/style/nsStyleStruct.cpp:1502 (0x4064eaa2 libxul.so+0x42baa2)
>        nsRuleNode::ComputeBackgroundData(void*, nsRuleData const*, nsStyleContext*, nsRuleNode*, nsRuleNode::RuleDetail, bool) /Users/jlebar/code/moz/ff-git/src/layout/style/nsRuleNode.cpp:5702 (0x40646924 libxul.so+0x423924)
Comment 3 Justin Lebar (not reading bugmail) 2012-12-10 20:31:28 PST
I don't know if this is still useful, but here are two more sets of stacks from
the gallery app.  Together, these are ~43% of the gallery app's
heap-unclassified.

> Unreported: 49 blocks in block group 2 of 215
>  1,605,632 bytes (1,411,200 requested / 194,432 slop)
>  12.66% of the heap (26.23% cumulative);  28.68% of unreported (59.40% cumulative)
>  Allocated at
>        malloc /Users/jlebar/code/moz/ff-git/src/memory/build/replace_malloc.c:152 (0x4020b2ae libmozglue.so+0x42ae)
>        moz_malloc /Users/jlebar/code/moz/ff-git/src/memory/mozalloc/mozalloc.cpp:65 (0x40e5adf2 libxul.so+0xc37df2)
>        gfxImageSurface /Users/jlebar/code/moz/ff-git/src/gfx/thebes/gfxImageSurface.cpp:110 (0x419ae7b6 libxul.so+0xa877b6)
>        nsRefPtr<gfxASurface>::assign_with_AddRef(gfxASurface*) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsAutoPtr.h:846 (0x419c3ac0 libxul.so+0xa9cac0)
>        gfxPlatform::OptimizeImage(gfxImageSurface*, gfxASurface::gfxImageFormat) /Users/jlebar/code/moz/ff-git/src/gfx/thebes/gfxPlatform.cpp:464 (0x419bbbe4 libxul.so+0xa94be4)
>        nsRefPtr<gfxASurface>::assign_assuming_AddRef(gfxASurface*) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsAutoPtr.h:861 (0x4126637a libxul.so+0x33f37a)
>        mozilla::image::RasterImage::DecodingComplete() /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsError.h:155 (0x41261f3a libxul.so+0x33af3a)
>        nsCOMPtr<imgIDecoderObserver>::get() const /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsCOMPtr.h:764 (0x4125fa90 libxul.so+0x338a90)
>        mozilla::image::nsJPEGDecoder::NotifyDone() /Users/jlebar/code/moz/ff-git/src/image/decoders/nsJPEGDecoder.cpp:549 (0x4126fda6 libxul.so+0x348da6)
>        mozilla::image::term_source(jpeg_decompress_struct*) /Users/jlebar/code/moz/ff-git/src/image/decoders/nsJPEGDecoder.cpp:867 (0x4126fdb0 libxul.so+0x348db0)
>        jpeg_finish_decompress /Users/jlebar/code/moz/ff-git/src/media/libjpeg/jdapimin.c:393 (0x41b3ebb0 libxul.so+0xc17bb0)
>        mozilla::image::nsJPEGDecoder::WriteInternal(char const*, unsigned int) /Users/jlebar/code/moz/ff-git/src/image/decoders/nsJPEGDecoder.cpp:518 (0x4127035a libxul.so+0x34935a)
>        mozilla::image::Decoder::Write(char const*, unsigned int) /Users/jlebar/code/moz/ff-git/src/image/src/Decoder.cpp:80 (0x4055b9c0 libxul.so+0x3389c0)
>        mozilla::image::RasterImage::WriteToDecoder(char const*, unsigned int) /Users/jlebar/code/moz/ff-git/src/image/src/RasterImage.cpp:2649 (0x4055d976 libxul.so+0x33a976)
>        mozilla::image::RasterImage::DecodeSomeData(unsigned int) /Users/jlebar/code/moz/ff-git/src/image/src/RasterImage.cpp:3168 (0x4055da0c libxul.so+0x33aa0c)
>        mozilla::image::RasterImage::DecodeWorker::DecodeSomeOfImage(mozilla::image::RasterImage*, mozilla::image::RasterImage::DecodeWorker::DecodeType) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsError.h:155 (0x4055e172 libxul.so+0x33b172)
>        mozilla::image::RasterImage::DecodeWorker::DecodeUntilSizeAvailable(mozilla::image::RasterImage*) /Users/jlebar/code/moz/ff-git/src/image/src/RasterImage.cpp:3429 (0x4055e2c8 libxul.so+0x33b2c8)
>        mozilla::image::RasterImage::SourceDataComplete() /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsError.h:155 (0x4055f32e libxul.so+0x33c32e)
>        imgRequest::OnStopRequest(nsIRequest*, nsISupports*, tag_nsresult) /Users/jlebar/code/moz/ff-git/src/image/src/imgRequest.cpp:656 (0x40567202 libxul.so+0x344202)
>        ProxyListener::OnStopRequest(nsIRequest*, nsISupports*, tag_nsresult) /Users/jlebar/code/moz/ff-git/src/image/src/imgLoader.cpp:2063 (0x405628b4 libxul.so+0x33f8b4)
>        nsCOMPtr<nsIStreamListener>::operator=(nsIStreamListener*) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsCOMPtr.h:624 (0x411acf58 libxul.so+0x285f58)
>        nsCOMPtr<nsIStreamListener>::operator=(nsIStreamListener*) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsCOMPtr.h:624 (0x404ad460 libxul.so+0x28a460)
>        nsInputStreamPump::OnInputStreamReady(nsIAsyncInputStream*) /Users/jlebar/code/moz/ff-git/src/netwerk/base/src/nsInputStreamPump.cpp:382 (0x404ad6c0 libxul.so+0x28a6c0)
>        nsCOMPtr<nsIOutputStreamCallback>::operator=(nsIOutputStreamCallback*) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsCOMPtr.h:624 (0x40c59896 libxul.so+0xa36896)
> 
> Unreported: 25 blocks in block group 3 of 215
>  819,200 bytes (768,000 requested / 51,200 slop)
>  6.46% of the heap (32.69% cumulative);  14.63% of unreported (74.03% cumulative)
>  Allocated at
>        malloc /Users/jlebar/code/moz/ff-git/src/memory/build/replace_malloc.c:152 (0x4020b2ae libmozglue.so+0x42ae)
>        moz_malloc /Users/jlebar/code/moz/ff-git/src/memory/mozalloc/mozalloc.cpp:65 (0x40e5adf2 libxul.so+0xc37df2)
>        gfxImageSurface /Users/jlebar/code/moz/ff-git/src/gfx/thebes/gfxImageSurface.cpp:110 (0x419ae7b6 libxul.so+0xa877b6)
>        nsRefPtr<gfxASurface>::assign_with_AddRef(gfxASurface*) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsAutoPtr.h:846 (0x419c3ac0 libxul.so+0xa9cac0)
>        gfxPlatform::OptimizeImage(gfxImageSurface*, gfxASurface::gfxImageFormat) /Users/jlebar/code/moz/ff-git/src/gfx/thebes/gfxPlatform.cpp:464 (0x419bbbe4 libxul.so+0xa94be4)
>        nsRefPtr<gfxASurface>::assign_assuming_AddRef(gfxASurface*) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsAutoPtr.h:861 (0x4126637a libxul.so+0x33f37a)
>        mozilla::image::RasterImage::DecodingComplete() /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsError.h:155 (0x41261f3a libxul.so+0x33af3a)
>        nsCOMPtr<imgIDecoderObserver>::get() const /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsCOMPtr.h:764 (0x4125fa90 libxul.so+0x338a90)
>        mozilla::image::nsJPEGDecoder::NotifyDone() /Users/jlebar/code/moz/ff-git/src/image/decoders/nsJPEGDecoder.cpp:549 (0x4126fda6 libxul.so+0x348da6)
>        mozilla::image::term_source(jpeg_decompress_struct*) /Users/jlebar/code/moz/ff-git/src/image/decoders/nsJPEGDecoder.cpp:867 (0x4126fdb0 libxul.so+0x348db0)
>        jpeg_finish_decompress /Users/jlebar/code/moz/ff-git/src/media/libjpeg/jdapimin.c:393 (0x41b3ebb0 libxul.so+0xc17bb0)
>        mozilla::image::nsJPEGDecoder::WriteInternal(char const*, unsigned int) /Users/jlebar/code/moz/ff-git/src/image/decoders/nsJPEGDecoder.cpp:518 (0x4127035a libxul.so+0x34935a)
>        mozilla::image::Decoder::Write(char const*, unsigned int) /Users/jlebar/code/moz/ff-git/src/image/src/Decoder.cpp:80 (0x4055b9c0 libxul.so+0x3389c0)
>        mozilla::image::RasterImage::WriteToDecoder(char const*, unsigned int) /Users/jlebar/code/moz/ff-git/src/image/src/RasterImage.cpp:2649 (0x4055d976 libxul.so+0x33a976)
>        mozilla::image::RasterImage::SyncDecode() /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsError.h:155 (0x404fe4e6 libxul.so+0x33b4e6)
>        mozilla::image::RasterImage::GetFrame(unsigned int, unsigned int, gfxASurface**) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsError.h:155 (0x40500184 libxul.so+0x33d184)
>        nsLayoutUtils::SurfaceFromElement(nsIImageLoadingContent*, unsigned int) /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsError.h:155 (0x4054866a libxul.so+0x38566a)
>        ~nsCOMPtr /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsCOMPtr.h:453 (0x40548850 libxul.so+0x385850)
>        nsRefPtr<gfxASurface>::get() const /Users/jlebar/code/moz/B2G/objdir-gecko/dist/include/nsAutoPtr.h:1005 (0x406a598c libxul.so+0x4e298c)
>        mozilla::dom::CanvasRenderingContext2DBinding::drawImage(JSContext*, JS::Handle<JSObject*>, mozilla::dom::CanvasRenderingContext2D*, unsigned int, JS::Value*) /Users/jlebar/code/moz/B2G/objdir-gecko/dom/bindings/CanvasRenderingContext2DBinding.cpp:1593 (0x40b9a1fe libxul.so+0x9d71fe)
>        mozilla::dom::CanvasRenderingContext2DBinding::genericMethod(JSContext*, unsigned int, JS::Value*) /Users/jlebar/code/moz/B2G/objdir-gecko/dom/bindings/CanvasRenderingContext2DBinding.cpp:3245 (0x40b9b2cc libxul.so+0x9d82cc)
Comment 4 Nicholas Nethercote [:njn] 2012-12-18 17:17:58 PST
imgFrame::mOptSurface is reported in a way that DMD doesn't know about -- it uses gfxASurface::KnownMemoryUsed(), which uses a counter rather than a nsMallocSizeOfFun.

To fix this requires implementing gfxASurface::SizeOfIncludingThis().  This is possible, but difficult.  The main difficulty is that there are at least 12 sub-classes of gfxASurface.

For this B2G case I think the surface is created via gfxAndroidPlatform::CreateOffscreenSurface, and the particular sub-class is gfxImageSurface, for which we already do have a reporter.  So maybe it won't be so hard... I could just fallback to KnownMemoryUsed() for the other sub-classes.
Comment 5 Nicholas Nethercote [:njn] 2012-12-18 19:16:08 PST
Created attachment 693728 [details] [diff] [review]
Measure imgFrame::mOptSurface's size where possible, instead of calculating it.

This patch provides a mechanism whereby sub-classes of gfxASurface can indicate
if they are able to measure their memory consumption with an
nsMallocSizeOfFun.  Currently gfxImageSurface is the only one that can, but
that should be enough on Android for imgFrame::mOptSurface to be measured,
because it is a gfxImageSurface.

jlebar, I haven't confirmed this works because I don't have an Android device.
(On Linux64, imgFrame::mOptSurface is a gfxXlibSurface, which is difficult to
measure because it contains Cairo stuff.)  If you run DMD on b2g hopefully
those unreported blocks will become reported.
Comment 6 Nicholas Nethercote [:njn] 2012-12-18 19:19:08 PST
BTW, this is another case where the memory is being reported, just not in a way that DMD knows about.  So it won't necessarily reduce "heap-unclassified".
Comment 7 Nicholas Nethercote [:njn] 2012-12-18 21:59:59 PST
Created attachment 693759 [details] [diff] [review]
Measure imgFrame::mOptSurface's size where possible, instead of calculating it.

Just for kicks, here's a version that compiles.
Comment 8 Joe Drew (not getting mail) 2012-12-19 08:59:07 PST
Comment on attachment 693759 [details] [diff] [review]
Measure imgFrame::mOptSurface's size where possible, instead of calculating it.

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

Q: Why is SizeOfIncludingThis() returning 0 not enough? That is to say, could we *not* add this extra virtual function, unconditionally call SizeOfIncludingThis(), and detect 0 as a "it doesn't work" condition?

Presuming there is an answer to that, r=me.

::: gfx/thebes/gfxASurface.h
@@ +201,5 @@
>      virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
> +    // We have lots of sub-classes of gfxASurface.  This method indicates if a
> +    // sub-class is capable of measuring its own size accurately.  If not, we
> +    // fall back to a computed size (KnownMemoryUsed()).  The default method
> +    // returns false, naturally.

No need for that last sentence, as it's implied in, you know, the body of the function :)
Comment 9 Justin Lebar (not reading bugmail) 2012-12-19 14:18:26 PST
> That is to say, could we *not* add this extra virtual function, unconditionally call 
> SizeOfIncludingThis(), and detect 0 as a "it doesn't work" condition?

I wondered the same thing, but it turns out that gfxASurface::SizeOfIncludingThis doesn't return 0 -- it returns aMallocSizeOf(this) + SizeOfExcludingThis().
Comment 10 Justin Lebar (not reading bugmail) 2012-12-19 14:18:54 PST
We could check whether SizeOfExcludingThis() returns 0.  :shrug:
Comment 11 Nicholas Nethercote [:njn] 2012-12-19 14:22:57 PST
> Q: Why is SizeOfIncludingThis() returning 0 not enough? That is to say,
> could we *not* add this extra virtual function, unconditionally call
> SizeOfIncludingThis(), and detect 0 as a "it doesn't work" condition?

The problem is that 0 is an unclear signal -- does it mean "zero bytes" or does it mean "it doesn't work"?  We have this in gfxASurface.cpp:

 size_t
 gfxASurface::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
 {
     // We don't measure mSurface because cairo doesn't allow it.
     return 0;
 }

gfxASurface::SizeOfExcludingThis cannot sensibly both (a) measure itself, and (b) act as a "it doesn't work" default for sub-classes.  So SizeOfIsMeasured() has to play the role of (b).  (Actually, given that it returns 0 at the moment it can serve both roles, but that's a fluke of the overloading of 0, and if we ever changed it to measure gfxASurface::{mSurface,mOpaqueRect} it would no longer return 0 and things would break.)

Now that I think about it, I can improve the "zero bytes" vs. "it doesn't work" distinction better in some other places in imgFrame.cpp.  I'll do a follow-up patch.
Comment 12 Justin Lebar (not reading bugmail) 2012-12-19 14:27:34 PST
Comment on attachment 693759 [details] [diff] [review]
Measure imgFrame::mOptSurface's size where possible, instead of calculating it.

bah, njn wanted me to actually /test/ this before giving f+.
Comment 13 Nicholas Nethercote [:njn] 2012-12-19 15:29:39 PST
> Now that I think about it, I can improve the "zero bytes" vs. "it doesn't
> work" distinction better in some other places in imgFrame.cpp.  I'll do a
> follow-up patch.

Actually, that didn't work out.  The current code is as good as it gets.
Comment 14 Justin Lebar (not reading bugmail) 2012-12-19 16:51:49 PST
Comment on attachment 693759 [details] [diff] [review]
Measure imgFrame::mOptSurface's size where possible, instead of calculating it.

Verified that this works.
Comment 15 Nicholas Nethercote [:njn] 2012-12-19 20:40:26 PST
https://hg.mozilla.org/integration/mozilla-inbound/rev/20cb0fa34108
Comment 16 Ed Morley [:emorley] 2012-12-20 13:44:20 PST
https://hg.mozilla.org/mozilla-central/rev/20cb0fa34108

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