Changeset 41168 in webkit for trunk/JavaScriptCore/runtime


Ignore:
Timestamp:
Feb 23, 2009, 7:58:09 PM (16 years ago)
Author:
[email protected]
Message:

2009-02-23 Geoffrey Garen <[email protected]>

Reviewed by Sam Weinig.

Next step in splitting JIT functionality out of the Interpreter class:
Moved vptr storage from Interpreter to JSGlobalData, so it could be shared
between Interpreter and JITStubs, and moved the *Trampoline JIT stubs
into the JITStubs class. Also added a VPtrSet class to encapsulate vptr
hacks during JSGlobalData initialization.


SunSpider says 0.4% faster. Meh.

  • JavaScriptCore.exp:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • interpreter/Interpreter.cpp: (JSC::Interpreter::Interpreter): (JSC::Interpreter::tryCacheGetByID): (JSC::Interpreter::privateExecute):
  • interpreter/Interpreter.h:
  • jit/JIT.cpp: (JSC::JIT::privateCompileMainPass): (JSC::JIT::privateCompile): (JSC::JIT::privateCompileCTIMachineTrampolines):
  • jit/JIT.h: (JSC::JIT::compileCTIMachineTrampolines):
  • jit/JITCall.cpp: (JSC::JIT::compileOpCall): (JSC::JIT::compileOpCallSlowCase):
  • jit/JITPropertyAccess.cpp: (JSC::JIT::privateCompilePatchGetArrayLength):
  • jit/JITStubs.cpp: (JSC::JITStubs::JITStubs): (JSC::JITStubs::tryCacheGetByID): (JSC::JITStubs::cti_vm_dontLazyLinkCall): (JSC::JITStubs::cti_op_get_by_val): (JSC::JITStubs::cti_op_get_by_val_byte_array): (JSC::JITStubs::cti_op_put_by_val): (JSC::JITStubs::cti_op_put_by_val_array): (JSC::JITStubs::cti_op_put_by_val_byte_array): (JSC::JITStubs::cti_op_is_string):
  • jit/JITStubs.h: (JSC::JITStubs::ctiArrayLengthTrampoline): (JSC::JITStubs::ctiStringLengthTrampoline): (JSC::JITStubs::ctiVirtualCallPreLink): (JSC::JITStubs::ctiVirtualCallLink): (JSC::JITStubs::ctiVirtualCall):
  • runtime/ArrayPrototype.cpp: (JSC::arrayProtoFuncPop): (JSC::arrayProtoFuncPush):
  • runtime/FunctionPrototype.cpp: (JSC::functionProtoFuncApply):
  • runtime/JSArray.h: (JSC::isJSArray):
  • runtime/JSByteArray.h: (JSC::asByteArray): (JSC::isJSByteArray):
  • runtime/JSCell.h:
  • runtime/JSFunction.h:
  • runtime/JSGlobalData.cpp: (JSC::VPtrSet::VPtrSet): (JSC::JSGlobalData::JSGlobalData): (JSC::JSGlobalData::create): (JSC::JSGlobalData::sharedInstance):
  • runtime/JSGlobalData.h:
  • runtime/JSString.h: (JSC::isJSString):
  • runtime/Operations.h: (JSC::jsLess): (JSC::jsLessEq):
  • wrec/WREC.cpp: (JSC::WREC::Generator::compileRegExp):
