Title: [169148] branches/ftlopt/Source/_javascript_Core
Revision
169148
Author
[email protected]
Date
2014-05-20 22:16:40 -0700 (Tue, 20 May 2014)

Log Message

[ftlopt] A StructureSet with one element should only require one word and no allocation
https://bugs.webkit.org/show_bug.cgi?id=133014

Reviewed by Oliver Hunt.
        
This makes it more efficient to use StructureSet in situations where the common case is
just one structure.
        
I also took the opportunity to use the same set terminology we use in BitVector: merge,
filter, exclude, contains, etc.
        
Eventually, this will be used to implement StructureAbstractValue as well.

* CMakeLists.txt:
* _javascript_Core.vcxproj/_javascript_Core.vcxproj:
* _javascript_Core.xcodeproj/project.pbxproj:
* bytecode/StructureSet.cpp: Added.
(JSC::StructureSet::StructureSet):
(JSC::StructureSet::operator=):
(JSC::StructureSet::clear):
(JSC::StructureSet::add):
(JSC::StructureSet::remove):
(JSC::StructureSet::contains):
(JSC::StructureSet::merge):
(JSC::StructureSet::filter):
(JSC::StructureSet::exclude):
(JSC::StructureSet::isSubsetOf):
(JSC::StructureSet::overlaps):
(JSC::StructureSet::operator==):
(JSC::StructureSet::speculationFromStructures):
(JSC::StructureSet::arrayModesFromStructures):
(JSC::StructureSet::dumpInContext):
(JSC::StructureSet::dump):
(JSC::StructureSet::addOutOfLine):
(JSC::StructureSet::containsOutOfLine):
(JSC::StructureSet::copyFrom):
(JSC::StructureSet::OutOfLineList::create):
(JSC::StructureSet::OutOfLineList::destroy):
* bytecode/StructureSet.h:
(JSC::StructureSet::StructureSet):
(JSC::StructureSet::~StructureSet):
(JSC::StructureSet::onlyStructure):
(JSC::StructureSet::isEmpty):
(JSC::StructureSet::size):
(JSC::StructureSet::at):
(JSC::StructureSet::operator[]):
(JSC::StructureSet::last):
(JSC::StructureSet::OutOfLineList::list):
(JSC::StructureSet::OutOfLineList::OutOfLineList):
(JSC::StructureSet::deleteStructureListIfNecessary):
(JSC::StructureSet::isThin):
(JSC::StructureSet::pointer):
(JSC::StructureSet::singleStructure):
(JSC::StructureSet::structureList):
(JSC::StructureSet::set):
(JSC::StructureSet::clear): Deleted.
(JSC::StructureSet::add): Deleted.
(JSC::StructureSet::addAll): Deleted.
(JSC::StructureSet::remove): Deleted.
(JSC::StructureSet::contains): Deleted.
(JSC::StructureSet::containsOnly): Deleted.
(JSC::StructureSet::isSubsetOf): Deleted.
(JSC::StructureSet::overlaps): Deleted.
(JSC::StructureSet::singletonStructure): Deleted.
(JSC::StructureSet::speculationFromStructures): Deleted.
(JSC::StructureSet::arrayModesFromStructures): Deleted.
(JSC::StructureSet::operator==): Deleted.
(JSC::StructureSet::dumpInContext): Deleted.
(JSC::StructureSet::dump): Deleted.
* dfg/DFGAbstractInterpreterInlines.h:
(JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
* dfg/DFGByteCodeParser.cpp:
(JSC::DFG::ByteCodeParser::emitPrototypeChecks):
(JSC::DFG::ByteCodeParser::handleGetById):
(JSC::DFG::ByteCodeParser::parseBlock):
* dfg/DFGCSEPhase.cpp:
(JSC::DFG::CSEPhase::structureTransitionWatchpointElimination):
* dfg/DFGNode.h:
(JSC::DFG::Node::convertToStructureTransitionWatchpoint):
* dfg/DFGTypeCheckHoistingPhase.cpp:
(JSC::DFG::TypeCheckHoistingPhase::noticeStructureCheck):

Modified Paths

Added Paths

Diff

Modified: branches/ftlopt/Source/_javascript_Core/CMakeLists.txt (169147 => 169148)


--- branches/ftlopt/Source/_javascript_Core/CMakeLists.txt	2014-05-21 04:59:06 UTC (rev 169147)
+++ branches/ftlopt/Source/_javascript_Core/CMakeLists.txt	2014-05-21 05:16:40 UTC (rev 169148)
@@ -89,6 +89,7 @@
     bytecode/SamplingTool.cpp
     bytecode/SpecialPointer.cpp
     bytecode/SpeculatedType.cpp
+    bytecode/StructureSet.cpp
     bytecode/StructureStubClearingWatchpoint.cpp
     bytecode/StructureStubInfo.cpp
     bytecode/UnlinkedCodeBlock.cpp

Modified: branches/ftlopt/Source/_javascript_Core/ChangeLog (169147 => 169148)


--- branches/ftlopt/Source/_javascript_Core/ChangeLog	2014-05-21 04:59:06 UTC (rev 169147)
+++ branches/ftlopt/Source/_javascript_Core/ChangeLog	2014-05-21 05:16:40 UTC (rev 169148)
@@ -1,3 +1,87 @@
+2014-05-16  Filip Pizlo  <[email protected]>
+
+        [ftlopt] A StructureSet with one element should only require one word and no allocation
+        https://bugs.webkit.org/show_bug.cgi?id=133014
+
+        Reviewed by Oliver Hunt.
+        
+        This makes it more efficient to use StructureSet in situations where the common case is
+        just one structure.
+        
+        I also took the opportunity to use the same set terminology we use in BitVector: merge,
+        filter, exclude, contains, etc.
+        
+        Eventually, this will be used to implement StructureAbstractValue as well.
+
+        * CMakeLists.txt:
+        * _javascript_Core.vcxproj/_javascript_Core.vcxproj:
+        * _javascript_Core.xcodeproj/project.pbxproj:
+        * bytecode/StructureSet.cpp: Added.
+        (JSC::StructureSet::StructureSet):
+        (JSC::StructureSet::operator=):
+        (JSC::StructureSet::clear):
+        (JSC::StructureSet::add):
+        (JSC::StructureSet::remove):
+        (JSC::StructureSet::contains):
+        (JSC::StructureSet::merge):
+        (JSC::StructureSet::filter):
+        (JSC::StructureSet::exclude):
+        (JSC::StructureSet::isSubsetOf):
+        (JSC::StructureSet::overlaps):
+        (JSC::StructureSet::operator==):
+        (JSC::StructureSet::speculationFromStructures):
+        (JSC::StructureSet::arrayModesFromStructures):
+        (JSC::StructureSet::dumpInContext):
+        (JSC::StructureSet::dump):
+        (JSC::StructureSet::addOutOfLine):
+        (JSC::StructureSet::containsOutOfLine):
+        (JSC::StructureSet::copyFrom):
+        (JSC::StructureSet::OutOfLineList::create):
+        (JSC::StructureSet::OutOfLineList::destroy):
+        * bytecode/StructureSet.h:
+        (JSC::StructureSet::StructureSet):
+        (JSC::StructureSet::~StructureSet):
+        (JSC::StructureSet::onlyStructure):
+        (JSC::StructureSet::isEmpty):
+        (JSC::StructureSet::size):
+        (JSC::StructureSet::at):
+        (JSC::StructureSet::operator[]):
+        (JSC::StructureSet::last):
+        (JSC::StructureSet::OutOfLineList::list):
+        (JSC::StructureSet::OutOfLineList::OutOfLineList):
+        (JSC::StructureSet::deleteStructureListIfNecessary):
+        (JSC::StructureSet::isThin):
+        (JSC::StructureSet::pointer):
+        (JSC::StructureSet::singleStructure):
+        (JSC::StructureSet::structureList):
+        (JSC::StructureSet::set):
+        (JSC::StructureSet::clear): Deleted.
+        (JSC::StructureSet::add): Deleted.
+        (JSC::StructureSet::addAll): Deleted.
+        (JSC::StructureSet::remove): Deleted.
+        (JSC::StructureSet::contains): Deleted.
+        (JSC::StructureSet::containsOnly): Deleted.
+        (JSC::StructureSet::isSubsetOf): Deleted.
+        (JSC::StructureSet::overlaps): Deleted.
+        (JSC::StructureSet::singletonStructure): Deleted.
+        (JSC::StructureSet::speculationFromStructures): Deleted.
+        (JSC::StructureSet::arrayModesFromStructures): Deleted.
+        (JSC::StructureSet::operator==): Deleted.
+        (JSC::StructureSet::dumpInContext): Deleted.
+        (JSC::StructureSet::dump): Deleted.
+        * dfg/DFGAbstractInterpreterInlines.h:
+        (JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
+        * dfg/DFGByteCodeParser.cpp:
+        (JSC::DFG::ByteCodeParser::emitPrototypeChecks):
+        (JSC::DFG::ByteCodeParser::handleGetById):
+        (JSC::DFG::ByteCodeParser::parseBlock):
+        * dfg/DFGCSEPhase.cpp:
+        (JSC::DFG::CSEPhase::structureTransitionWatchpointElimination):
+        * dfg/DFGNode.h:
+        (JSC::DFG::Node::convertToStructureTransitionWatchpoint):
+        * dfg/DFGTypeCheckHoistingPhase.cpp:
+        (JSC::DFG::TypeCheckHoistingPhase::noticeStructureCheck):
+
 2014-05-20  Filip Pizlo  <[email protected]>
 
         [ftlopt] DFG bytecode parser should turn GetById with nothing but a Getter stub as stuff+handleCall, and handleCall should be allowed to inline if it wants to

Modified: branches/ftlopt/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj (169147 => 169148)


--- branches/ftlopt/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj	2014-05-21 04:59:06 UTC (rev 169147)
+++ branches/ftlopt/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj	2014-05-21 05:16:40 UTC (rev 169148)
@@ -343,6 +343,7 @@
     <ClCompile Include="..\bytecode\SamplingTool.cpp" />
     <ClCompile Include="..\bytecode\SpecialPointer.cpp" />
     <ClCompile Include="..\bytecode\SpeculatedType.cpp" />
+    <ClCompile Include="..\bytecode\StructureSet.cpp" />
     <ClCompile Include="..\bytecode\StructureStubClearingWatchpoint.cpp" />
     <ClCompile Include="..\bytecode\StructureStubInfo.cpp" />
     <ClCompile Include="..\bytecode\UnlinkedCodeBlock.cpp" />

Modified: branches/ftlopt/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj (169147 => 169148)


--- branches/ftlopt/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2014-05-21 04:59:06 UTC (rev 169147)
+++ branches/ftlopt/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2014-05-21 05:16:40 UTC (rev 169148)
@@ -416,6 +416,7 @@
 		0FB14E1F18124ACE009B6B4D /* JITInlineCacheGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FB14E1D18124ACE009B6B4D /* JITInlineCacheGenerator.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		0FB14E211812570B009B6B4D /* DFGInlineCacheWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FB14E201812570B009B6B4D /* DFGInlineCacheWrapper.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		0FB14E2318130955009B6B4D /* DFGInlineCacheWrapperInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FB14E2218130955009B6B4D /* DFGInlineCacheWrapperInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		0FB438A319270B1D00E1FBC9 /* StructureSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FB438A219270B1D00E1FBC9 /* StructureSet.cpp */; };
 		0FB5467714F59B5C002C2989 /* LazyOperandValueProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FB5467614F59AD1002C2989 /* LazyOperandValueProfile.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		0FB5467914F5C46B002C2989 /* LazyOperandValueProfile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FB5467814F5C468002C2989 /* LazyOperandValueProfile.cpp */; };
 		0FB5467B14F5C7E1002C2989 /* MethodOfGettingAValueProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FB5467A14F5C7D4002C2989 /* MethodOfGettingAValueProfile.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -2220,6 +2221,7 @@
 		0FB14E1D18124ACE009B6B4D /* JITInlineCacheGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JITInlineCacheGenerator.h; sourceTree = "<group>"; };
 		0FB14E201812570B009B6B4D /* DFGInlineCacheWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGInlineCacheWrapper.h; path = dfg/DFGInlineCacheWrapper.h; sourceTree = "<group>"; };
 		0FB14E2218130955009B6B4D /* DFGInlineCacheWrapperInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGInlineCacheWrapperInlines.h; path = dfg/DFGInlineCacheWrapperInlines.h; sourceTree = "<group>"; };
+		0FB438A219270B1D00E1FBC9 /* StructureSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StructureSet.cpp; sourceTree = "<group>"; };
 		0FB4B51016B3A964003F696B /* DFGMinifiedID.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGMinifiedID.h; path = dfg/DFGMinifiedID.h; sourceTree = "<group>"; };
 		0FB4B51916B62772003F696B /* DFGAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGAllocator.h; path = dfg/DFGAllocator.h; sourceTree = "<group>"; };
 		0FB4B51A16B62772003F696B /* DFGCommon.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DFGCommon.cpp; path = dfg/DFGCommon.cpp; sourceTree = "<group>"; };
@@ -5018,6 +5020,7 @@
 				0F5541B01613C1FB00CE3E25 /* SpecialPointer.h */,
 				0FD82E84141F3FDA00179C94 /* SpeculatedType.cpp */,
 				0FD82E4F141DAEA100179C94 /* SpeculatedType.h */,
