Commit e32f3e7d authored by rniwa@webkit.org's avatar rniwa@webkit.org
Browse files

Initialize AtomicStringTable in WTFThreadData's constructor

https://bugs.webkit.org/show_bug.cgi?id=117671

Reviewed by Geoffrey Garen.

Extracted AtomicStringTable from AtomicString.cpp into AtomicStringTable.h/cpp
and made WTFThreadDada::WTFThreadData create the atomic string table for the thread.

This eliminates a branch from stringTable() in AtomicString.cpp.

* GNUmakefile.list.am:
* WTF.pro:
* WTF.vcxproj/WTF.vcxproj:
* WTF.vcxproj/WTF.vcxproj.filters:
* WTF.xcodeproj/project.pbxproj:
* wtf/CMakeLists.txt:
* wtf/WTFThreadData.cpp:
(WTF::WTFThreadData::WTFThreadData):
* wtf/text/AtomicString.cpp:
(WTF::stringTable):
* wtf/text/AtomicStringTable.cpp: Added.
(WTF::AtomicStringTable::create):
(WTF::AtomicStringTable::destroy):
* wtf/text/AtomicStringTable.h: Added.
(WTF::AtomicStringTable::table):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@151663 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 30756939
2013-06-17 Ryosuke Niwa <rniwa@webkit.org>
Initialize AtomicStringTable in WTFThreadData's constructor
https://bugs.webkit.org/show_bug.cgi?id=117671
Reviewed by Geoffrey Garen.
Extracted AtomicStringTable from AtomicString.cpp into AtomicStringTable.h/cpp
and made WTFThreadDada::WTFThreadData create the atomic string table for the thread.
This eliminates a branch from stringTable() in AtomicString.cpp.
* GNUmakefile.list.am:
* WTF.pro:
* WTF.vcxproj/WTF.vcxproj:
* WTF.vcxproj/WTF.vcxproj.filters:
* WTF.xcodeproj/project.pbxproj:
* wtf/CMakeLists.txt:
* wtf/WTFThreadData.cpp:
(WTF::WTFThreadData::WTFThreadData):
* wtf/text/AtomicString.cpp:
(WTF::stringTable):
* wtf/text/AtomicStringTable.cpp: Added.
(WTF::AtomicStringTable::create):
(WTF::AtomicStringTable::destroy):
* wtf/text/AtomicStringTable.h: Added.
(WTF::AtomicStringTable::table):
2013-06-17 Roger Fong <roger_fong@apple.com>
 
