2011-06-09 Geoffrey Garen <ggaren@apple.com>
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Jun 2011 04:38:23 +0000 (04:38 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Jun 2011 04:38:23 +0000 (04:38 +0000)
        Reviewed by Oliver Hunt.

        Added OldSpace to the project
        https://bugs.webkit.org/show_bug.cgi?id=62417

        Currently unused.

        Added OldSpace, the ability to iterate NewSpace vs OldSpace, and a
        per-block flag for testing whether you're in NewSpace vs OldSpace.

        * CMakeLists.txt:
        * GNUmakefile.list.am:
        * JavaScriptCore.gypi:
        * JavaScriptCore.pro:
        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
        * JavaScriptCore.xcodeproj/project.pbxproj: Build!

        * heap/MarkedBlock.cpp:
        (JSC::MarkedBlock::MarkedBlock):
        * heap/MarkedBlock.h:
        (JSC::MarkedBlock::inNewSpace):
        (JSC::MarkedBlock::setInNewSpace): Added inNewSpace flag, for use in
        write barrier.

        * heap/NewSpace.cpp:
        (JSC::NewSpace::addBlock):
        (JSC::NewSpace::removeBlock):
        * heap/NewSpace.h:
        (JSC::NewSpace::forEachBlock): Added forEachBlock, to use for
        NewSpace-specific operations.

        * heap/OldSpace.cpp: Added.
        (JSC::OldSpace::OldSpace):
        (JSC::OldSpace::addBlock):
        (JSC::OldSpace::removeBlock):
        * heap/OldSpace.h: Added.
        (JSC::OldSpace::forEachBlock): New class for holding promoted blocks.
        Not in use yet.

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

13 files changed:
Source/JavaScriptCore/CMakeLists.txt
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/GNUmakefile.list.am
Source/JavaScriptCore/JavaScriptCore.gypi
Source/JavaScriptCore/JavaScriptCore.pro
Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/heap/MarkedBlock.cpp
Source/JavaScriptCore/heap/MarkedBlock.h
Source/JavaScriptCore/heap/NewSpace.cpp
Source/JavaScriptCore/heap/NewSpace.h
Source/JavaScriptCore/heap/OldSpace.cpp [new file with mode: 0644]
Source/JavaScriptCore/heap/OldSpace.h [new file with mode: 0644]

index e01ff84..afb5daf 100644 (file)
@@ -48,6 +48,7 @@ SET(JavaScriptCore_SOURCES
     heap/MachineStackMarker.cpp
     heap/MarkedBlock.cpp
     heap/NewSpace.cpp
+    heap/OldSpace.cpp
     heap/ConservativeRoots.cpp
     heap/MarkStack.cpp
 
index bc900b1..48e5549 100644 (file)
@@ -1,3 +1,44 @@
+2011-06-09  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Oliver Hunt.
+
+        Added OldSpace to the project
+        https://bugs.webkit.org/show_bug.cgi?id=62417
+        
+        Currently unused.
+        
+        Added OldSpace, the ability to iterate NewSpace vs OldSpace, and a
+        per-block flag for testing whether you're in NewSpace vs OldSpace.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * JavaScriptCore.gypi:
+        * JavaScriptCore.pro:
+        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
+        * JavaScriptCore.xcodeproj/project.pbxproj: Build!
+
+        * heap/MarkedBlock.cpp:
+        (JSC::MarkedBlock::MarkedBlock):
+        * heap/MarkedBlock.h:
+        (JSC::MarkedBlock::inNewSpace):
+        (JSC::MarkedBlock::setInNewSpace): Added inNewSpace flag, for use in
+        write barrier.
+
+        * heap/NewSpace.cpp:
+        (JSC::NewSpace::addBlock):
+        (JSC::NewSpace::removeBlock):
+        * heap/NewSpace.h:
+        (JSC::NewSpace::forEachBlock): Added forEachBlock, to use for
+        NewSpace-specific operations.
+
+        * heap/OldSpace.cpp: Added.
+        (JSC::OldSpace::OldSpace):
+        (JSC::OldSpace::addBlock):
+        (JSC::OldSpace::removeBlock):
+        * heap/OldSpace.h: Added.
+        (JSC::OldSpace::forEachBlock): New class for holding promoted blocks.
+        Not in use yet.
+
 2011-06-09  Hyowon Kim  <hw1008.kim@samsung.com>
 
         Reviewed by Antonio Gomes.
index baa3ae2..30eabd9 100644 (file)
@@ -121,6 +121,8 @@ javascriptcore_sources += \
        Source/JavaScriptCore/heap/TinyBloomFilter.h \
        Source/JavaScriptCore/heap/NewSpace.cpp \
        Source/JavaScriptCore/heap/NewSpace.h \
+       Source/JavaScriptCore/heap/OldSpace.cpp \
+       Source/JavaScriptCore/heap/OldSpace.h \
        Source/JavaScriptCore/heap/Strong.h \
        Source/JavaScriptCore/heap/Weak.h \
        Source/JavaScriptCore/config.h \
index 3435f3c..5fed0ef 100644 (file)
             'heap/TinyBloomFilter.h',
             'heap/NewSpace.cpp',
             'heap/NewSpace.h',
+            'heap/OldSpace.cpp',
+            'heap/OldSpace.h',
             'debugger/Debugger.cpp',
             'debugger/DebuggerActivation.cpp',
             'debugger/DebuggerCallFrame.cpp',
index dd0908d..831eb97 100644 (file)
@@ -78,6 +78,7 @@ SOURCES += \
     heap/MarkStack.cpp \
     heap/MarkedBlock.cpp \
     heap/NewSpace.cpp \
+    heap/OldSpace.cpp \
     debugger/DebuggerActivation.cpp \
     debugger/DebuggerCallFrame.cpp \
     debugger/Debugger.cpp \
index 9a39ddd..32a3f9d 100644 (file)
                                     >
                             </File>
                             <File
+                                    RelativePath="..\..\heap\OldSpace.cpp"
+                                    >
+                            </File>
+                            <File
+                                    RelativePath="..\..\heap\OldSpace.h"
+                                    >
+                            </File>
+                            <File
                                     RelativePath="..\..\heap\MarkStack.cpp"
                                     >
                             </File>
index cb44efa..0ca3aba 100644 (file)
@@ -85,6 +85,8 @@
                1429D8DE0ED2205B00B89619 /* CallFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 1429D8DC0ED2205B00B89619 /* CallFrame.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1429D92F0ED22D7000B89619 /* JIT.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1429D92D0ED22D7000B89619 /* JIT.cpp */; };
                1429D9300ED22D7000B89619 /* JIT.h in Headers */ = {isa = PBXBuildFile; fileRef = 1429D92E0ED22D7000B89619 /* JIT.h */; };
+               142A1D8313A19C84009DA5FE /* OldSpace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 142A1D8113A19C84009DA5FE /* OldSpace.cpp */; };
+               142A1D8413A19C84009DA5FE /* OldSpace.h in Headers */ = {isa = PBXBuildFile; fileRef = 142A1D8213A19C84009DA5FE /* OldSpace.h */; };
                142D3939103E4560007DCB52 /* NumericStrings.h in Headers */ = {isa = PBXBuildFile; fileRef = 142D3938103E4560007DCB52 /* NumericStrings.h */; settings = {ATTRIBUTES = (Private, ); }; };
                142D6F0813539A2800B02E86 /* MarkedBlock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 142D6F0613539A2800B02E86 /* MarkedBlock.cpp */; };
                142D6F0913539A2800B02E86 /* MarkedBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = 142D6F0713539A2800B02E86 /* MarkedBlock.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1429D8DC0ED2205B00B89619 /* CallFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CallFrame.h; sourceTree = "<group>"; };
                1429D92D0ED22D7000B89619 /* JIT.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JIT.cpp; sourceTree = "<group>"; };
                1429D92E0ED22D7000B89619 /* JIT.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JIT.h; sourceTree = "<group>"; };
+               142A1D8113A19C84009DA5FE /* OldSpace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OldSpace.cpp; sourceTree = "<group>"; };
+               142A1D8213A19C84009DA5FE /* OldSpace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OldSpace.h; sourceTree = "<group>"; };
                142D3938103E4560007DCB52 /* NumericStrings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NumericStrings.h; sourceTree = "<group>"; };
                142D6F0613539A2800B02E86 /* MarkedBlock.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MarkedBlock.cpp; sourceTree = "<group>"; };
                142D6F0713539A2800B02E86 /* MarkedBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MarkedBlock.h; sourceTree = "<group>"; };
                                14B7234012D7D0DA003BD5ED /* MachineStackMarker.h */,
                                142D6F0613539A2800B02E86 /* MarkedBlock.cpp */,
                                142D6F0713539A2800B02E86 /* MarkedBlock.h */,