+				0FB438A219270B1D00E1FBC9 /* StructureSet.cpp */,
 				0F93329B14CA7DC10085F3C6 /* StructureSet.h */,
 				0F766D3615AE4A1A008F363E /* StructureStubClearingWatchpoint.cpp */,
 				0F766D3715AE4A1A008F363E /* StructureStubClearingWatchpoint.h */,
@@ -7178,6 +7181,7 @@
 				2A83638918D7D0FE0000EBCC /* FullGCActivityCallback.cpp in Sources */,
 				1428083A107EC0750013E7B2 /* JSStack.cpp in Sources */,
 				147F39D5107EC37600427A48 /* JSString.cpp in Sources */,
+				0FB438A319270B1D00E1FBC9 /* StructureSet.cpp in Sources */,
 				2600B5A6152BAAA70091EE5F /* JSStringJoiner.cpp in Sources */,
 				1482B74E0A43032800517CFC /* JSStringRef.cpp in Sources */,
 				146AAB380B66A94400E55F16 /* JSStringRefCF.cpp in Sources */,

Added: branches/ftlopt/Source/_javascript_Core/bytecode/StructureSet.cpp (0 => 169148)


--- branches/ftlopt/Source/_javascript_Core/bytecode/StructureSet.cpp	                        (rev 0)
+++ branches/ftlopt/Source/_javascript_Core/bytecode/StructureSet.cpp	2014-05-21 05:16:40 UTC (rev 169148)
@@ -0,0 +1,350 @@
+/*
+ * Copyright (C) 2014 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. ``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
+ * 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 "StructureSet.h"
+
+#include <wtf/CommaPrinter.h>
+
+namespace JSC {
+
+StructureSet::StructureSet(const StructureSet& other)
+{
+    copyFrom(other);
+}
+
+StructureSet& StructureSet::operator=(const StructureSet& other)
+{
+    if (this == &other)
+        return *this;
+    deleteStructureListIfNecessary();
+    copyFrom(other);
+    return *this;
+}
+
+void StructureSet::clear()
+{
+    deleteStructureListIfNecessary();
+    set(0, true);
+}
+
+bool StructureSet::add(Structure* structure)
+{
+    ASSERT(structure);
+    if (isThin()) {
+        if (singleStructure() == structure)
+            return false;
+        if (!singleStructure()) {
+            set(structure);
+            return true;
+        }
+        OutOfLineList* list = OutOfLineList::create(defaultStartingSize);
+        list->m_length = 2;
+        list->list()[0] = singleStructure();
+        list->list()[1] = structure;
+        set(list);
+        return true;
+    }
+    
+    return addOutOfLine(structure);
+}
+
+bool StructureSet::remove(Structure* structure)
+{
+    if (isThin()) {
+        if (singleStructure() == structure) {
+            set(0, true);
+            return true;
+        }
+        return false;
+    }
+    
+    OutOfLineList* list = structureList();
+    for (unsigned i = 0; i < list->m_length; ++i) {
+        if (list->list()[i] != structure)
+            continue;
+        list->list()[i] = list->list()[--list->m_length];
+        if (!list->m_length) {
+            OutOfLineList::destroy(list);
+            set(0, true);
+        }
+        return true;
+    }
+    return false;
+}
+
+bool StructureSet::contains(Structure* structure) const
+{
+    if (isThin())
+        return singleStructure() == structure;
+
+    return containsOutOfLine(structure);
+}
+
+bool StructureSet::merge(const StructureSet& other)
+{
+    if (other.isThin()) {
+        if (other.singleStructure())
+            return add(other.singleStructure());
+        return false;
+    }
+    
+    OutOfLineList* list = other.structureList();
+    if (list->m_length >= 2) {
+        if (isThin()) {
+            OutOfLineList* myNewList = OutOfLineList::create(
+                list->m_length + !!singleStructure());
+            if (singleStructure()) {
+                myNewList->m_length = 1;
+                myNewList->list()[0] = singleStructure();
+            }
+            set(myNewList);
+        }
+        bool changed = false;
+        for (unsigned i = 0; i < list->m_length; ++i)
+            changed |= addOutOfLine(list->list()[i]);
+        return changed;
+    }
+    
+    ASSERT(list->m_length);
+    return add(list->list()[0]);
+}
+
+void StructureSet::filter(const StructureSet& other)
+{
+    if (other.isThin()) {
+        if (!other.singleStructure() || !contains(other.singleStructure()))
+            clear();
+        else {
+            clear();
+            set(other.singleStructure());
+        }
+        return;
+    }
+    
+    if (isThin()) {
+        if (!singleStructure())
+            return;
+        if (other.containsOutOfLine(singleStructure()))
+            return;
+        clear();
+        return;
+    }
+    
+    OutOfLineList* list = structureList();
+    for (unsigned i = 0; i < list->m_length; ++i) {
+        if (other.containsOutOfLine(list->list()[i]))
+            continue;
+        list->list()[i--] = list->list()[--list->m_length];
+    }
+    if (!list->m_length)
+        clear();
+}
+
+void StructureSet::exclude(const StructureSet& other)
+{
+    if (other.isThin()) {
+        if (other.singleStructure())
+            remove(other.singleStructure());
+        return;
+    }
+    
+    if (isThin()) {
+        if (!singleStructure())
+            return;
+        if (other.contains(singleStructure()))
+            clear();
+        return;
+    }
+    
+    OutOfLineList* list = structureList();
+    for (unsigned i = 0; i < list->m_length; ++i) {
+        if (!other.containsOutOfLine(list->list()[i]))
+            continue;
+        list->list()[i--] = list->list()[--list->m_length];
+    }
+    if (!list->m_length)
+        clear();
+}
+
+bool StructureSet::isSubsetOf(const StructureSet& other) const
+{
+    if (isThin()) {
+        if (!singleStructure())
+            return true;
+        return other.contains(singleStructure());
+    }
+    
+    if (other.isThin()) {
+        if (!other.singleStructure())
+            return false;
+        OutOfLineList* list = structureList();
+        if (list->m_length >= 2)
+            return false;
+        if (list->list()[0] == other.singleStructure())
+            return true;
+        return false;
+    }
+    
+    OutOfLineList* list = structureList();
+    for (unsigned i = 0; i < list->m_length; ++i) {
+        if (!other.containsOutOfLine(list->list()[i]))
+            return false;
+    }
+    return true;
+}
+
+bool StructureSet::overlaps(const StructureSet& other) const
+{
+    if (isThin()) {
+        if (!singleStructure())
+            return false;
+        return other.contains(singleStructure());
+    }
+    
+    if (other.isThin()) {
+        if (!other.singleStructure())
+            return false;
+        return containsOutOfLine(other.singleStructure());
+    }
+    
+    OutOfLineList* list = structureList();
+    for (unsigned i = 0; i < list->m_length; ++i) {
+        if (other.containsOutOfLine(list->list()[i]))
+            return true;
+    }
+    return false;
+}
+
+bool StructureSet::operator==(const StructureSet& other) const
+{
+    if (size() != other.size())
+        return false;
+    return isSubsetOf(other);
+}
+
+SpeculatedType StructureSet::speculationFromStructures() const
+{
+    if (isThin()) {
+        if (!singleStructure())
+            return SpecNone;
+        return speculationFromStructure(singleStructure());
+    }
+    
+    SpeculatedType result = SpecNone;
+    OutOfLineList* list = structureList();
+    for (unsigned i = 0; i < list->m_length; ++i)
+        mergeSpeculation(result, speculationFromStructure(list->list()[i]));
+    return result;
+}
+
+ArrayModes StructureSet::arrayModesFromStructures() const
+{
+    if (isThin()) {
+        if (!singleStructure())
+            return 0;
+        return asArrayModes(singleStructure()->indexingType());
+    }
+    
+    ArrayModes result = 0;
+    OutOfLineList* list = structureList();
+    for (unsigned i = 0; i < list->m_length; ++i)
+        mergeArrayModes(result, asArrayModes(list->list()[i]->indexingType()));
+    return result;
+}
+
+void StructureSet::dumpInContext(PrintStream& out, DumpContext* context) const
+{
+    CommaPrinter comma;
+    out.print("[");
+    for (size_t i = 0; i < size(); ++i)
+        out.print(comma, inContext(*at(i), context));
+    out.print("]");
+}
+
+void StructureSet::dump(PrintStream& out) const
+{
+    dumpInContext(out, nullptr);
+}
+
+bool StructureSet::addOutOfLine(Structure* structure)
+{
+    OutOfLineList* list = structureList();
+    for (unsigned i = 0; i < list->m_length; ++i) {
+        if (list->list()[i] == structure)
+            return false;
+    }
+    
+    if (list->m_length < list->m_capacity) {
+        list->list()[list->m_length++] = structure;
+        return true;
+    }
+    
+    OutOfLineList* newList = OutOfLineList::create(list->m_capacity * 2);
+    newList->m_length = list->m_length + 1;
+    for (unsigned i = list->m_length; i--;)
+        newList->list()[i] = list->list()[i];
+    newList->list()[list->m_length] = structure;
+    set(newList);
+    return true;
+}
+
+bool StructureSet::containsOutOfLine(Structure* structure) const
+{
+    OutOfLineList* list = structureList();
+    for (unsigned i = 0; i < list->m_length; ++i) {
+        if (list->list()[i] == structure)
+            return true;
+    }
+    return false;
+}
+
+void StructureSet::copyFrom(const StructureSet& other)
+{
+    if (other.isThin()) {
+        m_pointer = other.m_pointer;
+        return;
+    }
+    
+    OutOfLineList* otherList = other.structureList();
+    OutOfLineList* myList = OutOfLineList::create(otherList->m_length);
+    myList->m_length = otherList->m_length;
+    for (unsigned i = otherList->m_length; i--;)
+        myList->list()[i] = otherList->list()[i];
+    set(myList);
+}
+
+StructureSet::OutOfLineList* StructureSet::OutOfLineList::create(unsigned capacity)
+{
+    return new (NotNull, fastMalloc(sizeof(OutOfLineList) + capacity * sizeof(Structure*))) OutOfLineList(0, capacity);
+}
+
+void StructureSet::OutOfLineList::destroy(OutOfLineList* list)
+{
+    fastFree(list);
+}
+
+} // namespace JSC
+

Modified: branches/ftlopt/Source/_javascript_Core/bytecode/StructureSet.h (169147 => 169148)


--- branches/ftlopt/Source/_javascript_Core/bytecode/StructureSet.h	2014-05-21 04:59:06 UTC (rev 169147)
+++ branches/ftlopt/Source/_javascript_Core/bytecode/StructureSet.h	2014-05-21 05:16:40 UTC (rev 169148)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2011, 2013, 2014 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -30,167 +30,167 @@
 #include "SpeculatedType.h"
 #include "Structure.h"
 #include "DumpContext.h"
-#include <wtf/CommaPrinter.h>
-#include <wtf/Vector.h>
 
 namespace JSC {
 
-namespace DFG {
-class StructureAbstractValue;
-}
-
 class StructureSet {
 public:
-    StructureSet() { }
-    
-    StructureSet(Structure* structure)
+    StructureSet()
     {
-        ASSERT(structure);
-        m_structures.append(structure);
+        set(0, true);
     }
     
-    void clear()
+    StructureSet(Structure* structure)
     {
-        m_structures.clear();
+        set(structure);
     }
     
-    void add(Structure* structure)
+    StructureSet(const StructureSet& other);
+    StructureSet& operator=(const StructureSet& other);
+    
+    ~StructureSet()
     {
-        ASSERT(structure);
-        ASSERT(!contains(structure));
-        m_structures.append(structure);
+        deleteStructureListIfNecessary();
     }
     
-    bool addAll(const StructureSet& other)
+    void clear();
+    
+    Structure* onlyStructure() const
     {
-        bool changed = false;
-        for (size_t i = 0; i < other.size(); ++i) {
-            if (contains(other[i]))
-                continue;
-            add(other[i]);
-            changed = true;
+        if (isThin()) {
+            ASSERT(singleStructure());
+            return singleStructure();
         }
-        return changed;
+        ASSERT(structureList()->m_length == 1);
+        return structureList()->list()[0];
     }
     
-    void remove(Structure* structure)
+    bool isEmpty() const
     {
-        for (size_t i = 0; i < m_structures.size(); ++i) {
-            if (m_structures[i] != structure)
-                continue;
-            
-            m_structures[i] = m_structures.last();
-            m_structures.removeLast();
-            return;
-        }
+        return isThin() && !singleStructure();
     }
     
-    bool contains(Structure* structure) const
+    bool add(Structure*);
+    bool remove(Structure*);
+    bool contains(Structure*) const;
+    
+    bool merge(const StructureSet&);
+    void filter(const StructureSet&);
+    void exclude(const StructureSet&);
+    
+    bool isSubsetOf(const StructureSet&) const;
+    bool isSupersetOf(const StructureSet& other) const
     {
-        for (size_t i = 0; i < m_structures.size(); ++i) {
-            if (m_structures[i] == structure)
-                return true;
-        }
-        return false;
+        return other.isSubsetOf(*this);
     }
     
-    bool containsOnly(Structure* structure) const
+    bool overlaps(const StructureSet&) const;
+    
+    size_t size() const
     {
-        if (size() != 1)
-            return false;
-        return singletonStructure() == structure;
+        if (isThin())
+            return !!singleStructure();
+        return structureList()->m_length;
     }
     
-    bool isSubsetOf(const StructureSet& other) const
+    Structure* at(size_t i) const
     {
-        for (size_t i = 0; i < m_structures.size(); ++i) {
-            if (!other.contains(m_structures[i]))
-                return false;
+        if (isThin()) {
+            ASSERT(!i);
+            ASSERT(singleStructure());
+            return singleStructure();
         }
-        return true;
+        ASSERT(i < structureList()->m_length);
+        return structureList()->list()[i];
     }
     
-    bool isSupersetOf(const StructureSet& other) const
-    {
-        return other.isSubsetOf(*this);
-    }
+    Structure* operator[](size_t i) const { return at(i); }
     
-    bool overlaps(const StructureSet& other) const
+    Structure* last() const
     {
-        for (size_t i = 0; i < m_structures.size(); ++i) {
-            if (other.contains(m_structures[i]))
-                return true;
+        if (isThin()) {
+            ASSERT(singleStructure());
+            return singleStructure();
         }
-        return false;
+        return structureList()->list()[structureList()->m_length - 1];
     }
     
-    size_t size() const { return m_structures.size(); }
+    bool operator==(const StructureSet& other) const;
     
-    // Call this if you know that the structure set must consist of exactly
-    // one structure.
-    Structure* singletonStructure() const
-    {
-        ASSERT(m_structures.size() == 1);
-        return m_structures[0];
-    }
+    SpeculatedType speculationFromStructures() const;
+    ArrayModes arrayModesFromStructures() const;
     
-    Structure* at(size_t i) const { return m_structures.at(i); }
+    void dumpInContext(PrintStream&, DumpContext*) const;
+    void dump(PrintStream&) const;
     
-    Structure* operator[](size_t i) const { return at(i); }
+private:
+    static const uintptr_t thinFlag = 1;
+    static const uintptr_t reservedFlag = 2;
+    static const uintptr_t flags = 3;
+    static const uintptr_t reservedValue = 4;
+
+    static const unsigned defaultStartingSize = 4;
     
-    Structure* last() const { return m_structures.last(); }
+    bool addOutOfLine(Structure*);
+    bool containsOutOfLine(Structure*) const;
+    void copyFrom(const StructureSet&);
+    
+    class OutOfLineList {
+    public:
+        static OutOfLineList* create(unsigned capacity);
+        static void destroy(OutOfLineList*);
+        
+        Structure** list() { return bitwise_cast<Structure**>(this + 1); }
+        
+        OutOfLineList(unsigned length, unsigned capacity)
+            : m_length(length)
+            , m_capacity(capacity)
+        {
+        }
 
-    SpeculatedType speculationFromStructures() const
+        unsigned m_length;
+        unsigned m_capacity;
+    };
+    
+    void deleteStructureListIfNecessary()
     {
-        SpeculatedType result = SpecNone;
-        
-        for (size_t i = 0; i < m_structures.size(); ++i)
-            mergeSpeculation(result, speculationFromStructure(m_structures[i]));
-        
-        return result;
+        if (!isThin())
+            OutOfLineList::destroy(structureList());
     }
     
-    ArrayModes arrayModesFromStructures() const
+    bool isThin() const { return m_pointer & thinFlag; }
+    
+    void* pointer() const
     {
-        ArrayModes result = 0;
-        
-        for (size_t i = 0; i < m_structures.size(); ++i)
-            mergeArrayModes(result, asArrayModes(m_structures[i]->indexingType()));
-        
-        return result;
+        return bitwise_cast<void*>(m_pointer & ~flags);
     }
     
-    bool operator==(const StructureSet& other) const
+    Structure* singleStructure() const
     {
-        if (m_structures.size() != other.m_structures.size())
-            return false;
-        
-        for (size_t i = 0; i < m_structures.size(); ++i) {
-            if (!other.contains(m_structures[i]))
-                return false;
-        }
-        
-        return true;
+        ASSERT(isThin());
+        return static_cast<Structure*>(pointer());
     }
     
-    void dumpInContext(PrintStream& out, DumpContext* context) const
+    OutOfLineList* structureList() const
     {
-        CommaPrinter comma;
-        out.print("[");
-        for (size_t i = 0; i < m_structures.size(); ++i)
-            out.print(comma, inContext(*m_structures[i], context));
-        out.print("]");
+        ASSERT(!isThin());
+        return static_cast<OutOfLineList*>(pointer());
     }
     
-    void dump(PrintStream& out) const
+    void set(Structure* structure)
     {
-        dumpInContext(out, 0);
+        set(bitwise_cast<uintptr_t>(structure), true);
     }
-    
-private:
-    friend class DFG::StructureAbstractValue;
-    
-    Vector<Structure*, 2> m_structures;
+    void set(OutOfLineList* structures)
+    {
+        set(bitwise_cast<uintptr_t>(structures), false);
+    }
+    void set(uintptr_t pointer, bool singleStructure)
+    {
+        m_pointer = pointer | (singleStructure ? thinFlag : 0) | (m_pointer & reservedFlag);
+    }
+
+    uintptr_t m_pointer;
 };
 
 } // namespace JSC

Modified: branches/ftlopt/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h (169147 => 169148)


--- branches/ftlopt/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h	2014-05-21 04:59:06 UTC (rev 169147)
+++ branches/ftlopt/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h	2014-05-21 05:16:40 UTC (rev 169148)
@@ -1673,7 +1673,7 @@
         
         StructureSet set;
         for (unsigned i = node->multiGetByOffsetData().variants.size(); i--;)
-            set.addAll(node->multiGetByOffsetData().variants[i].structureSet());
+            set.merge(node->multiGetByOffsetData().variants[i].structureSet());
         
         filter(node->child1(), set);
         forNode(node).makeHeapTop();
@@ -1722,12 +1722,12 @@
             const PutByIdVariant& variant = node->multiPutByOffsetData().variants[i];
             if (variant.kind() == PutByIdVariant::Replace) {
                 if (value.m_currentKnownStructure.contains(variant.structure()))
-                    newSet.addAll(variant.structure());
+                    newSet.add(variant.structure());
                 continue;
             }
             ASSERT(variant.kind() == PutByIdVariant::Transition);
             if (value.m_currentKnownStructure.contains(variant.oldStructure()))
-                newSet.addAll(variant.newStructure());
+                newSet.add(variant.newStructure());
         }
         
         // Use filter(value, set) as a way of setting the structure set. This works because

Modified: branches/ftlopt/Source/_javascript_Core/dfg/DFGByteCodeParser.cpp (169147 => 169148)


--- branches/ftlopt/Source/_javascript_Core/dfg/DFGByteCodeParser.cpp	2014-05-21 04:59:06 UTC (rev 169147)
+++ branches/ftlopt/Source/_javascript_Core/dfg/DFGByteCodeParser.cpp	2014-05-21 05:16:40 UTC (rev 169148)
@@ -1898,6 +1898,7 @@
 Node* ByteCodeParser::emitPrototypeChecks(
     Structure* structure, IntendedStructureChain* chain)
 {
+    ASSERT(structure);
     Node* base = 0;
     m_graph.chains().addLazily(chain);
     Structure* currentStructure = structure;
@@ -1939,7 +1940,7 @@
         for (unsigned variantIndex = getByIdStatus.numVariants(); variantIndex--;) {
             if (getByIdStatus[variantIndex].chain()) {
                 emitPrototypeChecks(
-                    getByIdStatus[variantIndex].structureSet().singletonStructure(),
+                    getByIdStatus[variantIndex].structureSet().onlyStructure(),
                     getByIdStatus[variantIndex].chain());
             }
         }
@@ -1965,7 +1966,7 @@
     
     if (variant.chain()) {
         base = emitPrototypeChecks(
-            variant.structureSet().singletonStructure(), variant.chain());
+            variant.structureSet().onlyStructure(), variant.chain());
     }
     
     // Unless we want bugs like https://bugs.webkit.org/show_bug.cgi?id=88783, we need to
@@ -3108,7 +3109,7 @@
                     set(VirtualRegister(dst), addToGraph(GetByIdFlush, OpInfo(identifierNumber), OpInfo(prediction), get(VirtualRegister(scope))));
                     break;
                 }
-                Node* base = cellConstantWithStructureCheck(globalObject, status[0].structureSet().singletonStructure());
+                Node* base = cellConstantWithStructureCheck(globalObject, status[0].structureSet().onlyStructure());
                 addToGraph(Phantom, get(VirtualRegister(scope)));
                 if (JSValue specificValue = status[0].specificValue())
                     set(VirtualRegister(dst), cellConstant(specificValue.asCell()));

Modified: branches/ftlopt/Source/_javascript_Core/dfg/DFGCSEPhase.cpp (169147 => 169148)


--- branches/ftlopt/Source/_javascript_Core/dfg/DFGCSEPhase.cpp	2014-05-21 04:59:06 UTC (rev 169147)
+++ branches/ftlopt/Source/_javascript_Core/dfg/DFGCSEPhase.cpp	2014-05-21 05:16:40 UTC (rev 169148)
@@ -519,7 +519,7 @@
             switch (node->op()) {
             case CheckStructure:
                 if (node->child1() == child1
-                    && node->structureSet().containsOnly(structure))
+                    && node->structureSet().isSubsetOf(StructureSet(structure)))
                     return true;
                 break;
                 

Modified: branches/ftlopt/Source/_javascript_Core/dfg/DFGNode.h (169147 => 169148)


--- branches/ftlopt/Source/_javascript_Core/dfg/DFGNode.h	2014-05-21 04:59:06 UTC (rev 169147)
+++ branches/ftlopt/Source/_javascript_Core/dfg/DFGNode.h	2014-05-21 05:16:40 UTC (rev 169148)
@@ -490,13 +490,14 @@
         ASSERT(m_op == CheckStructure || m_op == ArrayifyToStructure);
         ASSERT(!child2());
         ASSERT(!child3());
+        ASSERT(structure);
         m_opInfo = bitwise_cast<uintptr_t>(structure);
         m_op = StructureTransitionWatchpoint;
     }
     
     void convertToStructureTransitionWatchpoint()
     {
-        convertToStructureTransitionWatchpoint(structureSet().singletonStructure());
+        convertToStructureTransitionWatchpoint(structureSet().onlyStructure());
     }
     
     void convertToGetByOffset(unsigned storageAccessDataIndex, Edge storage)

Modified: branches/ftlopt/Source/_javascript_Core/dfg/DFGTypeCheckHoistingPhase.cpp (169147 => 169148)


--- branches/ftlopt/Source/_javascript_Core/dfg/DFGTypeCheckHoistingPhase.cpp	2014-05-21 04:59:06 UTC (rev 169147)
+++ branches/ftlopt/Source/_javascript_Core/dfg/DFGTypeCheckHoistingPhase.cpp	2014-05-21 05:16:40 UTC (rev 169148)
@@ -503,7 +503,7 @@
             noticeStructureCheck(variable, 0);
             return;
         }
-        noticeStructureCheck(variable, set.singletonStructure());
+        noticeStructureCheck(variable, set.onlyStructure());
     }
 
     void noticeCheckArray(VariableAccessData* variable, ArrayMode arrayMode)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to