Changeset 34412 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Jun 6, 2008, 11:03:24 PM (17 years ago)
Author:
[email protected]
Message:

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.

  • 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.
Location:
trunk/JavaScriptCore/kjs
Files:
2 added
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/CommonIdentifiers.cpp

    r33979 r34412  
    2222#include "CommonIdentifiers.h"
    2323
    24 #if USE(MULTIPLE_THREADS)
    25 #include <wtf/ThreadSpecific.h>
    26 using namespace WTF;
    27 #endif
    28 
    2924namespace KJS {
    3025
    3126const char* const nullCString = 0;
    3227
    33 #define INITIALIZE_PROPERTY_NAME(name) , name ( #name )
     28#define INITIALIZE_PROPERTY_NAME(name) , name(globalData, #name)
    3429
    35 CommonIdentifiers::CommonIdentifiers()
    36     : nullIdentifier(nullCString)
    37     , underscoreProto("__proto__")
    38     , thisIdentifier("this")
     30CommonIdentifiers::CommonIdentifiers(JSGlobalData* globalData)
     31    : nullIdentifier(globalData, nullCString)
     32    , underscoreProto(globalData, "__proto__")
     33    , thisIdentifier(globalData, "this")
    3934    KJS_COMMON_IDENTIFIERS_EACH_PROPERTY_NAME(INITIALIZE_PROPERTY_NAME)
    4035{
    4136}
    4237
    43 CommonIdentifiers* CommonIdentifiers::shared()
    44 {
    45 #if USE(MULTIPLE_THREADS)
    46     static ThreadSpecific<CommonIdentifiers> sharedInstance;
    47     return sharedInstance;
    48 #else
    49     static CommonIdentifiers sharedInstance;
    50     return &sharedInstance;
    51 #endif
    52 }
    53 
    5438} // namespace KJS
  • trunk/JavaScriptCore/kjs/CommonIdentifiers.h

    r33979 r34412  
    2424#include "identifier.h"
    2525#include <wtf/Noncopyable.h>
    26 
    27 namespace WTF {
    28     template<typename T> class ThreadSpecific;
    29 }
    3026
    3127// List of property names, passed to a macro so we can do set them up various
     
    7571
    7672    private:
    77         CommonIdentifiers();
    78         friend class WTF::ThreadSpecific<CommonIdentifiers>;
     73        CommonIdentifiers(JSGlobalData*);
     74        friend struct JSGlobalData;
    7975
    8076    public:
    81         static CommonIdentifiers* shared();
    82 
    8377        const Identifier nullIdentifier;
    8478        const Identifier underscoreProto;
  • trunk/JavaScriptCore/kjs/DebuggerCallFrame.cpp

    r34273 r34412  
    7474    UString errMsg;
    7575
    76     RefPtr<EvalNode> evalNode = parser().parse<EvalNode>(&newExec, UString(), 1, UStringSourceProvider::create(script), &sourceId, &errLine, &errMsg);
     76    RefPtr<EvalNode> evalNode = newExec.parser()->parse<EvalNode>(&newExec, UString(), 1, UStringSourceProvider::create(script), &sourceId, &errLine, &errMsg);
    7777
    7878    if (!evalNode)
  • trunk/JavaScriptCore/kjs/ExecState.cpp

    r33979 r34412  
    3636    , m_globalThisValue(globalThisValue)
    3737    , m_exception(0)
    38     , m_perThreadData(globalObject->perThreadData())
     38    , m_globalData(globalObject->globalData())
    3939    , m_prev(0)
    4040    , m_machine(0)
     
    4949    , m_globalThisValue(exec->m_globalThisValue)
    5050    , m_exception(0)
    51     , m_perThreadData(exec->m_globalObject->perThreadData())
     51    , m_globalData(exec->m_globalData)
    5252    , m_prev(exec)
    5353    , m_machine(machine)
  • trunk/JavaScriptCore/kjs/ExecState.h

    r34355 r34412  
    2525#define ExecState_h
    2626
     27#include "JSGlobalData.h"
    2728#include "LabelStack.h"
    2829#include "LocalStorageEntry.h"
     
    3334namespace KJS  {
    3435
    35     class CommonIdentifiers;
    3636    class EvalNode;
    3737    class FunctionBodyNode;
    3838    class FunctionImp;
    3939    class GlobalFuncImp;
    40     struct HashTable;
    4140    class Interpreter;
    4241    class JSGlobalObject;
     
    4948    struct Instruction;
    5049   
    51     struct PerThreadData {
    52         const HashTable* arrayTable;
    53         const HashTable* dateTable;
    54         const HashTable* mathTable;
    55         const HashTable* numberTable;
    56         const HashTable* RegExpImpTable;
    57         const HashTable* RegExpObjectImpTable;
    58         const HashTable* stringTable;
    59 
    60         CommonIdentifiers* propertyNames;
    61         List emptyList;
    62     };
    63 
    6450    // Represents the current state of script execution.
    6551    // Passed as the first argument to most functions.
     
    9278        bool hadException() const { return !!m_exception; }
    9379
    94         // These pointers are used to avoid accessing global variables for these,
    95         // to avoid taking PIC branches in Mach-O binaries.
    96         const CommonIdentifiers& propertyNames() const { return *m_perThreadData->propertyNames; }
    97         const List& emptyList() const { return m_perThreadData->emptyList; }
    98         static const HashTable* arrayTable(ExecState* exec) { return exec->m_perThreadData->arrayTable; }
    99         static const HashTable* dateTable(ExecState* exec) { return exec->m_perThreadData->dateTable; }
    100         static const HashTable* mathTable(ExecState* exec) { return exec->m_perThreadData->mathTable; }
    101         static const HashTable* numberTable(ExecState* exec) { return exec->m_perThreadData->numberTable; }
    102         static const HashTable* RegExpImpTable(ExecState* exec) { return exec->m_perThreadData->RegExpImpTable; }
    103         static const HashTable* RegExpObjectImpTable(ExecState* exec) { return exec->m_perThreadData->RegExpObjectImpTable; }
    104         static const HashTable* stringTable(ExecState* exec) { return exec->m_perThreadData->stringTable; }
     80        JSGlobalData& globalData() { return *m_globalData; }
     81
     82        IdentifierTable* identifierTable() { return m_globalData->identifierTable; }
     83        const CommonIdentifiers& propertyNames() const { return *m_globalData->propertyNames; }
     84        const List& emptyList() const { return m_globalData->emptyList; }
     85        Lexer* lexer() { return m_globalData->lexer; }
     86        Parser* parser() { return m_globalData->parser; }
     87        static const HashTable* arrayTable(ExecState* exec) { return exec->m_globalData->arrayTable; }
     88        static const HashTable* dateTable(ExecState* exec) { return exec->m_globalData->dateTable; }
     89        static const HashTable* mathTable(ExecState* exec) { return exec->m_globalData->mathTable; }
     90        static const HashTable* numberTable(ExecState* exec) { return exec->m_globalData->numberTable; }
     91        static const HashTable* RegExpImpTable(ExecState* exec) { return exec->m_globalData->RegExpImpTable; }
     92        static const HashTable* RegExpObjectImpTable(ExecState* exec) { return exec->m_globalData->RegExpObjectImpTable; }
     93        static const HashTable* stringTable(ExecState* exec) { return exec->m_globalData->stringTable; }
    10594
    10695    private:
     
    117106        JSValue* m_exception;
    118107
    119         const PerThreadData* m_perThreadData;
     108        JSGlobalData* m_globalData;
    120109
    121110        // These values are controlled by the machine.
  • trunk/JavaScriptCore/kjs/InitializeThreading.cpp

    r33038 r34412  
    3535#include "identifier.h"
    3636#include "JSGlobalObject.h"
    37 #include "lexer.h"
    38 #include "Parser.h"
    3937#include "ustring.h"
    4038#include <wtf/Threading.h>
     
    5452    Collector::registerAsMainThread();
    5553#endif
     54    JSGlobalData::threadInstance();
    5655    UString::null();
    57     Identifier::initializeIdentifierThreading();
    58     CommonIdentifiers::shared();
    59     lexer();
    6056    initDateMath();
    61     JSGlobalObject::threadClassInfoHashTables();
    62     JSGlobalObject::head();
    6357#endif
    6458}
  • trunk/JavaScriptCore/kjs/JSGlobalObject.cpp

    r33980 r34412  
    4545#include "string_object.h"
    4646
    47 #if USE(MULTIPLE_THREADS)
    48 #include <wtf/ThreadSpecific.h>
    49 using namespace WTF;
    50 #endif
    51 
    5247#if HAVE(SYS_TIME_H)
    5348#include <sys/time.h>
     
    6358
    6459namespace KJS {
    65 
    66 extern const HashTable arrayTable;
    67 extern const HashTable dateTable;
    68 extern const HashTable mathTable;
    69 extern const HashTable numberTable;
    70 extern const HashTable RegExpImpTable;
    71 extern const HashTable RegExpObjectImpTable;
    72 extern const HashTable stringTable;
    7360
    7461// Default number of ticks before a timeout check should be done.
     
    125112}
    126113
    127 struct ThreadClassInfoHashTables {
    128     ThreadClassInfoHashTables()
    129         : arrayTable(KJS::arrayTable)
    130         , dateTable(KJS::dateTable)
    131         , mathTable(KJS::mathTable)
    132         , numberTable(KJS::numberTable)
    133         , RegExpImpTable(KJS::RegExpImpTable)
    134         , RegExpObjectImpTable(KJS::RegExpObjectImpTable)
    135         , stringTable(KJS::stringTable)
    136     {
    137     }
    138 
    139     ~ThreadClassInfoHashTables()
    140     {
    141 #if USE(MULTIPLE_THREADS)
    142         delete[] arrayTable.table;
    143         delete[] dateTable.table;
    144         delete[] mathTable.table;
    145         delete[] numberTable.table;
    146         delete[] RegExpImpTable.table;
    147         delete[] RegExpObjectImpTable.table;
    148         delete[] stringTable.table;
    149 #endif
    150     }
    151 
    152 #if USE(MULTIPLE_THREADS)
    153     HashTable arrayTable;
    154     HashTable dateTable;
    155     HashTable mathTable;
    156     HashTable numberTable;
    157     HashTable RegExpImpTable;
    158     HashTable RegExpObjectImpTable;
    159     HashTable stringTable;
    160 #else
    161     const HashTable& arrayTable;
    162     const HashTable& dateTable;
    163     const HashTable& mathTable;
    164     const HashTable& numberTable;
    165     const HashTable& RegExpImpTable;
    166     const HashTable& RegExpObjectImpTable;
    167     const HashTable& stringTable;
    168 #endif
    169 };
    170 
    171 ThreadClassInfoHashTables* JSGlobalObject::threadClassInfoHashTables()
    172 {
    173 #if USE(MULTIPLE_THREADS)
    174     static ThreadSpecific<ThreadClassInfoHashTables> sharedInstance;
    175     return sharedInstance;
    176 #else
    177     static ThreadClassInfoHashTables sharedInstance;
    178     return &sharedInstance;
    179 #endif
    180 }
    181 
    182114void JSGlobalObject::init(JSObject* thisValue)
    183115{
     
    199131    d()->debugger = 0;
    200132   
    201     d()->perThreadData.arrayTable = &threadClassInfoHashTables()->arrayTable;
    202     d()->perThreadData.dateTable = &threadClassInfoHashTables()->dateTable;
    203     d()->perThreadData.mathTable = &threadClassInfoHashTables()->mathTable;
    204     d()->perThreadData.numberTable = &threadClassInfoHashTables()->numberTable;
    205     d()->perThreadData.RegExpImpTable = &threadClassInfoHashTables()->RegExpImpTable;
    206     d()->perThreadData.RegExpObjectImpTable = &threadClassInfoHashTables()->RegExpObjectImpTable;
    207     d()->perThreadData.stringTable = &threadClassInfoHashTables()->stringTable;
    208     d()->perThreadData.propertyNames = CommonIdentifiers::shared();
     133    d()->globalData = &JSGlobalData::threadInstance();
    209134
    210135    d()->globalExec.set(new ExecState(this, thisValue, d()->globalScopeChain.node()));
  • trunk/JavaScriptCore/kjs/JSGlobalObject.h

    r34143 r34412  
    2424#define KJS_GlobalObject_h
    2525
     26#include "JSGlobalData.h"
    2627#include "JSVariableObject.h"
    2728#include "RegisterFile.h"
     
    7273    class UriErrorPrototype;
    7374    struct ActivationStackNode;
    74     struct ThreadClassInfoHashTables;
    7575
    7676    typedef Vector<ExecState*, 16> ExecStateStack;
     
    8484                : JSVariableObjectData(&symbolTable, registerFileStack.globalBasePointer(), 0)
    8585                , globalScopeChain(globalObject, thisValue)
    86                 , globalExec(new ExecState(globalObject, thisValue, globalScopeChain.node()))
    8786            {
    8887            }
     
    143142            unsigned pageGroupIdentifier;
    144143
    145             PerThreadData perThreadData;
     144            JSGlobalData* globalData;
    146145
    147146            HashSet<ProgramCodeBlock*> codeBlocks;
     
    176175        virtual void defineSetter(ExecState*, const Identifier& propertyName, JSObject* setterFunc);
    177176
    178         // Linked list of all global objects.
    179         static JSGlobalObject* head() { return s_head; }
     177        // Per-thread linked list of all global objects.
     178        static JSGlobalObject*& head() { return JSGlobalData::threadInstance().head; }
    180179        JSGlobalObject* next() { return d()->next; }
    181180
     
    260259
    261260        // Per-thread hash tables, cached on the global object for faster access.
    262         const PerThreadData* perThreadData() const { return &d()->perThreadData; }
    263 
    264         // Initialize and/or retrieve per-thread hash tables - use perThreadData() for faster access instead.
    265         static ThreadClassInfoHashTables* threadClassInfoHashTables();
     261        JSGlobalData* globalData() { return d()->globalData; }
    266262
    267263        void init(JSObject* thisValue);
  • trunk/JavaScriptCore/kjs/Parser.cpp

    r34273 r34412  
    2929#include "lexer.h"
    3030#include <wtf/HashSet.h>
    31 #if USE(MULTIPLE_THREADS)
    32 #include <wtf/ThreadSpecific.h>
    33 using namespace WTF;
    34 #endif
    3531#include <wtf/Vector.h>
    3632
     
    6662    *errMsg = 0;
    6763       
    68     Lexer& lexer = KJS::lexer();
     64    Lexer& lexer = *JSGlobalData::threadInstance().lexer;
    6965
    7066    ASSERT(startingLineNumber > 0);
     
    7571    *sourceId = ++m_sourceId;
    7672
    77     int parseError = kjsyyparse(&lexer);
     73    int parseError = kjsyyparse(&JSGlobalData::threadInstance());
    7874    bool lexError = lexer.sawError();
    7975    lexer.clear();
     
    10298}
    10399
    104 Parser& parser()
    105 {
    106 #if USE(MULTIPLE_THREADS)
    107     static ThreadSpecific<Parser> staticParser;
    108     return *staticParser;
    109 #else
    110     static Parser staticParser;
    111     return staticParser;
    112 #endif
    113 }
    114 
    115100} // namespace KJS
  • trunk/JavaScriptCore/kjs/Parser.h

    r33979 r34412  
    3333#include <wtf/RefPtr.h>
    3434
    35 namespace WTF {
    36     template<typename T> class ThreadSpecific;
    37 }
    38 
    3935namespace KJS {
    4036
     
    6157
    6258    private:
    63         friend Parser& parser();
    64         friend class WTF::ThreadSpecific<Parser>;
     59        friend struct JSGlobalData;
     60        Parser();
    6561
    66         Parser(); // Use parser() instead.
    6762        void parse(ExecState*, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> source,
    6863                   int* sourceId, int* errLine, UString* errMsg);
     
    7772        int m_lastLine;
    7873    };
    79    
    80     Parser& parser(); // Returns the singleton JavaScript parser.
    8174
    8275    template <class ParsedNode>
  • trunk/JavaScriptCore/kjs/function.cpp

    r34355 r34412  
    166166
    167167    if (static_cast<size_t>(index) >= body->parameters().size())
    168         return CommonIdentifiers::shared()->nullIdentifier;
     168        return JSGlobalData::threadInstance().propertyNames->nullIdentifier;
    169169 
    170170    Identifier name = parameters[index];
     
    174174    for (size_t i = index + 1; i < size; ++i)
    175175        if (parameters[i] == name)
    176             return CommonIdentifiers::shared()->nullIdentifier;
     176            return JSGlobalData::threadInstance().propertyNames->nullIdentifier;
    177177
    178178    return name;
     
    261261  ASSERT(indexIsNumber && indexAsNumber < size);
    262262 
    263   _map[indexAsNumber] = CommonIdentifiers::shared()->nullIdentifier;
     263  _map[indexAsNumber] = JSGlobalData::threadInstance().propertyNames->nullIdentifier;
    264264}
    265265
     
    575575    UString errMsg;
    576576
    577     RefPtr<EvalNode> evalNode = parser().parse<EvalNode>(exec, UString(), 1, UStringSourceProvider::create(s), &sourceId, &errLine, &errMsg);
     577    RefPtr<EvalNode> evalNode = exec->parser()->parse<EvalNode>(exec, UString(), 1, UStringSourceProvider::create(s), &sourceId, &errLine, &errMsg);
    578578   
    579579    if (!evalNode)
  • trunk/JavaScriptCore/kjs/function_object.cpp

    r34334 r34412  
    164164    UString errMsg;
    165165    RefPtr<SourceProvider> source = UStringSourceProvider::create(body);
    166     RefPtr<FunctionBodyNode> functionBody = parser().parse<FunctionBodyNode>(exec, sourceURL, lineNumber, source, &sourceId, &errLine, &errMsg);
     166    RefPtr<FunctionBodyNode> functionBody = exec->parser()->parse<FunctionBodyNode>(exec, sourceURL, lineNumber, source, &sourceId, &errLine, &errMsg);
    167167
    168168    // No program node == syntax error - throw a syntax error
  • trunk/JavaScriptCore/kjs/grammar.y

    r34373 r34412  
    3434#include "lexer.h"
    3535#include "internal.h"
     36#include "JSGlobalData.h"
    3637#include "CommonIdentifiers.h"
    3738#include "NodeInfo.h"
     
    5051#endif
    5152
    52 #define LEXER (static_cast<KJS::Lexer*>(lexer))
    53 
    54 int kjsyylex(void* lvalp, void* llocp, void* lexer);
     53int kjsyylex(void* lvalp, void* llocp, void* globalPtr);
    5554int kjsyyerror(const char*);
    5655static inline bool allowAutomaticSemicolon(KJS::Lexer&, int);
     56
     57#define GLOBAL_DATA static_cast<JSGlobalData*>(globalPtr)
     58#define LEXER (GLOBAL_DATA->lexer)
    5759
    5860#define AUTO_SEMICOLON do { if (!allowAutomaticSemicolon(*LEXER, yychar)) YYABORT; } while (0)
     
    6769static ExpressionNode* makePrefixNode(ExpressionNode* expr, Operator);
    6870static ExpressionNode* makePostfixNode(ExpressionNode* expr, Operator);
    69 static PropertyNode* makeGetterOrSetterPropertyNode(const Identifier &getOrSet, const Identifier& name, ParameterNode*, FunctionBodyNode*, const SourceRange&);
    70 static ExpressionNodeInfo makeFunctionCallNode(ExpressionNodeInfo func, ArgumentsNodeInfo);
     71static PropertyNode* makeGetterOrSetterPropertyNode(void*, const Identifier &getOrSet, const Identifier& name, ParameterNode*, FunctionBodyNode*, const SourceRange&);
     72static ExpressionNodeInfo makeFunctionCallNode(void*, ExpressionNodeInfo func, ArgumentsNodeInfo);
    7173static ExpressionNode* makeTypeOfNode(ExpressionNode*);
    7274static ExpressionNode* makeDeleteNode(ExpressionNode*);
     
    9193#endif
    9294
    93 #define YYPARSE_PARAM lexer
    94 #define YYLEX_PARAM lexer
     95#define YYPARSE_PARAM globalPtr
     96#define YYLEX_PARAM globalPtr
    9597
    9698template <typename T> NodeDeclarationInfo<T> createNodeDeclarationInfo(T node, ParserRefCountedData<DeclarationStacks::VarStack>* varDecls,
     
    303305  | STRING ':' AssignmentExpr           { $$ = createNodeFeatureInfo<PropertyNode*>(new PropertyNode(Identifier(*$1), $3.m_node, PropertyNode::Constant), $3.m_featureInfo); }
    304306  | NUMBER ':' AssignmentExpr           { $$ = createNodeFeatureInfo<PropertyNode*>(new PropertyNode(Identifier(UString::from($1)), $3.m_node, PropertyNode::Constant), $3.m_featureInfo); }
    305   | IDENT IDENT '(' ')' OPENBRACE FunctionBody CLOSEBRACE    { $$ = createNodeFeatureInfo<PropertyNode*>(makeGetterOrSetterPropertyNode(*$1, *$2, 0, $6, LEXER->sourceRange($5, $7)), ClosureFeature); DBG($6, @5, @7); if (!$$.m_node) YYABORT; }
     307  | IDENT IDENT '(' ')' OPENBRACE FunctionBody CLOSEBRACE    { $$ = createNodeFeatureInfo<PropertyNode*>(makeGetterOrSetterPropertyNode(globalPtr, *$1, *$2, 0, $6, LEXER->sourceRange($5, $7)), ClosureFeature); DBG($6, @5, @7); if (!$$.m_node) YYABORT; }
    306308  | IDENT IDENT '(' FormalParameterList ')' OPENBRACE FunctionBody CLOSEBRACE
    307                                         { $$ = createNodeFeatureInfo<PropertyNode*>(makeGetterOrSetterPropertyNode(*$1, *$2, $4.head, $7, LEXER->sourceRange($6, $8)), ClosureFeature); DBG($7, @6, @8); if (!$$.m_node) YYABORT; }
     309                                        { $$ = createNodeFeatureInfo<PropertyNode*>(makeGetterOrSetterPropertyNode(globalPtr, *$1, *$2, $4.head, $7, LEXER->sourceRange($6, $8)), ClosureFeature); DBG($7, @6, @8); if (!$$.m_node) YYABORT; }
    308310;
    309311
     
    385387
    386388CallExpr:
    387     MemberExpr Arguments                { $$ = makeFunctionCallNode($1, $2); }
    388   | CallExpr Arguments                  { $$ = makeFunctionCallNode($1, $2); }
     389    MemberExpr Arguments                { $$ = makeFunctionCallNode(globalPtr, $1, $2); }
     390  | CallExpr Arguments                  { $$ = makeFunctionCallNode(globalPtr, $1, $2); }
    389391  | CallExpr '[' Expr ']'               { $$ = createNodeFeatureInfo<ExpressionNode*>(new BracketAccessorNode($1.m_node, $3.m_node, $3.m_featureInfo & AssignFeature), $1.m_featureInfo | $3.m_featureInfo); }
    390392  | CallExpr '.' IDENT                  { $$ = createNodeFeatureInfo<ExpressionNode*>(new DotAccessorNode($1.m_node, *$3), $1.m_featureInfo); }
     
    392394
    393395CallExprNoBF:
    394     MemberExprNoBF Arguments            { $$ = makeFunctionCallNode($1, $2); }
    395   | CallExprNoBF Arguments              { $$ = makeFunctionCallNode($1, $2); }
     396    MemberExprNoBF Arguments            { $$ = makeFunctionCallNode(globalPtr, $1, $2); }
     397  | CallExprNoBF Arguments              { $$ = makeFunctionCallNode(globalPtr, $1, $2); }
    396398  | CallExprNoBF '[' Expr ']'           { $$ = createNodeFeatureInfo<ExpressionNode*>(new BracketAccessorNode($1.m_node, $3.m_node, $3.m_featureInfo & AssignFeature), $1.m_featureInfo | $3.m_featureInfo); }
    397399  | CallExprNoBF '.' IDENT              { $$ = createNodeFeatureInfo<ExpressionNode*>(new DotAccessorNode($1.m_node, *$3), $1.m_featureInfo); }
     
    10021004
    10031005TryStatement:
    1004     TRY Block FINALLY Block             { $$ = createNodeDeclarationInfo<StatementNode*>(new TryNode($2.m_node, CommonIdentifiers::shared()->nullIdentifier, 0, $4.m_node),
     1006    TRY Block FINALLY Block             { $$ = createNodeDeclarationInfo<StatementNode*>(new TryNode($2.m_node, GLOBAL_DATA->propertyNames->nullIdentifier, 0, $4.m_node),
    10051007                                                                                         mergeDeclarationLists($2.m_varDeclarations, $4.m_varDeclarations),
    10061008                                                                                         mergeDeclarationLists($2.m_funcDeclarations, $4.m_funcDeclarations),
     
    10341036
    10351037FunctionExpr:
    1036     FUNCTION '(' ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = createNodeFeatureInfo(new FuncExprNode(CommonIdentifiers::shared()->nullIdentifier, $5, LEXER->sourceRange($4, $6)), ClosureFeature); DBG($5, @4, @6); }
    1037   | FUNCTION '(' FormalParameterList ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = createNodeFeatureInfo(new FuncExprNode(CommonIdentifiers::shared()->nullIdentifier, $6, LEXER->sourceRange($5, $7), $3.head), ClosureFeature); DBG($6, @5, @7); }
     1038    FUNCTION '(' ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = createNodeFeatureInfo(new FuncExprNode(GLOBAL_DATA->propertyNames->nullIdentifier, $5, LEXER->sourceRange($4, $6)), ClosureFeature); DBG($5, @4, @6); }
     1039  | FUNCTION '(' FormalParameterList ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = createNodeFeatureInfo(new FuncExprNode(GLOBAL_DATA->propertyNames->nullIdentifier, $6, LEXER->sourceRange($5, $7), $3.head), ClosureFeature); DBG($6, @5, @7); }
    10381040  | FUNCTION IDENT '(' ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = createNodeFeatureInfo(new FuncExprNode(*$2, $6, LEXER->sourceRange($5, $7)), ClosureFeature); DBG($6, @5, @7); }
    10391041  | FUNCTION IDENT '(' FormalParameterList ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = createNodeFeatureInfo(new FuncExprNode(*$2, $7, LEXER->sourceRange($6, $8), $4.head), ClosureFeature); DBG($7, @6, @8); }
     
    10661068
    10671069Program:
    1068     /* not in spec */                   { parser().didFinishParsing(new SourceElements, 0, 0, false, false, @0.last_line); }
    1069     | SourceElements                    { parser().didFinishParsing($1.m_node, $1.m_varDeclarations, $1.m_funcDeclarations,
     1070    /* not in spec */                   { GLOBAL_DATA->parser->didFinishParsing(new SourceElements, 0, 0, false, false, @0.last_line); }
     1071    | SourceElements                    { GLOBAL_DATA->parser->didFinishParsing($1.m_node, $1.m_varDeclarations, $1.m_funcDeclarations,
    10701072                                                                    ($1.m_featureInfo & EvalFeature) != 0, ($1.m_featureInfo & ClosureFeature) != 0,
    10711073                                                                    @1.last_line); }
     
    11821184}
    11831185
    1184 static ExpressionNodeInfo makeFunctionCallNode(ExpressionNodeInfo func, ArgumentsNodeInfo args)
     1186static ExpressionNodeInfo makeFunctionCallNode(void* globalPtr, ExpressionNodeInfo func, ArgumentsNodeInfo args)
    11851187{
    11861188    FeatureInfo features = func.m_featureInfo | args.m_featureInfo;
     
    11901192        ResolveNode* resolve = static_cast<ResolveNode*>(func.m_node);
    11911193        const Identifier& identifier = resolve->identifier();
    1192         if (identifier == CommonIdentifiers::shared()->eval)
     1194        if (identifier == GLOBAL_DATA->propertyNames->eval)
    11931195            return createNodeFeatureInfo<ExpressionNode*>(new EvalFunctionCallNode(args.m_node), EvalFeature | features);
    11941196        return createNodeFeatureInfo<ExpressionNode*>(new FunctionCallResolveNode(identifier, args.m_node), features);
     
    12291231}
    12301232
    1231 static PropertyNode* makeGetterOrSetterPropertyNode(const Identifier& getOrSet, const Identifier& name, ParameterNode* params, FunctionBodyNode* body, const SourceRange& source)
     1233static PropertyNode* makeGetterOrSetterPropertyNode(void* globalPtr, const Identifier& getOrSet, const Identifier& name, ParameterNode* params, FunctionBodyNode* body, const SourceRange& source)
    12321234{
    12331235    PropertyNode::Type type;
     
    12381240    else
    12391241        return 0;
    1240     return new PropertyNode(name, new FuncExprNode(CommonIdentifiers::shared()->nullIdentifier, body, source, params), type);
     1242    return new PropertyNode(name, new FuncExprNode(GLOBAL_DATA->propertyNames->nullIdentifier, body, source, params), type);
    12411243}
    12421244
     
    12921294}
    12931295
     1296#undef GLOBAL_DATA
  • trunk/JavaScriptCore/kjs/identifier.cpp

    r34361 r34412  
    2929#include <wtf/FastMalloc.h>
    3030#include <wtf/HashSet.h>
    31 #if USE(MULTIPLE_THREADS)
    32 #include <wtf/ThreadSpecific.h>
    33 using namespace WTF;
    34 #endif
    3531
    3632namespace KJS {
     33
     34typedef HashMap<const char*, RefPtr<UString::Rep>, PtrHash<const char*> > LiteralIdentifierTable;
    3735
    3836class IdentifierTable {
     
    6260    void remove(UString::Rep* r) { m_table.remove(r); }
    6361
     62    LiteralIdentifierTable& literalTable() { return m_literalTable; }
     63
    6464private:
    6565    HashSet<UString::Rep*> m_table;
    66 };
    67 
    68 typedef HashMap<const char*, RefPtr<UString::Rep>, PtrHash<const char*> > LiteralIdentifierTable;
    69 
    70 static inline IdentifierTable& identifierTable()
    71 {
    72 #if USE(MULTIPLE_THREADS)
    73     static ThreadSpecific<IdentifierTable> table;
    74     return *table;
    75 #else
    76     static IdentifierTable table;
    77     return table;
    78 #endif
    79 }
    80 
    81 static inline LiteralIdentifierTable& literalIdentifierTable()
    82 {
    83 #if USE(MULTIPLE_THREADS)
    84     static ThreadSpecific<LiteralIdentifierTable> table;
    85     return *table;
    86 #else
    87     static LiteralIdentifierTable table;
    88     return table;
    89 #endif
    90 }
    91 
    92 void Identifier::initializeIdentifierThreading()
    93 {
    94     identifierTable();
    95     literalIdentifierTable();
     66    LiteralIdentifierTable m_literalTable;
     67};
     68
     69IdentifierTable* createIdentifierTable()
     70{
     71    return new IdentifierTable;
     72}
     73
     74void deleteIdentifierTable(IdentifierTable* table)
     75{
     76    delete table;
    9677}
    9778
     
    156137    }
    157138
    158     LiteralIdentifierTable& literalTableLocalRef = literalIdentifierTable();
    159 
    160     const LiteralIdentifierTable::iterator& iter = literalTableLocalRef.find(c);
    161     if (iter != literalTableLocalRef.end())
     139    IdentifierTable& identifierTable = *JSGlobalData::threadInstance().identifierTable;
     140    LiteralIdentifierTable& literalIdentifierTable = identifierTable.literalTable();
     141
     142    const LiteralIdentifierTable::iterator& iter = literalIdentifierTable.find(c);
     143    if (iter != literalIdentifierTable.end())
    162144        return iter->second;
    163145
    164     UString::Rep* addedString = *identifierTable().add<const char*, CStringTranslator>(c).first;
    165     literalTableLocalRef.add(c, addedString);
     146    UString::Rep* addedString = *identifierTable.add<const char*, CStringTranslator>(c).first;
     147    literalIdentifierTable.add(c, addedString);
     148
     149    return addedString;
     150}
     151
     152PassRefPtr<UString::Rep> Identifier::add(JSGlobalData* globalData, const char* c)
     153{
     154    if (!c) {
     155        UString::Rep::null.hash();
     156        return &UString::Rep::null;
     157    }
     158
     159    if (!c[0]) {
     160        UString::Rep::empty.hash();
     161        return &UString::Rep::empty;
     162    }
     163
     164    IdentifierTable& identifierTable = *globalData->identifierTable;
     165    LiteralIdentifierTable& literalIdentifierTable = identifierTable.literalTable();
     166
     167    const LiteralIdentifierTable::iterator& iter = literalIdentifierTable.find(c);
     168    if (iter != literalIdentifierTable.end())
     169        return iter->second;
     170
     171    UString::Rep* addedString = *identifierTable.add<const char*, CStringTranslator>(c).first;
     172    literalIdentifierTable.add(c, addedString);
    166173
    167174    return addedString;
     
    207214   
    208215    UCharBuffer buf = {s, length};
    209     return *identifierTable().add<UCharBuffer, UCharBufferTranslator>(buf).first;
     216    return *JSGlobalData::threadInstance().identifierTable->add<UCharBuffer, UCharBufferTranslator>(buf).first;
    210217}
    211218
     
    219226    }
    220227
    221     return *identifierTable().add(r).first;
     228    return *JSGlobalData::threadInstance().identifierTable->add(r).first;
    222229}
    223230
  • trunk/JavaScriptCore/kjs/identifier.h

    r34361 r34412  
    2222#define KJS_IDENTIFIER_H
    2323
     24#include "JSGlobalData.h"
    2425#include "ustring.h"
    2526
     
    3435        explicit Identifier(UString::Rep* rep) : _ustring(add(rep)) { }
    3536        explicit Identifier(const UString& s) : _ustring(add(s.rep())) { }
     37
     38        Identifier(JSGlobalData* globalData, const char* s) : _ustring(add(globalData, s)) { } // Only to be used with string literals.
    3639
    3740        // Special constructor for cases where we overwrite an object in place.
     
    8083            { return equal(a._ustring.rep(), b); }
    8184       
     85        static PassRefPtr<UString::Rep> add(JSGlobalData*, const char*);
    8286        static PassRefPtr<UString::Rep> add(const UChar*, int length);
    8387        static PassRefPtr<UString::Rep> add(UString::Rep* r)
     
    99103        { return Identifier::equal(a, b); }
    100104
     105    IdentifierTable* createIdentifierTable();
     106    void deleteIdentifierTable(IdentifierTable*);
     107
    101108} // namespace KJS
    102109
  • trunk/JavaScriptCore/kjs/interpreter.cpp

    r34036 r34412  
    5050    UString errMsg;
    5151
    52     RefPtr<ProgramNode> progNode = parser().parse<ProgramNode>(exec, sourceURL, startingLineNumber, source, 0, &errLine, &errMsg);
     52    RefPtr<ProgramNode> progNode = exec->parser()->parse<ProgramNode>(exec, sourceURL, startingLineNumber, source, 0, &errLine, &errMsg);
    5353    if (!progNode)
    5454        return Completion(Throw, Error::create(exec, SyntaxError, errMsg, errLine, 0, sourceURL));
     
    7070    UString errMsg;
    7171
    72     RefPtr<ProgramNode> programNode = parser().parse<ProgramNode>(exec, sourceURL, startingLineNumber, source, &sourceId, &errLine, &errMsg);
     72    RefPtr<ProgramNode> programNode = exec->parser()->parse<ProgramNode>(exec, sourceURL, startingLineNumber, source, &sourceId, &errLine, &errMsg);
    7373
    7474    // no program node means a syntax error occurred
  • trunk/JavaScriptCore/kjs/lexer.cpp

    r34273 r34412  
    3434#include <wtf/unicode/Unicode.h>
    3535
    36 #if USE(MULTIPLE_THREADS)
    37 #include <wtf/ThreadSpecific.h>
    38 #endif
    39 
    4036using namespace WTF;
    4137using namespace Unicode;
     
    5248
    5349// a bridge for yacc from the C world to C++
    54 int kjsyylex(void* lvalp, void* llocp, void* lexer)
    55 {
    56   return static_cast<Lexer*>(lexer)->lex(lvalp, llocp);
     50int kjsyylex(void* lvalp, void* llocp, void* globalData)
     51{
     52    return static_cast<JSGlobalData*>(globalData)->lexer->lex(lvalp, llocp);
    5753}
    5854
     
    6359static const size_t initialReadBufferCapacity = 32;
    6460static const size_t initialStringTableCapacity = 64;
    65 
    66 Lexer& lexer()
    67 {
    68 #if USE(MULTIPLE_THREADS)
    69     static ThreadSpecific<Lexer> staticLexer;
    70     return *staticLexer;
    71 #else
    72     static Lexer staticLexer;
    73     return staticLexer;
    74 #endif
    75 }
    7661
    7762Lexer::Lexer()
  • trunk/JavaScriptCore/kjs/lexer.h

    r33979 r34412  
    2929#include <wtf/Vector.h>
    3030#include "SourceRange.h"
    31 
    32 namespace WTF {
    33     template<typename T> class ThreadSpecific;
    34 }
    3531
    3632namespace KJS {
     
    9591
    9692  private:
    97     friend Lexer& lexer();
    98     friend class WTF::ThreadSpecific<Lexer>;
     93    friend struct JSGlobalData;
    9994    Lexer();
    10095    ~Lexer();
     
    154149    const HashTable mainTable;
    155150  };
    156  
    157   Lexer& lexer(); // Returns the singletone JavaScript lexer.
    158151
    159152} // namespace KJS
  • trunk/JavaScriptCore/kjs/nodes.cpp

    r34400 r34412  
    194194    : m_expectedReturnType(ObjectType)
    195195{
    196     m_line = lexer().lineNo();
     196    m_line = JSGlobalData::threadInstance().lexer->lineNo();
    197197}
    198198
     
    200200    : m_expectedReturnType(expectedReturn)
    201201{
    202     m_line = lexer().lineNo();
     202    m_line = JSGlobalData::threadInstance().lexer->lineNo();
    203203}
    204204
     
    444444    RefPtr<RegisterID> base = generator.tempDestination(dst);
    445445    RegisterID* func = generator.newTemporary();
    446     generator.emitResolveWithBase(base.get(), func, CommonIdentifiers::shared()->eval);
     446    generator.emitResolveWithBase(base.get(), func, generator.propertyNames().eval);
    447447    return generator.emitCallEval(generator.finalDestination(dst, base.get()), func, base.get(), m_args.get());
    448448}
     
    17221722ScopeNode::ScopeNode(SourceElements* children, VarStack* varStack, FunctionStack* funcStack, bool usesEval, bool needsClosure)
    17231723    : BlockNode(children)
    1724     , m_sourceURL(parser().sourceURL())
    1725     , m_sourceId(parser().sourceId())
     1724    , m_sourceURL(JSGlobalData::threadInstance().parser->sourceURL())
     1725    , m_sourceId(JSGlobalData::threadInstance().parser->sourceId())
    17261726    , m_usesEval(usesEval)
    17271727    , m_needsClosure(needsClosure)
  • trunk/JavaScriptCore/kjs/testkjs.cpp

    r34273 r34412  
    276276    UString errMsg;
    277277    UString scriptUString(script.data());
    278     RefPtr<ProgramNode> programNode = parser().parse<ProgramNode>(exec, fileName, 1, UStringSourceProvider::create(scriptUString), 0, &errLine, &errMsg);
     278    RefPtr<ProgramNode> programNode = exec->parser()->parse<ProgramNode>(exec, fileName, 1, UStringSourceProvider::create(scriptUString), 0, &errLine, &errMsg);
    279279    if (!programNode) {
    280280        fprintf(stderr, "%s:%d: %s.\n", fileName.UTF8String().c_str(), errLine, errMsg.UTF8String().c_str());
Note: See TracChangeset for help on using the changeset viewer.