+                               141448CA13A176EC00F5BA1A /* MarkedBlockSet.h */,
                                142D6F0E13539A4100B02E86 /* MarkStack.cpp */,
                                142D6F0F13539A4100B02E86 /* MarkStack.h */,
                                14D2F3D8139F4BE200491031 /* NewSpace.cpp */,
                                14D2F3D9139F4BE200491031 /* NewSpace.h */,
+                               142A1D8113A19C84009DA5FE /* OldSpace.cpp */,
+                               142A1D8213A19C84009DA5FE /* OldSpace.h */,
                                142E3132134FF0A600AFADB5 /* Strong.h */,
-                               142E3133134FF0A600AFADB5 /* Weak.h */,
-                               141448CA13A176EC00F5BA1A /* MarkedBlockSet.h */,
                                141448CC13A1783700F5BA1A /* TinyBloomFilter.h */,
+                               142E3133134FF0A600AFADB5 /* Weak.h */,
                        );
                        path = heap;
                        sourceTree = "<group>";
                                14D2F3DB139F4BE200491031 /* NewSpace.h in Headers */,
                                141448CB13A176EC00F5BA1A /* MarkedBlockSet.h in Headers */,
                                141448CD13A1783700F5BA1A /* TinyBloomFilter.h in Headers */,
