Title: [155021] trunk/Source
Revision
155021
Author
fpi...@apple.com
Date
2013-09-03 22:48:06 -0700 (Tue, 03 Sep 2013)

Log Message

CodeBlock memory cost reporting should be rationalized
https://bugs.webkit.org/show_bug.cgi?id=120615

Source/_javascript_Core: 

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):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (155020 => 155021)


--- trunk/Source/_javascript_Core/ChangeLog	2013-09-04 05:06:08 UTC (rev 155020)
+++ trunk/Source/_javascript_Core/ChangeLog	2013-09-04 05:48:06 UTC (rev 155021)
@@ -1,3 +1,23 @@
+2013-09-03  Filip Pizlo  <fpi...@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....@apple.com>
 
         Converting StackIterator to a callback interface.

Modified: trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp (155020 => 155021)


--- trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp	2013-09-04 05:06:08 UTC (rev 155020)
+++ trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp	2013-09-04 05:48:06 UTC (rev 155021)
@@ -1847,7 +1847,7 @@
     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 @@
     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,

Modified: trunk/Source/WTF/ChangeLog (155020 => 155021)


--- trunk/Source/WTF/ChangeLog	2013-09-04 05:06:08 UTC (rev 155020)
+++ trunk/Source/WTF/ChangeLog	2013-09-04 05:48:06 UTC (rev 155021)
@@ -1,3 +1,13 @@
+2013-09-03  Filip Pizlo  <fpi...@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  <enr...@apple.com>
 
         Follow up to http://trac.webkit.org/changeset/155014

Modified: trunk/Source/WTF/wtf/RefCountedArray.h (155020 => 155021)


--- trunk/Source/WTF/wtf/RefCountedArray.h	2013-09-04 05:06:08 UTC (rev 155020)
+++ trunk/Source/WTF/wtf/RefCountedArray.h	2013-09-04 05:48:06 UTC (rev 155021)
@@ -112,6 +112,13 @@
         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)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to