Ignore:
Timestamp:
May 5, 2009, 4:34:23 AM (16 years ago)
Author:
[email protected]
Message:

Bug 25559: Improve native function call performance
<https://bugs.webkit.org/show_bug.cgi?id=25559>

Reviewed by Gavin Barraclough

In order to cache calls to native functions we now make the standard
prototype functions use a small assembly thunk that converts the JS
calling convention into the native calling convention. As this is
only beneficial in the JIT we use the NativeFunctionWrapper typedef
to alternate between PrototypeFunction and JSFunction to keep the
code sane. This change from PrototypeFunction to NativeFunctionWrapper
is the bulk of this patch.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/JSFunction.h

    r43122 r43220  
    4747        JSFunction(PassRefPtr<Structure> structure)
    4848            : InternalFunction(structure)
    49             , m_scopeChain(NoScopeChain())
    5049        {
     50            clearScopeChain();
    5151        }
    5252
    5353    public:
     54        JSFunction(ExecState*, PassRefPtr<Structure>, int length, const Identifier&, NativeFunction);
    5455        JSFunction(ExecState*, const Identifier&, FunctionBodyNode*, ScopeChainNode*);
    5556        ~JSFunction();
     
    6263        JSValue call(ExecState*, JSValue thisValue, const ArgList&);
    6364
    64         void setScope(const ScopeChain& scopeChain) { m_scopeChain = scopeChain; }
    65         ScopeChain& scope() { return m_scopeChain; }
     65        void setScope(const ScopeChain& scopeChain) { setScopeChain(scopeChain); }
     66        ScopeChain& scope() { return scopeChain(); }
    6667
    6768        void setBody(FunctionBodyNode* body) { m_body = body; }
     
    7879        }
    7980
     81#if ENABLE(JIT)
     82        bool isHostFunction() const { return m_body && m_body->isHostFunction(); }
     83#else
     84        bool isHostFunction() const { return false; }
     85#endif
    8086    private:
    8187        virtual const ClassInfo* classInfo() const { return &info; }
     
    8995
    9096        RefPtr<FunctionBodyNode> m_body;
    91         ScopeChain m_scopeChain;
     97        ScopeChain& scopeChain()
     98        {
     99            ASSERT(!isHostFunction());
     100            return *reinterpret_cast<ScopeChain*>(m_data);
     101        }
     102        void clearScopeChain()
     103        {
     104            ASSERT(!isHostFunction());
     105            new (m_data) ScopeChain(NoScopeChain());
     106        }
     107        void setScopeChain(ScopeChainNode* sc)
     108        {
     109            ASSERT(!isHostFunction());
     110            new (m_data) ScopeChain(sc);
     111        }
     112        void setScopeChain(const ScopeChain& sc)
     113        {
     114            ASSERT(!isHostFunction());
     115            *reinterpret_cast<ScopeChain*>(m_data) = sc;
     116        }
     117        NativeFunction nativeFunction()
     118        {
     119            return *reinterpret_cast<NativeFunction*>(m_data);
     120        }
     121        void setNativeFunction(NativeFunction func)
     122        {
     123            *reinterpret_cast<NativeFunction*>(m_data) = func;
     124        }
     125        unsigned char m_data[sizeof(void*)];
    92126    };
    93127
Note: See TracChangeset for help on using the changeset viewer.