+                               142A1D8413A19C84009DA5FE /* OldSpace.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                7934BB7C1361979400CB99A1 /* ParallelJobsGeneric.cpp in Sources */,
                                86BB09C0138E381B0056702F /* DFGRepatch.cpp in Sources */,
                                14D2F3DA139F4BE200491031 /* NewSpace.cpp in Sources */,
+                               142A1D8313A19C84009DA5FE /* OldSpace.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 7ffac18..9393cbe 100644 (file)
@@ -50,6 +50,7 @@ void MarkedBlock::destroy(MarkedBlock* block)
 
 MarkedBlock::MarkedBlock(const PageAllocationAligned& allocation, Heap* heap, size_t cellSize)
     : m_nextAtom(firstAtom())
+    , m_inNewSpace(false)
     , m_allocation(allocation)
     , m_heap(heap)
 {
index 7653883..b5b35be 100644 (file)
@@ -58,6 +58,9 @@ namespace JSC {
         static size_t firstAtom();
         
         Heap* heap() const;
+        
+        bool inNewSpace();
+        void setInNewSpace(bool);
 
         void* allocate();
         void resetAllocator();
@@ -97,6 +100,7 @@ namespace JSC {
         size_t m_endAtom; // This is a fuzzy end. Always test for < m_endAtom.
         size_t m_atomsPerCell;
         WTF::Bitmap<blockSize / atomSize> m_marks;
+        bool m_inNewSpace;
         PageAllocationAligned m_allocation;
         Heap* m_heap;
         MarkedBlock* m_prev;
@@ -128,6 +132,16 @@ namespace JSC {
         return m_heap;
     }
 
+    inline bool MarkedBlock::inNewSpace()
+    {
+        return m_inNewSpace;
+    }
+    
+    inline void MarkedBlock::setInNewSpace(bool inNewSpace)
+    {
+        m_inNewSpace = inNewSpace;
+    }
+
     inline void MarkedBlock::resetAllocator()
     {
         m_nextAtom = firstAtom();
index fb7195b..b591d4b 100644 (file)
@@ -45,12 +45,14 @@ NewSpace::NewSpace(Heap* heap)
 
 void NewSpace::addBlock(SizeClass& sizeClass, MarkedBlock* block)
 {
+    block->setInNewSpace(true);
     sizeClass.nextBlock = block;
     sizeClass.blockList.append(block);
 }
 
 void NewSpace::removeBlock(MarkedBlock* block)
 {
+    block->setInNewSpace(false);
     SizeClass& sizeClass = sizeClassFor(block->cellSize());
     sizeClass.nextBlock = block->next();
     sizeClass.blockList.remove(block);
index bbc335a..e798cac 100644 (file)
@@ -61,6 +61,7 @@ namespace JSC {
 
         SizeClass& sizeClassFor(size_t);
         void* allocate(SizeClass&);
+        void resetAllocator();
 
         void addBlock(SizeClass&, MarkedBlock*);
         void removeBlock(MarkedBlock*);
@@ -69,7 +70,8 @@ namespace JSC {
         size_t highWaterMark();
         void setHighWaterMark(size_t);
 
-        void resetAllocator();
+        template<typename Functor> typename Functor::ReturnType forEachBlock(Functor&); // Safe to remove the current item while iterating.
+        template<typename Functor> typename Functor::ReturnType forEachBlock();
 
     private:
         // [ 8, 16... 128 )
@@ -124,6 +126,35 @@ namespace JSC {
         return 0;
     }
 
+    template <typename Functor> inline typename Functor::ReturnType NewSpace::forEachBlock(Functor& functor)
+    {
+        for (size_t i = 0; i < preciseCount; ++i) {
+            SizeClass& sizeClass = m_preciseSizeClasses[i];
+            MarkedBlock* next;
+            for (MarkedBlock* block = sizeClass.blockList.head(); block; block = next) {
+                next = block->next();
+                functor(block);
+            }
+        }
+
+        for (size_t i = 0; i < impreciseCount; ++i) {
+            SizeClass& sizeClass = m_impreciseSizeClasses[i];
+            MarkedBlock* next;
+            for (MarkedBlock* block = sizeClass.blockList.head(); block; block = next) {
+                next = block->next();
+                functor(block);
+            }
+        }
+
+        return functor.returnValue();
+    }
+
+    template <typename Functor> inline typename Functor::ReturnType NewSpace::forEachBlock()
+    {
+        Functor functor;
+        return forEachBlock(functor);
+    }
+
     inline NewSpace::SizeClass::SizeClass()
         : nextBlock(0)
         , cellSize(0)
diff --git a/Source/JavaScriptCore/heap/OldSpace.cpp b/Source/JavaScriptCore/heap/OldSpace.cpp
new file mode 100644 (file)
index 0000000..549ba93
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "OldSpace.h"
+
+namespace JSC {
+
+OldSpace::OldSpace(Heap* heap)
+    : m_heap(heap)
+{
+}
+
+void OldSpace::addBlock(MarkedBlock* block)
+{
+    m_blocks.append(block);
+}
+
+void OldSpace::removeBlock(MarkedBlock* block)
+{
+    m_blocks.remove(block);
+}
+
+} // namespace JSC
diff --git a/Source/JavaScriptCore/heap/OldSpace.h b/Source/JavaScriptCore/heap/OldSpace.h
new file mode 100644 (file)
index 0000000..979d8bf
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef OldSpace_h
+#define OldSpace_h
+
+#include "MarkedBlock.h"
+#include <wtf/DoublyLinkedList.h>
+#include <wtf/NonCopyable.h>
+
+namespace JSC {
+    
+class Heap;
+
+class OldSpace {
+    WTF_MAKE_NONCOPYABLE(OldSpace);
+public:
+    OldSpace(Heap*);
+
+    void addBlock(MarkedBlock*);
+    void removeBlock(MarkedBlock*);
+
+    template<typename Functor> typename Functor::ReturnType forEachBlock();
+    template<typename Functor> typename Functor::ReturnType forEachBlock(Functor&);
+
+private:
+    DoublyLinkedList<MarkedBlock> m_blocks;
+    Heap* m_heap;
+};
+
+template <typename Functor> inline typename Functor::ReturnType OldSpace::forEachBlock(Functor& functor)
+{
+    MarkedBlock* next;
+    for (MarkedBlock* block = m_blocks.head(); block; block = next) {
+        next = block->next();
+        functor(block);
+    }
+
+    return functor.returnValue();
+}
+
+template <typename Functor> inline typename Functor::ReturnType OldSpace::forEachBlock()
+{
+    Functor functor;
+    return forEachBlock(functor);
+}
+
+} // namespace JSC
+
+#endif // OldSpace_h