Changeset 31936 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Apr 16, 2008, 2:30:01 AM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Darin.

Implement an abstraction for thread-specific storage, use it to get rid of some static objects.

SunSpider results were not conclusive, possibly up to 0.2% slowdown.

  • wtf/ThreadSpecific.h: Added. (WTF::::ThreadSpecific): (WTF::::~ThreadSpecific): (WTF::::get): (WTF::::set): (WTF::::destroy): (WTF::T): (WTF::::operator): Only implemented for platforms that use pthreads.
  • kjs/CommonIdentifiers.cpp: (KJS::CommonIdentifiers::shared):
  • kjs/CommonIdentifiers.h:
  • kjs/InitializeThreading.cpp: (KJS::initializeThreading):
  • kjs/Parser.cpp: (KJS::parser):
  • kjs/Parser.h:
  • kjs/identifier.cpp: (KJS::identifierTable): (KJS::literalIdentifierTable): (KJS::Identifier::initializeIdentifierThreading):
  • kjs/identifier.h:
  • kjs/lexer.cpp: (KJS::lexer):
  • kjs/lexer.h: Make static instances per-thread.
Location:
trunk/JavaScriptCore/kjs
Files:
9 edited

Legend:

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

    r29663 r31936  
    2222#include "CommonIdentifiers.h"
    2323
     24#if USE(MULTIPLE_THREADS)
     25#include <wtf/ThreadSpecific.h>
     26#endif
     27
    2428namespace KJS {
    2529
     
    3741CommonIdentifiers* CommonIdentifiers::shared()
    3842{
    39     static CommonIdentifiers* sharedInstance;
    40     if (!sharedInstance) {
    41         JSLock lock;
    42         sharedInstance = new CommonIdentifiers;
    43     }
     43#if USE(MULTIPLE_THREADS)
     44    static ThreadSpecific<CommonIdentifiers> sharedInstance;
    4445    return sharedInstance;
     46#else
     47    static CommonIdentifiers sharedInstance;
     48    return &sharedInstance;
     49#endif
    4550}
    4651
  • trunk/JavaScriptCore/kjs/CommonIdentifiers.h

    r31208 r31936  
    2424#include "identifier.h"
    2525#include <wtf/Noncopyable.h>
     26
     27namespace WTF {
     28    template<typename T> class ThreadSpecific;
     29}
    2630
    2731// List of property names, passed to a macro so we can do set them up various
     
    7175    private:
    7276        CommonIdentifiers();
     77        template<typename T> friend class WTF::ThreadSpecific;
    7378
    7479    public:
  • trunk/JavaScriptCore/kjs/InitializeThreading.cpp

    r31813 r31936  
    3232#include "DateMath.h"
    3333#include "dtoa.h"
     34#include "identifier.h"
     35#include "lexer.h"
     36#include "Parser.h"
    3437#include "ustring.h"
    3538#include <wtf/Threading.h>
     
    4447        s_dtoaP5Mutex = new Mutex;
    4548        UString::null();
     49        Identifier::initializeIdentifierThreading();
     50        CommonIdentifiers::shared();
     51        lexer();
    4652        initDateMath();
    4753    }
  • trunk/JavaScriptCore/kjs/Parser.cpp

    r31809 r31936  
    2828#include "lexer.h"
    2929#include <wtf/HashSet.h>
     30#if USE(MULTIPLE_THREADS)
     31#include <wtf/ThreadSpecific.h>
     32#endif
    3033#include <wtf/Vector.h>
    3134
     
    8588Parser& parser()
    8689{
    87     ASSERT(JSLock::currentThreadIsHoldingLock());
    88 
    89     static Parser& staticParser = *new Parser;
     90#if USE(MULTIPLE_THREADS)
     91    static ThreadSpecific<Parser> staticParser;
     92    return *staticParser;
     93#else
     94    static Parser staticParser;
    9095    return staticParser;
     96#endif
    9197}
    9298
  • trunk/JavaScriptCore/kjs/Parser.h

    r31072 r31936  
    3232#include "nodes.h"
    3333
     34namespace WTF {
     35    template<typename T> class ThreadSpecific;
     36}
     37
    3438namespace KJS {
    3539
     
    5761    private:
    5862        friend Parser& parser();
     63        template<typename T> friend class WTF::ThreadSpecific;
    5964
    6065        Parser(); // Use parser() instead.
  • trunk/JavaScriptCore/kjs/identifier.cpp

    r31677 r31936  
    2929#include <wtf/FastMalloc.h>
    3030#include <wtf/HashSet.h>
     31#if USE(MULTIPLE_THREADS)
     32#include <wtf/ThreadSpecific.h>
     33#endif
    3134
    3235namespace WTF {
     
    5154typedef HashSet<UString::Rep*> IdentifierTable;
    5255typedef HashMap<const char*, UString::Rep*, PtrHash<const char*> > LiteralIdentifierTable;
    53 static IdentifierTable* table;
    54 static LiteralIdentifierTable* literalTable;
    5556
    5657static inline IdentifierTable& identifierTable()
    5758{
    58     ASSERT(JSLock::lockCount() > 0);
    59 
    60     if (!table)
    61         table = new IdentifierTable;
     59#if USE(MULTIPLE_THREADS)
     60    static ThreadSpecific<IdentifierTable> table;
    6261    return *table;
     62#else
     63    static IdentifierTable table;
     64    return table;
     65#endif
    6366}
    6467
    6568static inline LiteralIdentifierTable& literalIdentifierTable()
    6669{
    67     ASSERT(JSLock::lockCount() > 0);
    68 
    69     if (!literalTable)
    70         literalTable = new LiteralIdentifierTable;
    71     return *literalTable;
    72 }
    73 
     70#if USE(MULTIPLE_THREADS)
     71    static ThreadSpecific<LiteralIdentifierTable> table;
     72    return *table;
     73#else
     74    static LiteralIdentifierTable table;
     75    return table;
     76#endif
     77}
     78
     79void Identifier::initializeIdentifierThreading()
     80{
     81    identifierTable();
     82    literalIdentifierTable();
     83}
    7484
    7585bool Identifier::equal(const UString::Rep *r, const char *s)
  • trunk/JavaScriptCore/kjs/identifier.h

    r31319 r31936  
    7070        static PassRefPtr<UString::Rep> add(const char*);
    7171
     72        static void initializeIdentifierThreading();
     73
    7274    private:
    7375        UString _ustring;
  • trunk/JavaScriptCore/kjs/lexer.cpp

    r31811 r31936  
    3333#include <string.h>
    3434#include <wtf/Assertions.h>
     35#if USE(MULTIPLE_THREADS)
     36#include <wtf/ThreadSpecific.h>
     37#endif
    3538#include <wtf/unicode/Unicode.h>
    3639
     
    6366Lexer& lexer()
    6467{
    65     ASSERT(JSLock::currentThreadIsHoldingLock());
    66 
    67     // FIXME: We'd like to avoid calling new here, but we don't currently
    68     // support tearing down the Lexer at app quit time, since that would involve
    69     // tearing down its UString data members without holding the JSLock.
    70     static Lexer* staticLexer = new Lexer;
     68#if USE(MULTIPLE_THREADS)
     69    static ThreadSpecific<Lexer> staticLexer;
    7170    return *staticLexer;
     71#else
     72    static Lexer staticLexer;
     73    return staticLexer;
     74#endif
    7275}
    7376
  • trunk/JavaScriptCore/kjs/lexer.h

    r31811 r31936  
    2727#include "ustring.h"
    2828#include <wtf/Vector.h>
     29
     30namespace WTF {
     31    template<typename T> class ThreadSpecific;
     32}
    2933
    3034namespace KJS {
     
    8993  private:
    9094    friend Lexer& lexer();
     95    template<typename T> friend class WTF::ThreadSpecific;
    9196    Lexer();
    9297
Note: See TracChangeset for help on using the changeset viewer.