Location:
trunk/JavaScriptCore/runtime
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/ArrayPrototype.cpp

    r40993 r41168  
    301301JSValuePtr arrayProtoFuncPop(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList&)
    302302{
    303     if (exec->interpreter()->isJSArray(thisValue))
     303    if (isJSArray(&exec->globalData(), thisValue))
    304304        return asArray(thisValue)->pop();
    305305
     
    320320JSValuePtr arrayProtoFuncPush(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList& args)
    321321{
    322     if (exec->interpreter()->isJSArray(thisValue) && args.size() == 1) {
     322    if (isJSArray(&exec->globalData(), thisValue) && args.size() == 1) {
    323323        JSArray* array = asArray(thisValue);
    324324        array->push(exec, args.begin()->jsValue(exec));
  • trunk/JavaScriptCore/runtime/FunctionPrototype.cpp

    r41083 r41168  
    113113        if (asObject(array)->classInfo() == &Arguments::info)
    114114            asArguments(array)->fillArgList(exec, applyArgs);
    115         else if (exec->interpreter()->isJSArray(array))
     115        else if (isJSArray(&exec->globalData(), array))
    116116            asArray(array)->fillArgList(exec, applyArgs);
    117117        else if (asObject(array)->inherits(&JSArray::info)) {
  • trunk/JavaScriptCore/runtime/JSArray.h

    r40993 r41168  
    123123    }
    124124
     125    inline bool isJSArray(JSGlobalData* globalData, JSValuePtr v) { return v.isCell() && v.asCell()->vptr() == globalData->jsArrayVPtr; }
     126
    125127} // namespace JSC
    126128
  • trunk/JavaScriptCore/runtime/JSByteArray.h

    r40536 r41168  
    3434
    3535    class JSByteArray : public JSObject {
    36         friend class Interpreter;
     36        friend class VPtrSet;
    3737    public:
    3838        bool canAccessIndex(unsigned i) { return i < m_storage->length(); }
     
    108108        return static_cast<JSByteArray*>(asCell(value));
    109109    }
    110 }
    111110
    112 #endif
     111    inline bool isJSByteArray(JSGlobalData* globalData, JSValuePtr v) { return v.isCell() && v.asCell()->vptr() == globalData->jsByteArrayVPtr; }
     112
     113} // namespace JSC
     114
     115#endif // JSByteArray_h
  • trunk/JavaScriptCore/runtime/JSCell.h

    r40046 r41168  
    3333
    3434    class JSCell : Noncopyable {
    35         friend class JIT;
    3635        friend class GetterSetter;
    3736        friend class Heap;
     37        friend class JIT;
    3838        friend class JSNumberCell;
    3939        friend class JSObject;
     
    4141        friend class JSString;
    4242        friend class JSValuePtr;
    43         friend class Interpreter;
     43        friend class VPtrSet;
    4444
    4545    private:
  • trunk/JavaScriptCore/runtime/JSFunction.h

    r41126 r41168  
    3939
    4040    class JSFunction : public InternalFunction {
    41         friend class Interpreter;
    4241        friend class JIT;
    4342        friend class JITStubs;
     43        friend class VPtrSet;
    4444
    4545        typedef InternalFunction Base;
  • trunk/JavaScriptCore/runtime/JSGlobalData.cpp

    r41126 r41168  
    3636#include "Interpreter.h"
    3737#include "JSActivation.h"
     38#include "JSArray.h"
     39#include "JSByteArray.h"
    3840#include "JSClassRef.h"
    3941#include "JSLock.h"
     
    6567extern const HashTable stringTable;
    6668
    67 JSGlobalData::JSGlobalData(bool isShared)
     69struct VPtrSet {
     70    VPtrSet();
     71
     72    void* jsArrayVPtr;
     73    void* jsByteArrayVPtr;
     74    void* jsStringVPtr;
     75    void* jsFunctionVPtr;
     76};
     77
     78VPtrSet::VPtrSet()
     79{
     80    // Bizarrely, calling fastMalloc here is faster than allocating space on the stack.
     81    void* storage = fastMalloc(sizeof(CollectorBlock));
     82
     83    JSCell* jsArray = new (storage) JSArray(JSArray::createStructure(jsNull()));
     84    jsArrayVPtr = jsArray->vptr();
     85    jsArray->~JSCell();
     86
     87    JSCell* jsByteArray = new (storage) JSByteArray(JSByteArray::VPtrStealingHack);
     88    jsByteArrayVPtr = jsByteArray->vptr();
     89    jsByteArray->~JSCell();
     90
     91    JSCell* jsString = new (storage) JSString(JSString::VPtrStealingHack);
     92    jsStringVPtr = jsString->vptr();
     93    jsString->~JSCell();
     94
     95    JSCell* jsFunction = new (storage) JSFunction(JSFunction::createStructure(jsNull()));
     96    jsFunctionVPtr = jsFunction->vptr();
     97    jsFunction->~JSCell();
     98
     99    fastFree(storage);
     100}
     101
     102JSGlobalData::JSGlobalData(bool isShared, const VPtrSet& vptrSet)
    68103    : isSharedInstance(isShared)
    69104    , clientData(0)
    70     , interpreter(new Interpreter)
    71     , exception(noValue())
    72     , initializingLazyNumericCompareFunction(false)
    73105    , arrayTable(new HashTable(JSC::arrayTable))
    74106    , dateTable(new HashTable(JSC::dateTable))
     
    87119    , numberStructure(JSNumberCell::createStructure(jsNull()))
    88120#endif
     121    , jsArrayVPtr(vptrSet.jsArrayVPtr)
     122    , jsByteArrayVPtr(vptrSet.jsByteArrayVPtr)
     123    , jsStringVPtr(vptrSet.jsStringVPtr)
     124    , jsFunctionVPtr(vptrSet.jsFunctionVPtr)
    89125    , identifierTable(createIdentifierTable())
    90126    , propertyNames(new CommonIdentifiers(this))
     
    92128    , lexer(new Lexer(this))
    93129    , parser(new Parser)
     130    , interpreter(new Interpreter)
     131#if ENABLE(JIT)
     132    , jitStubs(this)
     133#endif
     134    , heap(this)
     135    , exception(noValue())
     136    , initializingLazyNumericCompareFunction(false)
    94137    , newParserObjects(0)
    95138    , parserObjectExtraRefCounts(0)
     
    97140    , dynamicGlobalObject(0)
    98141    , scopeNodeBeingReparsed(0)
    99     , heap(this)
    100142{
    101143#if PLATFORM(MAC)
    102144    startProfilerServerIfNeeded();
    103145#endif
    104     interpreter->initialize(this);
    105146}
    106147
     
    146187}
    147188
    148 PassRefPtr<JSGlobalData> JSGlobalData::create()
    149 {
    150     return adoptRef(new JSGlobalData);
     189PassRefPtr<JSGlobalData> JSGlobalData::create(bool isShared)
     190{
     191    return adoptRef(new JSGlobalData(isShared, VPtrSet()));
    151192}
    152193
     
    172213    JSGlobalData*& instance = sharedInstanceInternal();
    173214    if (!instance) {
    174         instance = new JSGlobalData(true);
     215        instance = create(true).releaseRef();
    175216#if ENABLE(JSC_MULTIPLE_THREADS)
    176217        instance->makeUsableFromMultipleThreads();
  • trunk/JavaScriptCore/runtime/JSGlobalData.h

    r41126 r41168  
    3232#include "Collector.h"
    3333#include "ExecutableAllocator.h"
     34#include "JITStubs.h"
    3435#include "JSValue.h"
    3536#include "SmallStrings.h"
     
    5960    class UString;
    6061    struct HashTable;
     62    struct VPtrSet;
    6163
    6264    class JSGlobalData : public RefCounted<JSGlobalData> {
     
    6971        static JSGlobalData& sharedInstance();
    7072
    71         static PassRefPtr<JSGlobalData> create();
     73        static PassRefPtr<JSGlobalData> create(bool isShared = false);
    7274        static PassRefPtr<JSGlobalData> createLeaked();
    7375        ~JSGlobalData();
     
    8082        bool isSharedInstance;
    8183        ClientData* clientData;
    82 
    83         Interpreter* interpreter;
    84         TimeoutChecker timeoutChecker;
    85 
    86         JSValuePtr exception;
    87 #if ENABLE(JIT)
    88         void* exceptionLocation;
    89 #endif
    90 
    91         const Vector<Instruction>& numericCompareFunction(ExecState*);
    92         Vector<Instruction> lazyNumericCompareFunction;
    93         bool initializingLazyNumericCompareFunction;
    9484
    9585        const HashTable* arrayTable;
     
    111101#endif
    112102
     103        void* jsArrayVPtr;
     104        void* jsByteArrayVPtr;
     105        void* jsStringVPtr;
     106        void* jsFunctionVPtr;
     107
    113108        IdentifierTable* identifierTable;
    114109        CommonIdentifiers* propertyNames;
    115110        const ArgList* 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.
    116111        SmallStrings smallStrings;
    117        
    118         HashMap<OpaqueJSClass*, OpaqueJSClassContextData*> opaqueJSClassData;
     112
     113#if ENABLE(ASSEMBLER)
     114        ExecutableAllocator executableAllocator;
     115#endif
    119116
    120117        Lexer* lexer;
    121118        Parser* parser;
     119        Interpreter* interpreter;
     120#if ENABLE(JIT)
     121        JITStubs jitStubs;
     122#endif
     123        TimeoutChecker timeoutChecker;
     124        Heap heap;
     125
     126        JSValuePtr exception;
     127#if ENABLE(JIT)
     128        void* exceptionLocation;
     129#endif
     130
     131        const Vector<Instruction>& numericCompareFunction(ExecState*);
     132        Vector<Instruction> lazyNumericCompareFunction;
     133        bool initializingLazyNumericCompareFunction;
     134
     135        HashMap<OpaqueJSClass*, OpaqueJSClassContextData*> opaqueJSClassData;
     136
    122137        HashSet<ParserRefCounted*>* newParserObjects;
    123138        HashCountedSet<ParserRefCounted*>* parserObjectExtraRefCounts;
     
    130145        ScopeNode* scopeNodeBeingReparsed;
    131146
    132         Heap heap;
    133 #if ENABLE(ASSEMBLER)
    134         PassRefPtr<ExecutablePool> poolForSize(size_t n) { return m_executableAllocator.poolForSize(n); }
    135 #endif
    136 
    137147    private:
    138         JSGlobalData(bool isShared = false);
    139 #if ENABLE(ASSEMBLER)
    140         ExecutableAllocator m_executableAllocator;
    141 #endif
    142 
     148        JSGlobalData(bool isShared, const VPtrSet&);
    143149        static JSGlobalData*& sharedInstanceInternal();
    144150    };
  • trunk/JavaScriptCore/runtime/JSString.h

    r39769 r41168  
    6161    class JSString : public JSCell {
    6262        friend class JIT;
    63         friend class Interpreter;
     63        friend class VPtrSet;
    6464
    6565    public:
     
    203203    }
    204204
     205    inline bool isJSString(JSGlobalData* globalData, JSValuePtr v) { return v.isCell() && v.asCell()->vptr() == globalData->jsStringVPtr; }
     206
    205207    // --- JSValue inlines ----------------------------
    206208
  • trunk/JavaScriptCore/runtime/Operations.h

    r41100 r41168  
    147147            return n1 < n2;
    148148
    149         Interpreter* interpreter = callFrame->interpreter();
    150         if (interpreter->isJSString(v1) && interpreter->isJSString(v2))
     149        JSGlobalData* globalData = &callFrame->globalData();
     150        if (isJSString(globalData, v1) && isJSString(globalData, v2))
    151151            return asString(v1)->value() < asString(v2)->value();
    152152
     
    172172            return n1 <= n2;
    173173
    174         Interpreter* interpreter = callFrame->interpreter();
    175         if (interpreter->isJSString(v1) && interpreter->isJSString(v2))
     174        JSGlobalData* globalData = &callFrame->globalData();
     175        if (isJSString(globalData, v1) && isJSString(globalData, v2))
    176176            return !(asString(v2)->value() < asString(v1)->value());
    177177
Note: See TracChangeset for help on using the changeset viewer.