Bug 154838 - Add new MethodTable method to get an estimated size for a cell
Summary: Add new MethodTable method to get an estimated size for a cell
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Joseph Pecoraro
URL:
Keywords:
Depends on:
Blocks: 10930
  Show dependency treegraph
 
Reported: 2016-02-29 15:29 PST by Joseph Pecoraro
Modified: 2016-02-29 18:07 PST (History)
9 users (show)

See Also:


Attachments
[PATCH] Proposed Fix (23.78 KB, patch)
2016-02-29 15:41 PST, Joseph Pecoraro
fpizlo: review+
Details | Formatted Diff | Diff
[PATCH] For Landing (23.87 KB, patch)
2016-02-29 17:19 PST, Joseph Pecoraro
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Pecoraro 2016-02-29 15:29:07 PST
* SUMMARY
Add new MethodTable method to get an estimated size for a cell

The new class method estimatedSize(JSCell*) estimates the size for a single cell.

    Base implementation (JSCell)
      - returns the MarkedBlock bucket size for this cell.
      - This gets us basic member/inline storage. Basically a better sizeof.

    Subclasses with "Extra Memory Cost":
      - Any class that reports extra memory (reportExtraMemoryVisited) should include that in the estimated size.
      - E.g. CodeBlock, JSGenericTypedArrayView, WeakMapData, etc.

    Subclasses with "Copied Space" storage:
      - Any class with data in copied space (has copyBackingStore) should include that in the estimated size.
      - E.g. JSObject, JSGenericTypedArrayView, JSMap, JSSet, DirectArguments, etc.

* NOTES
To be used by Inspector for JavaScript Heap Instrumentation.
Comment 1 Joseph Pecoraro 2016-02-29 15:41:55 PST
Created attachment 272525 [details]
[PATCH] Proposed Fix
Comment 2 Mark Lam 2016-02-29 16:01:37 PST
Comment on attachment 272525 [details]
[PATCH] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=272525&action=review

> Source/JavaScriptCore/bytecode/CodeBlock.cpp:2468
> +    size_t extraMemoryAllocated = thisObject->m_instructions.size() * sizeof(Instruction);

Maybe add a fixme here (with a bug to track) to add JITCode size (for baseline and DFG/FTL codeBlocks)?

> Source/JavaScriptCore/runtime/JSGenericTypedArrayViewInlines.h:416
> +    if (thisObject->m_mode == OversizeTypedArray)
> +        return Base::estimatedSize(thisObject) + thisObject->byteSize();
> +    if (thisObject->m_mode == FastTypedArray && thisObject->m_vector)
> +        return Base::estimatedSize(thisObject) + thisObject->byteSize();

Why not || the 2 conditions?
Comment 3 Joseph Pecoraro 2016-02-29 16:57:20 PST
(In reply to comment #2)
> Comment on attachment 272525 [details]
> [PATCH] Proposed Fix
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=272525&action=review
> 
> > Source/JavaScriptCore/bytecode/CodeBlock.cpp:2468
> > +    size_t extraMemoryAllocated = thisObject->m_instructions.size() * sizeof(Instruction);

Good catch, I should definitely have been including the m_jitCode->size() here if we have m_jitCode.


> Maybe add a fixme here (with a bug to track) to add JITCode size (for
> baseline and DFG/FTL codeBlocks)?
> 
> > Source/JavaScriptCore/runtime/JSGenericTypedArrayViewInlines.h:416
> > +    if (thisObject->m_mode == OversizeTypedArray)
> > +        return Base::estimatedSize(thisObject) + thisObject->byteSize();
> > +    if (thisObject->m_mode == FastTypedArray && thisObject->m_vector)
> > +        return Base::estimatedSize(thisObject) + thisObject->byteSize();
> 
> Why not || the 2 conditions?

I could go either way on this. I converted the switch in JSGenericTypedArrayView<Adaptor>::visitChildren to a couple if statements. They happened to have the same calculation, but most of the code in this file treats the modes separate (via the switch), so I followed suit here. I like treating these as separate in case storage ever differs between the two different modes.
Comment 4 Joseph Pecoraro 2016-02-29 17:19:50 PST
Created attachment 272532 [details]
[PATCH] For Landing
Comment 5 WebKit Commit Bot 2016-02-29 18:07:05 PST
Comment on attachment 272532 [details]
[PATCH] For Landing

Clearing flags on attachment: 272532

Committed r197379: <http://trac.webkit.org/changeset/197379>
Comment 6 WebKit Commit Bot 2016-02-29 18:07:09 PST
All reviewed patches have been landed.  Closing bug.