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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.