Modify Windows makefiles to copy some bin output into Program Files.
......
......@@ -225,6 +225,8 @@ wtf_sources += \
Source/WTF/wtf/text/AtomicString.h \
Source/WTF/wtf/text/AtomicStringHash.h \
Source/WTF/wtf/text/AtomicStringImpl.h \
Source/WTF/wtf/text/AtomicStringTable.cpp \
Source/WTF/wtf/text/AtomicStringTable.h \
Source/WTF/wtf/text/Base64.cpp \
Source/WTF/wtf/text/Base64.h \
Source/WTF/wtf/text/CString.cpp \
......
......@@ -144,6 +144,7 @@ HEADERS += \
text/AtomicString.h \
text/AtomicStringHash.h \
text/AtomicStringImpl.h \
text/AtomicStringTable.h \
text/Base64.h \
text/CString.h \
text/IntegerToStringConversion.h \
......@@ -233,6 +234,7 @@ SOURCES += \
TypeTraits.cpp \
WTFThreadData.cpp \
text/AtomicString.cpp \
text/AtomicStringTable.cpp \
text/Base64.cpp \
text/CString.cpp \
text/StringBuilder.cpp \
......
......@@ -72,6 +72,7 @@
<ClCompile Include="..\wtf\StringPrintStream.cpp" />
<ClCompile Include="..\wtf\TCSystemAlloc.cpp" />
<ClCompile Include="..\wtf\text\AtomicString.cpp" />
<ClCompile Include="..\wtf\text\AtomicStringTable.cpp" />
<ClCompile Include="..\wtf\text\Base64.cpp" />
<ClCompile Include="..\wtf\text\CString.cpp" />
<ClCompile Include="..\wtf\text\StringBuilder.cpp" />
......@@ -223,6 +224,7 @@
<ClInclude Include="..\wtf\text\AtomicString.h" />
<ClInclude Include="..\wtf\text\AtomicStringHash.h" />
<ClInclude Include="..\wtf\text\AtomicStringImpl.h" />
<ClInclude Include="..\wtf\text\AtomicStringTable.h" />
<ClInclude Include="..\wtf\text\Base64.h" />
<ClInclude Include="..\wtf\text\CString.h" />
<ClInclude Include="..\wtf\text\IntegerToStringConversion.h" />
......
......@@ -261,6 +261,9 @@
<ClInclude Include="..\wtf\text\AtomicStringImpl.h">
<Filter>text</Filter>
</ClInclude>
<ClInclude Include="..\wtf\text\AtomicStringTable.h">
<Filter>text</Filter>
</ClInclude>
<ClInclude Include="..\wtf\text\Base64.h">
<Filter>text</Filter>
</ClInclude>
......
......@@ -54,6 +54,8 @@
8134013815B092FD001FF0B8 /* Base64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8134013615B092FD001FF0B8 /* Base64.cpp */; };
8134013915B092FD001FF0B8 /* Base64.h in Headers */ = {isa = PBXBuildFile; fileRef = 8134013715B092FD001FF0B8 /* Base64.h */; };
974CFC8E16A4F327006D5404 /* WeakPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 974CFC8D16A4F327006D5404 /* WeakPtr.h */; };
9BC70F05176C379D00101DEC /* AtomicStringTable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9BC70F04176C379D00101DEC /* AtomicStringTable.cpp */; };
9BD8F40B176C2B470002D865 /* AtomicStringTable.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BD8F40A176C2AD80002D865 /* AtomicStringTable.h */; };
A876DBD8151816E500DADB95 /* Platform.h in Headers */ = {isa = PBXBuildFile; fileRef = A876DBD7151816E500DADB95 /* Platform.h */; };
A8A4737F151A825B004123FF /* Alignment.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A47254151A825A004123FF /* Alignment.h */; };
A8A47381151A825B004123FF /* ArrayBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8A47256151A825A004123FF /* ArrayBuffer.cpp */; };
......@@ -323,6 +325,8 @@
8134013615B092FD001FF0B8 /* Base64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Base64.cpp; sourceTree = "<group>"; };
8134013715B092FD001FF0B8 /* Base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Base64.h; sourceTree = "<group>"; };
974CFC8D16A4F327006D5404 /* WeakPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakPtr.h; sourceTree = "<group>"; };
9BC70F04176C379D00101DEC /* AtomicStringTable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AtomicStringTable.cpp; sourceTree = "<group>"; };
9BD8F40A176C2AD80002D865 /* AtomicStringTable.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AtomicStringTable.h; sourceTree = "<group>"; };
A876DBD7151816E500DADB95 /* Platform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Platform.h; sourceTree = "<group>"; };
A8A47254151A825A004123FF /* Alignment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Alignment.h; sourceTree = "<group>"; };
A8A47256151A825A004123FF /* ArrayBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ArrayBuffer.cpp; sourceTree = "<group>"; };
......@@ -845,6 +849,8 @@
A8A4731E151A825B004123FF /* AtomicString.h */,
A8A4731F151A825B004123FF /* AtomicStringHash.h */,
A8A47320151A825B004123FF /* AtomicStringImpl.h */,
9BD8F40A176C2AD80002D865 /* AtomicStringTable.h */,
9BC70F04176C379D00101DEC /* AtomicStringTable.cpp */,
8134013615B092FD001FF0B8 /* Base64.cpp */,
8134013715B092FD001FF0B8 /* Base64.h */,
A8A47321151A825B004123FF /* CString.cpp */,
......@@ -914,6 +920,7 @@
1469419216EAAF6D0024E146 /* RunLoopTimer.h in Headers */,
1469419616EAAFF80024E146 /* SchedulePair.h in Headers */,
A8A47385151A825B004123FF /* ASCIICType.h in Headers */,
9BD8F40B176C2B470002D865 /* AtomicStringTable.h in Headers */,
A8A47434151A825B004123FF /* ASCIIFastPath.h in Headers */,
A8A47387151A825B004123FF /* Assertions.h in Headers */,
A8A47388151A825B004123FF /* Atomics.h in Headers */,
......@@ -1227,6 +1234,7 @@
A8A47458151A825B004123FF /* TypeTraits.cpp in Sources */,
A8A47469151A825B004123FF /* UTF8.cpp in Sources */,
A8A47445151A825B004123FF /* WTFString.cpp in Sources */,
9BC70F05176C379D00101DEC /* AtomicStringTable.cpp in Sources */,
A8A47486151A825B004123FF /* WTFThreadData.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
......
......@@ -126,6 +126,7 @@ set(WTF_HEADERS
text/AtomicString.h
text/AtomicStringImpl.h
text/AtomicStringTable.h
text/Base64.h
text/CString.h
text/IntegerToStringConversion.h
......@@ -192,6 +193,7 @@ set(WTF_SOURCES
dtoa/strtod.cc
text/AtomicString.cpp
text/AtomicStringTable.cpp
text/Base64.cpp
text/CString.cpp
text/StringBuilder.cpp
......
......@@ -27,6 +27,8 @@
#include "config.h"
#include "WTFThreadData.h"
#include <wtf/text/AtomicStringTable.h>
namespace WTF {
ThreadSpecific<WTFThreadData>* WTFThreadData::staticData;
......@@ -42,6 +44,7 @@ WTFThreadData::WTFThreadData()
, m_stackStats()
#endif
{
AtomicStringTable::create(*this);
}
WTFThreadData::~WTFThreadData()
......
......@@ -24,6 +24,7 @@
#include "AtomicString.h"
#include "AtomicStringTable.h"
#include "StringHash.h"
#include <wtf/HashSet.h>
#include <wtf/Threading.h>
......@@ -64,57 +65,9 @@ public:
};
#endif // USE(WEB_THREAD)
class AtomicStringTable {
WTF_MAKE_FAST_ALLOCATED;
public:
static AtomicStringTable* create(WTFThreadData& data)
{
#if USE(WEB_THREAD)
// On iOS, one AtomicStringTable is shared between the main UI thread and the WebThread.
static AtomicStringTable* sharedStringTable = new AtomicStringTable;
bool currentThreadIsWebThread = isWebThread();
if (currentThreadIsWebThread || isUIThread())
data.m_atomicStringTable = sharedStringTable;
else
data.m_atomicStringTable = new AtomicStringTable;
// We do the following so that its destruction happens only
// once - on the main UI thread.
if (!currentThreadIsWebThread)
data.m_atomicStringTableDestructor = AtomicStringTable::destroy;
#else
data.m_atomicStringTable = new AtomicStringTable;
data.m_atomicStringTableDestructor = AtomicStringTable::destroy;
#endif // USE(WEB_THREAD)
return data.m_atomicStringTable;
}
HashSet<StringImpl*>& table()
{
return m_table;
}
private:
static void destroy(AtomicStringTable* table)
{
HashSet<StringImpl*>::iterator end = table->m_table.end();
for (HashSet<StringImpl*>::iterator iter = table->m_table.begin(); iter != end; ++iter)
(*iter)->setIsAtomic(false);
delete table;
}
HashSet<StringImpl*> m_table;
};
static inline HashSet<StringImpl*>& stringTable()
static ALWAYS_INLINE HashSet<StringImpl*>& stringTable()
{
// Once possible we should make this non-lazy (constructed in WTFThreadData's constructor).
WTFThreadData& data = wtfThreadData();
AtomicStringTable* table = data.atomicStringTable();
if (UNLIKELY(!table))
table = AtomicStringTable::create(data);
return table->table();
return wtfThreadData().atomicStringTable()->table();
}
template<typename T, typename HashTranslator>
......
/*
* Copyright (C) 2004, 2005, 2006, 2007, 2008, 2013 Apple Inc. All rights reserved.
* Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
* Copyright (C) 2012 Google Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "config.h"
#include "AtomicStringTable.h"
#include <wtf/HashSet.h>
#include <wtf/WTFThreadData.h>
namespace WTF {
void AtomicStringTable::create(WTFThreadData& data)
{
#if USE(WEB_THREAD)
// On iOS, one AtomicStringTable is shared between the main UI thread and the WebThread.
static AtomicStringTable* sharedStringTable = new AtomicStringTable;
bool currentThreadIsWebThread = isWebThread();
if (currentThreadIsWebThread || isUIThread())
data.m_atomicStringTable = sharedStringTable;
else
data.m_atomicStringTable = new AtomicStringTable;
// We do the following so that its destruction happens only
// once - on the main UI thread.
if (!currentThreadIsWebThread)
data.m_atomicStringTableDestructor = destroyAtomicStringTable;
#else
data.m_atomicStringTable = new AtomicStringTable;
data.m_atomicStringTableDestructor = AtomicStringTable::destroy;
#endif // USE(WEB_THREAD)
}
void AtomicStringTable::destroy(AtomicStringTable* table)
{
HashSet<StringImpl*>::iterator end = table->m_table.end();
for (HashSet<StringImpl*>::iterator iter = table->m_table.begin(); iter != end; ++iter)
(*iter)->setIsAtomic(false);
delete table;
}
}
/*
* Copyright (C) 2004, 2005, 2006, 2007, 2008, 2013 Apple Inc. All rights reserved.
* Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
* Copyright (C) 2012 Google Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifndef WTF_AtomicStringTable_h
#define WTF_AtomicStringTable_h
#include <wtf/HashSet.h>
#include <wtf/WTFThreadData.h>
namespace WTF {
class StringImpl;
class AtomicStringTable {
WTF_MAKE_FAST_ALLOCATED;
public:
static void create(WTFThreadData&);
HashSet<StringImpl*>& table() { return m_table; }
private:
static void destroy(AtomicStringTable*);
HashSet<StringImpl*> m_table;
};
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment