CodeBlock memory cost reporting should be rationalized
authorfpizlo@apple.com <fpizlo@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Sep 2013 05:48:06 +0000 (05:48 +0000)
committerfpizlo@apple.com <fpizlo@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Sep 2013 05:48:06 +0000 (05:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=120615

Source/JavaScriptCore:

Reviewed by Darin Adler.

Report the size of the instruction stream, and then remind the GC that we're
using memory when we trace.

This is a slight slow-down on some JSBench tests because it makes us GC a
bit more frequently. But I think it's well worth it; if we really want those
tests to GC less frequently then we can achieve that through other kinds of
tuning. It's better that the GC knows that CodeBlocks do in fact use memory;
what it does with that information is a somewhat orthogonal question.

* bytecode/CodeBlock.cpp:
(JSC::CodeBlock::CodeBlock):
(JSC::CodeBlock::visitAggregate):

Source/WTF:

Reviewed by Darin Adler.

* wtf/RefCountedArray.h:
(WTF::RefCountedArray::refCount):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@155021 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/bytecode/CodeBlock.cpp
Source/WTF/ChangeLog
Source/WTF/wtf/RefCountedArray.h

index 526832a..d61a610 100644 (file)
@@ -1,3 +1,23 @@
+2013-09-03  Filip Pizlo  <fpizlo@apple.com>
+
+        CodeBlock memory cost reporting should be rationalized
+        https://bugs.webkit.org/show_bug.cgi?id=120615
+
+        Reviewed by Darin Adler.
+        
+        Report the size of the instruction stream, and then remind the GC that we're
+        using memory when we trace.
+        
+        This is a slight slow-down on some JSBench tests because it makes us GC a
+        bit more frequently. But I think it's well worth it; if we really want those
+        tests to GC less frequently then we can achieve that through other kinds of
+        tuning. It's better that the GC knows that CodeBlocks do in fact use memory;
+        what it does with that information is a somewhat orthogonal question.
+
+        * bytecode/CodeBlock.cpp:
+        (JSC::CodeBlock::CodeBlock):
+        (JSC::CodeBlock::visitAggregate):
+
 2013-09-03  Mark Lam  <mark.lam@apple.com>
 
         Converting StackIterator to a callback interface.
index 52f7552..1f94066 100644 (file)
@@ -1847,7 +1847,7 @@ CodeBlock::CodeBlock(ScriptExecutable* ownerExecutable, UnlinkedCodeBlock* unlin
     if (Options::dumpGeneratedBytecodes())
         dumpBytecode();
     m_heap->m_codeBlocks.add(this);
-    m_heap->reportExtraMemoryCost(sizeof(CodeBlock));
+    m_heap->reportExtraMemoryCost(sizeof(CodeBlock) + m_instructions.size() * sizeof(Instruction));
 }
 
 CodeBlock::~CodeBlock()
@@ -1931,6 +1931,17 @@ void CodeBlock::visitAggregate(SlotVisitor& visitor)
     if (!!m_alternative)
         m_alternative->visitAggregate(visitor);
 
+    visitor.reportExtraMemoryUsage(sizeof(CodeBlock));
+    if (m_jitCode)
+        visitor.reportExtraMemoryUsage(m_jitCode->size());
+    if (m_instructions.size()) {
+        // Divide by refCount() because m_instructions points to something that is shared
+        // by multiple CodeBlocks, and we only want to count it towards the heap size once.
+        // Having each CodeBlock report only its proportional share of the size is one way
+        // of accomplishing this.
+        visitor.reportExtraMemoryUsage(m_instructions.size() * sizeof(Instruction) / m_instructions.refCount());
+    }
+
     visitor.append(&m_unlinkedCode);
 
     // There are three things that may use unconditional finalizers: lazy bytecode freeing,
index 552dc10..8d0b5ce 100644 (file)
@@ -1,3 +1,13 @@
+2013-09-03  Filip Pizlo  <fpizlo@apple.com>
+
+        CodeBlock memory cost reporting should be rationalized
+        https://bugs.webkit.org/show_bug.cgi?id=120615
+
+        Reviewed by Darin Adler.
+
+        * wtf/RefCountedArray.h:
+        (WTF::RefCountedArray::refCount):
+
 2013-09-03  Enrica Casucci  <enrica@apple.com>
 
         Follow up to http://trac.webkit.org/changeset/155014
index d0c183d..60462cb 100644 (file)
@@ -112,6 +112,13 @@ public:
         fastFree(Header::fromPayload(m_data));
     }
     
+    unsigned refCount() const
+    {
+        if (!m_data)
+            return 0;
+        return Header::fromPayload(m_data)->refCount;
+    }
+    
     size_t size() const
     {
         if (!m_data)