Commit 5b30cfc2 authored by ap@webkit.org's avatar ap@webkit.org

Reviewed by Darin.

        Combine per-thread objects into one, to make it easier to support legacy clients (for
        which they shouldn't be really per-thread).

        No change on SunSpider total.

        * JavaScriptCore.xcodeproj/project.pbxproj: Added JSGlobalData.{h,cpp}

        * kjs/JSGlobalData.cpp: Added.
        (KJS::JSGlobalData::JSGlobalData):
        (KJS::JSGlobalData::~JSGlobalData):
        (KJS::JSGlobalData::threadInstance):
        * kjs/JSGlobalData.h: Added.
        This class encapsulates all data that should be per-thread (or shared between legacy clients).
        It will also keep a Heap pointer, but right now, Heap (Collector) methods are all static.

        * kjs/identifier.h:
        (KJS::Identifier::Identifier):
        Added a constructor explicitly taking JSGlobalData to access IdentifierTable. Actually,
        all of them should, but this will be a separate patch.

        * kjs/identifier.cpp:
        (KJS::IdentifierTable::literalTable):
        (KJS::createIdentifierTable):
        (KJS::deleteIdentifierTable):
        (KJS::Identifier::add):
        (KJS::Identifier::addSlowCase):
        Combined IdentifierTable and LiteralIdentifierTable into a single class for simplicity.

        * kjs/grammar.y: kjsyyparse now takes JSGlobalData, not just a Lexer.

        * kjs/nodes.cpp:
        (KJS::Node::Node):
        (KJS::EvalFunctionCallNode::emitCode):
        (KJS::ScopeNode::ScopeNode):
        Changed to access Lexer and Parser via JSGlobalData::threadInstance(). This is also a
        temporary measure, they will need to use JSGlobalData explicitly.

        * VM/CodeGenerator.cpp:
        (KJS::CodeGenerator::CodeGenerator):
        * VM/CodeGenerator.h:
        * VM/Machine.cpp:
        (KJS::callEval):
        * kjs/CommonIdentifiers.cpp:
        (KJS::CommonIdentifiers::CommonIdentifiers):
        * kjs/CommonIdentifiers.h:
        * kjs/DebuggerCallFrame.cpp:
        (KJS::DebuggerCallFrame::evaluate):
        * kjs/ExecState.cpp:
        (KJS::ExecState::ExecState):
        * kjs/ExecState.h:
        (KJS::ExecState::globalData):
        (KJS::ExecState::identifierTable):
        (KJS::ExecState::propertyNames):
        (KJS::ExecState::emptyList):
        (KJS::ExecState::lexer):
        (KJS::ExecState::parser):
        (KJS::ExecState::arrayTable):
        (KJS::ExecState::dateTable):
        (KJS::ExecState::mathTable):
        (KJS::ExecState::numberTable):
        (KJS::ExecState::RegExpImpTable):
        (KJS::ExecState::RegExpObjectImpTable):
        (KJS::ExecState::stringTable):
        * kjs/InitializeThreading.cpp:
        (KJS::initializeThreadingOnce):
        * kjs/JSGlobalObject.cpp:
        (KJS::JSGlobalObject::init):
        * kjs/JSGlobalObject.h:
        (KJS::JSGlobalObject::JSGlobalObjectData::JSGlobalObjectData):
        (KJS::JSGlobalObject::head):
        (KJS::JSGlobalObject::globalData):
        * kjs/Parser.cpp:
        (KJS::Parser::parse):
        * kjs/Parser.h:
        * kjs/function.cpp:
        (KJS::FunctionImp::getParameterName):
        (KJS::IndexToNameMap::unMap):
        (KJS::globalFuncEval):
        * kjs/function_object.cpp:
        (KJS::FunctionObjectImp::construct):
        * kjs/interpreter.cpp:
        (KJS::Interpreter::checkSyntax):
        (KJS::Interpreter::evaluate):
        * kjs/lexer.cpp:
        (kjsyylex):
        * kjs/lexer.h:
        * kjs/testkjs.cpp:
        (prettyPrintScript):
        Updated for the above changes. Most of threadInstance uses here will need to be replaced with
        explicitly passed pointers to support legacy JSC clients.

        * JavaScriptCore.exp: Removed KJS::parser().



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@34412 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent a1f1a97b
2008-06-06 Alexey Proskuryakov <ap@webkit.org>
Reviewed by Darin.
Combine per-thread objects into one, to make it easier to support legacy clients (for
which they shouldn't be really per-thread).
No change on SunSpider total.
* JavaScriptCore.xcodeproj/project.pbxproj: Added JSGlobalData.{h,cpp}
* kjs/JSGlobalData.cpp: Added.
(KJS::JSGlobalData::JSGlobalData):
(KJS::JSGlobalData::~JSGlobalData):
(KJS::JSGlobalData::threadInstance):
* kjs/JSGlobalData.h: Added.
This class encapsulates all data that should be per-thread (or shared between legacy clients).
It will also keep a Heap pointer, but right now, Heap (Collector) methods are all static.
* kjs/identifier.h:
(KJS::Identifier::Identifier):
Added a constructor explicitly taking JSGlobalData to access IdentifierTable. Actually,
all of them should, but this will be a separate patch.
* kjs/identifier.cpp:
(KJS::IdentifierTable::literalTable):
(KJS::createIdentifierTable):
(KJS::deleteIdentifierTable):
(KJS::Identifier::add):
(KJS::Identifier::addSlowCase):
Combined IdentifierTable and LiteralIdentifierTable into a single class for simplicity.
* kjs/grammar.y: kjsyyparse now takes JSGlobalData, not just a Lexer.
* kjs/nodes.cpp:
(KJS::Node::Node):
(KJS::EvalFunctionCallNode::emitCode):
(KJS::ScopeNode::ScopeNode):
Changed to access Lexer and Parser via JSGlobalData::threadInstance(). This is also a
temporary measure, they will need to use JSGlobalData explicitly.
* VM/CodeGenerator.cpp:
(KJS::CodeGenerator::CodeGenerator):
* VM/CodeGenerator.h:
* VM/Machine.cpp:
(KJS::callEval):
* kjs/CommonIdentifiers.cpp:
(KJS::CommonIdentifiers::CommonIdentifiers):
* kjs/CommonIdentifiers.h:
* kjs/DebuggerCallFrame.cpp:
(KJS::DebuggerCallFrame::evaluate):
* kjs/ExecState.cpp:
(KJS::ExecState::ExecState):
* kjs/ExecState.h:
(KJS::ExecState::globalData):
(KJS::ExecState::identifierTable):
(KJS::ExecState::propertyNames):
(KJS::ExecState::emptyList):
(KJS::ExecState::lexer):
(KJS::ExecState::parser):
(KJS::ExecState::arrayTable):
(KJS::ExecState::dateTable):
(KJS::ExecState::mathTable):
(KJS::ExecState::numberTable):
(KJS::ExecState::RegExpImpTable):
(KJS::ExecState::RegExpObjectImpTable):
(KJS::ExecState::stringTable):
* kjs/InitializeThreading.cpp:
(KJS::initializeThreadingOnce):
* kjs/JSGlobalObject.cpp:
(KJS::JSGlobalObject::init):
* kjs/JSGlobalObject.h:
(KJS::JSGlobalObject::JSGlobalObjectData::JSGlobalObjectData):
(KJS::JSGlobalObject::head):
(KJS::JSGlobalObject::globalData):
* kjs/Parser.cpp:
(KJS::Parser::parse):
* kjs/Parser.h:
* kjs/function.cpp:
(KJS::FunctionImp::getParameterName):
(KJS::IndexToNameMap::unMap):
(KJS::globalFuncEval):
* kjs/function_object.cpp:
(KJS::FunctionObjectImp::construct):
* kjs/interpreter.cpp:
(KJS::Interpreter::checkSyntax):
(KJS::Interpreter::evaluate):
* kjs/lexer.cpp:
(kjsyylex):
* kjs/lexer.h:
* kjs/testkjs.cpp:
(prettyPrintScript):
Updated for the above changes. Most of threadInstance uses here will need to be replaced with
explicitly passed pointers to support legacy JSC clients.
* JavaScriptCore.exp: Removed KJS::parser().
2008-06-06 Cameron Zwarich <cwzwarich@uwaterloo.ca>
Reviewed by Oliver.
......
......@@ -82,7 +82,6 @@ __ZN3KJS6JSLock4lockEv
__ZN3KJS6JSLock6unlockEv
__ZN3KJS6JSLock9lockCountEv
__ZN3KJS6Parser5parseEPNS_9ExecStateERKNS_7UStringEiN3WTF10PassRefPtrINS_14SourceProviderEEEPiSA_PS3_
__ZN3KJS6parserEv
__ZN3KJS6strtodEPKcPPc
__ZN3KJS7CStringaSERKS0_
__ZN3KJS7CStringD1Ev
......
......@@ -233,6 +233,8 @@
E11D51760B2E798D0056C188 /* StringExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = E11D51750B2E798D0056C188 /* StringExtras.h */; settings = {ATTRIBUTES = (Private, ); }; };
E17863400D9BEC0000D74E75 /* InitializeThreading.h in Headers */ = {isa = PBXBuildFile; fileRef = E178633F0D9BEC0000D74E75 /* InitializeThreading.h */; settings = {ATTRIBUTES = (Private, ); }; };
E178636D0D9BEEC300D74E75 /* InitializeThreading.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E178636C0D9BEEC300D74E75 /* InitializeThreading.cpp */; };
E18E3A580DF9278C00D90B34 /* JSGlobalData.h in Headers */ = {isa = PBXBuildFile; fileRef = E18E3A560DF9278C00D90B34 /* JSGlobalData.h */; settings = {ATTRIBUTES = (Private, ); }; };
E18E3A590DF9278C00D90B34 /* JSGlobalData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E18E3A570DF9278C00D90B34 /* JSGlobalData.cpp */; };
E195679609E7CF1200B89D13 /* UnicodeIcu.h in Headers */ = {isa = PBXBuildFile; fileRef = E195678F09E7CF1200B89D13 /* UnicodeIcu.h */; settings = {ATTRIBUTES = (Private, ); }; };
E195679809E7CF1200B89D13 /* Unicode.h in Headers */ = {isa = PBXBuildFile; fileRef = E195679409E7CF1200B89D13 /* Unicode.h */; settings = {ATTRIBUTES = (Private, ); }; };
E1A596380DE3E1C300C17E37 /* AVLTree.h in Headers */ = {isa = PBXBuildFile; fileRef = E1A596370DE3E1C300C17E37 /* AVLTree.h */; };
......@@ -579,6 +581,8 @@
E11D51750B2E798D0056C188 /* StringExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringExtras.h; sourceTree = "<group>"; };
E178633F0D9BEC0000D74E75 /* InitializeThreading.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InitializeThreading.h; sourceTree = "<group>"; };
E178636C0D9BEEC300D74E75 /* InitializeThreading.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InitializeThreading.cpp; sourceTree = "<group>"; };
E18E3A560DF9278C00D90B34 /* JSGlobalData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSGlobalData.h; sourceTree = "<group>"; };
E18E3A570DF9278C00D90B34 /* JSGlobalData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSGlobalData.cpp; sourceTree = "<group>"; };
E195678F09E7CF1200B89D13 /* UnicodeIcu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnicodeIcu.h; sourceTree = "<group>"; };
E195679409E7CF1200B89D13 /* Unicode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Unicode.h; sourceTree = "<group>"; };
E1A596370DE3E1C300C17E37 /* AVLTree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AVLTree.h; sourceTree = "<group>"; };
......@@ -1010,6 +1014,8 @@
F692A8640255597D01FF60F7 /* interpreter.h */,
14DA818F0D99FD2000B0A4FB /* JSActivation.cpp */,
14DA818E0D99FD2000B0A4FB /* JSActivation.h */,
E18E3A560DF9278C00D90B34 /* JSGlobalData.h */,
E18E3A570DF9278C00D90B34 /* JSGlobalData.cpp */,
14DE0D680D02431400AACCA2 /* JSGlobalObject.cpp */,
A8E894330CD0603F00367179 /* JSGlobalObject.h */,
14760863099C633800437128 /* JSImmediate.cpp */,
......@@ -1297,6 +1303,7 @@
A72701B50DADE94900E548D7 /* ExceptionHelpers.h in Headers */,
A7C31DA90DBEBA4300FDF8EB /* SegmentedVector.h in Headers */,
1480DB9D0DDC227F003CFDF2 /* DebuggerCallFrame.h in Headers */,
E18E3A580DF9278C00D90B34 /* JSGlobalData.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -1569,6 +1576,7 @@
14D797810DAC3307001A9F05 /* RegisterFileStack.cpp in Sources */,
A72701B60DADE94900E548D7 /* ExceptionHelpers.cpp in Sources */,
149559EE0DDCDDF700648087 /* DebuggerCallFrame.cpp in Sources */,
E18E3A590DF9278C00D90B34 /* JSGlobalData.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
......@@ -179,7 +179,7 @@ CodeGenerator::CodeGenerator(ProgramNode* programNode, const Debugger* debugger,
, m_codeType(GlobalCode)
, m_continueDepth(0)
, m_nextVar(-1)
, m_propertyNames(CommonIdentifiers::shared())
, m_propertyNames(&scopeChain.globalObject()->globalExec()->propertyNames())
{
// Global code can inherit previously defined symbols.
int size = symbolTable->size() + 1; // + 1 slot for "this"
......@@ -237,7 +237,7 @@ CodeGenerator::CodeGenerator(FunctionBodyNode* functionBody, const Debugger* deb
, m_codeType(FunctionCode)
, m_continueDepth(0)
, m_nextVar(-1)
, m_propertyNames(CommonIdentifiers::shared())
, m_propertyNames(&scopeChain.globalObject()->globalExec()->propertyNames())
{
const Node::FunctionStack& functionStack = functionBody->functionStack();
for (size_t i = 0; i < functionStack.size(); ++i) {
......@@ -284,7 +284,7 @@ CodeGenerator::CodeGenerator(EvalNode* evalNode, const Debugger* debugger, const
, m_codeType(EvalCode)
, m_continueDepth(0)
, m_nextVar(-1)
, m_propertyNames(CommonIdentifiers::shared())
, m_propertyNames(&scopeChain.globalObject()->globalExec()->propertyNames())
{
m_codeBlock->numVars = 1; // Allocate space for "this"
}
......
......@@ -371,7 +371,7 @@ namespace KJS {
IdentifierMap m_identifierMap;
JSValueMap m_jsValueMap;
CommonIdentifiers* m_propertyNames;
const CommonIdentifiers* m_propertyNames;
#ifndef NDEBUG
static bool s_dumpsGeneratedCode;
......
......@@ -446,7 +446,7 @@ static NEVER_INLINE JSValue* callEval(ExecState* exec, JSObject* thisObj, ScopeC
int sourceId;
int errLine;
UString errMsg;
RefPtr<EvalNode> evalNode = parser().parse<EvalNode>(exec, UString(), 1, UStringSourceProvider::create(static_cast<StringImp*>(program)->value()), &sourceId, &errLine, &errMsg);
RefPtr<EvalNode> evalNode = exec->parser()->parse<EvalNode>(exec, UString(), 1, UStringSourceProvider::create(static_cast<StringImp*>(program)->value()), &sourceId, &errLine, &errMsg);
if (!evalNode) {
exceptionValue = Error::create(exec, SyntaxError, errMsg, errLine, sourceId, NULL);
......
......@@ -21,34 +21,18 @@
#include "config.h"
#include "CommonIdentifiers.h"
#if USE(MULTIPLE_THREADS)
#include <wtf/ThreadSpecific.h>
using namespace WTF;
#endif
namespace KJS {
const char* const nullCString = 0;
#define INITIALIZE_PROPERTY_NAME(name) , name ( #name )
#define INITIALIZE_PROPERTY_NAME(name) , name(globalData, #name)
CommonIdentifiers::CommonIdentifiers()
: nullIdentifier(nullCString)
, underscoreProto("__proto__")
, thisIdentifier("this")
CommonIdentifiers::CommonIdentifiers(JSGlobalData* globalData)
: nullIdentifier(globalData, nullCString)
, underscoreProto(globalData, "__proto__")
, thisIdentifier(globalData, "this")
KJS_COMMON_IDENTIFIERS_EACH_PROPERTY_NAME(INITIALIZE_PROPERTY_NAME)
{
}
CommonIdentifiers* CommonIdentifiers::shared()
{
#if USE(MULTIPLE_THREADS)
static ThreadSpecific<CommonIdentifiers> sharedInstance;
return sharedInstance;
#else
static CommonIdentifiers sharedInstance;
return &sharedInstance;
#endif
}
} // namespace KJS
......@@ -24,10 +24,6 @@
#include "identifier.h"
#include <wtf/Noncopyable.h>
namespace WTF {
template<typename T> class ThreadSpecific;
}
// List of property names, passed to a macro so we can do set them up various
// ways without repeating the list.
#define KJS_COMMON_IDENTIFIERS_EACH_PROPERTY_NAME(macro) \
......@@ -74,12 +70,10 @@ namespace KJS {
class CommonIdentifiers : Noncopyable {
private:
CommonIdentifiers();
friend class WTF::ThreadSpecific<CommonIdentifiers>;
CommonIdentifiers(JSGlobalData*);
friend struct JSGlobalData;
public:
static CommonIdentifiers* shared();
const Identifier nullIdentifier;
const Identifier underscoreProto;
const Identifier thisIdentifier;
......
......@@ -73,7 +73,7 @@ JSValue* DebuggerCallFrame::evaluate(const UString& script, JSValue*& exception)
int errLine;
UString errMsg;
RefPtr<EvalNode> evalNode = parser().parse<EvalNode>(&newExec, UString(), 1, UStringSourceProvider::create(script), &sourceId, &errLine, &errMsg);
RefPtr<EvalNode> evalNode = newExec.parser()->parse<EvalNode>(&newExec, UString(), 1, UStringSourceProvider::create(script), &sourceId, &errLine, &errMsg);
if (!evalNode)
return Error::create(&newExec, SyntaxError, errMsg, errLine, sourceId, 0);
......
......@@ -35,7 +35,7 @@ ExecState::ExecState(JSGlobalObject* globalObject, JSObject* globalThisValue, Sc
: m_globalObject(globalObject)
, m_globalThisValue(globalThisValue)
, m_exception(0)
, m_perThreadData(globalObject->perThreadData())
, m_globalData(globalObject->globalData())
, m_prev(0)
, m_machine(0)
, m_registerFile(0)
......@@ -48,7 +48,7 @@ ExecState::ExecState(ExecState* exec, Machine* machine, RegisterFile* registerFi
: m_globalObject(exec->m_globalObject)
, m_globalThisValue(exec->m_globalThisValue)
, m_exception(0)
, m_perThreadData(exec->m_globalObject->perThreadData())
, m_globalData(exec->m_globalData)
, m_prev(exec)
, m_machine(machine)
, m_registerFile(registerFile)
......
......@@ -24,6 +24,7 @@
#ifndef ExecState_h
#define ExecState_h
#include "JSGlobalData.h"
#include "LabelStack.h"
#include "LocalStorageEntry.h"
#include "completion.h"
......@@ -32,12 +33,10 @@
namespace KJS {
class CommonIdentifiers;
class EvalNode;
class FunctionBodyNode;
class FunctionImp;
class GlobalFuncImp;
struct HashTable;
class Interpreter;
class JSGlobalObject;
class JSVariableObject;
......@@ -48,19 +47,6 @@ namespace KJS {
struct Instruction;
struct PerThreadData {
const HashTable* arrayTable;
const HashTable* dateTable;
const HashTable* mathTable;
const HashTable* numberTable;
const HashTable* RegExpImpTable;
const HashTable* RegExpObjectImpTable;
const HashTable* stringTable;
CommonIdentifiers* propertyNames;
List emptyList;
};
// Represents the current state of script execution.
// Passed as the first argument to most functions.
class ExecState : Noncopyable {
......@@ -91,17 +77,20 @@ namespace KJS {
JSValue** exceptionSlot() { return &m_exception; }
bool hadException() const { return !!m_exception; }
// These pointers are used to avoid accessing global variables for these,
// to avoid taking PIC branches in Mach-O binaries.
const CommonIdentifiers& propertyNames() const { return *m_perThreadData->propertyNames; }
const List& emptyList() const { return m_perThreadData->emptyList; }
static const HashTable* arrayTable(ExecState* exec) { return exec->m_perThreadData->arrayTable; }
static const HashTable* dateTable(ExecState* exec) { return exec->m_perThreadData->dateTable; }
static const HashTable* mathTable(ExecState* exec) { return exec->m_perThreadData->mathTable; }
static const HashTable* numberTable(ExecState* exec) { return exec->m_perThreadData->numberTable; }
static const HashTable* RegExpImpTable(ExecState* exec) { return exec->m_perThreadData->RegExpImpTable; }
static const HashTable* RegExpObjectImpTable(ExecState* exec) { return exec->m_perThreadData->RegExpObjectImpTable; }
static const HashTable* stringTable(ExecState* exec) { return exec->m_perThreadData->stringTable; }
JSGlobalData& globalData() { return *m_globalData; }
IdentifierTable* identifierTable() { return m_globalData->identifierTable; }
const CommonIdentifiers& propertyNames() const { return *m_globalData->propertyNames; }
const List& emptyList() const { return m_globalData->emptyList; }
Lexer* lexer() { return m_globalData->lexer; }
Parser* parser() { return m_globalData->parser; }
static const HashTable* arrayTable(ExecState* exec) { return exec->m_globalData->arrayTable; }
static const HashTable* dateTable(ExecState* exec) { return exec->m_globalData->dateTable; }
static const HashTable* mathTable(ExecState* exec) { return exec->m_globalData->mathTable; }
static const HashTable* numberTable(ExecState* exec) { return exec->m_globalData->numberTable; }
static const HashTable* RegExpImpTable(ExecState* exec) { return exec->m_globalData->RegExpImpTable; }
static const HashTable* RegExpObjectImpTable(ExecState* exec) { return exec->m_globalData->RegExpObjectImpTable; }
static const HashTable* stringTable(ExecState* exec) { return exec->m_globalData->stringTable; }
private:
// Default constructor required for gcc 3.
......@@ -116,7 +105,7 @@ namespace KJS {
JSValue* m_exception;
const PerThreadData* m_perThreadData;
JSGlobalData* m_globalData;
// These values are controlled by the machine.
ExecState* m_prev;
......
......@@ -34,8 +34,6 @@
#include "dtoa.h"
#include "identifier.h"
#include "JSGlobalObject.h"
#include "lexer.h"
#include "Parser.h"
#include "ustring.h"
#include <wtf/Threading.h>
......@@ -53,13 +51,9 @@ static void initializeThreadingOnce()
#if !PLATFORM(DARWIN) // Darwin has pthread_main_np(), and doesn't need registerAsMainThread() called.
Collector::registerAsMainThread();
#endif
JSGlobalData::threadInstance();
UString::null();
Identifier::initializeIdentifierThreading();
CommonIdentifiers::shared();
lexer();
initDateMath();
JSGlobalObject::threadClassInfoHashTables();
JSGlobalObject::head();
#endif
}
......
/*
* Copyright (C) 2008 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.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE 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 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 "JSGlobalData.h"
#include "collector.h"
#include "CommonIdentifiers.h"
#include "lexer.h"
#include "list.h"
#include "lookup.h"
#include "nodes.h"
#include "parser.h"
#if USE(MULTIPLE_THREADS)
#include <wtf/ThreadSpecific.h>
#endif
using namespace WTF;
namespace KJS {
extern const HashTable arrayTable;
extern const HashTable dateTable;
extern const HashTable mathTable;
extern const HashTable numberTable;
extern const HashTable RegExpImpTable;
extern const HashTable RegExpObjectImpTable;
extern const HashTable stringTable;
JSGlobalData::JSGlobalData()
// : heap(new Heap)
#if USE(MULTIPLE_THREADS)
: arrayTable(new HashTable(KJS::arrayTable))
, dateTable(new HashTable(KJS::dateTable))
, mathTable(new HashTable(KJS::mathTable))
, numberTable(new HashTable(KJS::numberTable))
, RegExpImpTable(new HashTable(KJS::RegExpImpTable))
, RegExpObjectImpTable(new HashTable(KJS::RegExpObjectImpTable))
, stringTable(new HashTable(KJS::stringTable))
#else
: arrayTable(&KJS::arrayTable)
, dateTable(&KJS::dateTable)
, mathTable(&KJS::mathTable)
, numberTable(&KJS::numberTable)
, RegExpImpTable(&KJS::RegExpImpTable)
, RegExpObjectImpTable(&KJS::RegExpObjectImpTable)
, stringTable(&KJS::stringTable)
#endif
, identifierTable(createIdentifierTable())
, propertyNames(new CommonIdentifiers(this))
, lexer(new Lexer)
, parser(new Parser)
, head(0)
{
}
JSGlobalData::~JSGlobalData()
{
#if USE(MULTIPLE_THREADS)
delete[] arrayTable->table;
delete[] dateTable->table;
delete[] mathTable->table;
delete[] numberTable->table;
delete[] RegExpImpTable->table;
delete[] RegExpObjectImpTable->table;
delete[] stringTable->table;
delete arrayTable;
delete dateTable;
delete mathTable;
delete numberTable;
delete RegExpImpTable;
delete RegExpObjectImpTable;
delete stringTable;
delete parser;
delete lexer;
delete propertyNames;
deleteIdentifierTable(identifierTable);
#endif
}
JSGlobalData& JSGlobalData::threadInstance()
{
#if USE(MULTIPLE_THREADS)
static ThreadSpecific<JSGlobalData> sharedInstance;
return *sharedInstance;
#else
return globalSharedInstance();
#endif
}
}
/*
* Copyright (C) 2008 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.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE 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 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 JSGlobalData_h
#define JSGlobalData_h
#include "list.h"
#include <wtf/HashCountedSet.h>
#include <wtf/HashSet.h>
#include <wtf/Noncopyable.h>
namespace WTF {
template<typename> class ThreadSpecific;
}
namespace KJS {
class CommonIdentifiers;
// class Heap;
class IdentifierTable;
class JSGlobalObject;
class Lexer;
class Parser;
class ParserRefCounted;
class UString;
struct HashTable;
struct UString::Rep;
// This serves as a bottleneck for accessing per-thread data structures.
// Note that the effective instance may be different from the thread one in case of legacy
// JavaScriptCore clients, which all share a single JSGlobalData, and thus cannot run concurrently.
struct JSGlobalData : Noncopyable {
static JSGlobalData& threadInstance();
// Heap* heap;
const HashTable* arrayTable;
const HashTable* dateTable;
const HashTable* mathTable;
const HashTable* numberTable;
const HashTable* RegExpImpTable;
const HashTable* RegExpObjectImpTable;
const HashTable* stringTable;
IdentifierTable* identifierTable;
CommonIdentifiers* propertyNames;
const List emptyList; // Lists are supposed to be allocated on the stack to have their elements properly marked, which is not the case here - but this list has nothing to mark.
HashSet<ParserRefCounted*> newTrackedObjects;
HashCountedSet<ParserRefCounted*> trackedObjectExtraRefCounts;
Lexer* lexer;
Parser* parser;
JSGlobalObject* head;
private:
friend class WTF::ThreadSpecific<JSGlobalData>;
JSGlobalData();
~JSGlobalData();
};
}
#endif
......@@ -44,11 +44,6 @@
#include "scope_chain_mark.h"
#include "string_object.h"
#if USE(MULTIPLE_THREADS)
#include <wtf/ThreadSpecific.h>
using namespace WTF;
#endif
#if HAVE(SYS_TIME_H)
#include <sys/time.h>
#endif