Changeset 27068 in webkit for trunk/JavaScriptCore/kjs/function.h


Ignore:
Timestamp:
Oct 25, 2007, 2:37:45 PM (18 years ago)
Author:
ggaren
Message:

Reviewed by Oliver Hunt.


Fixed http://bugs.webkit.org/show_bug.cgi?id=15694
Shrink the size of an activation object by 1 word


This is in preparation for adding a symbol table to the activation
object.


The basic strategy here is to rely on the mutual exclusion between
the arguments object pointer and the function pointer (you only need
the latter in order to create the former), and store them in the same
place. The LazyArgumentsObject class encapsulates this strategy.


Also inlined the ArgumentsImp constructor, for good measure.


SunSpider reports no regression. Regression tests pass.

  • JavaScriptCore.xcodeproj/project.pbxproj:
  • kjs/Context.cpp: (KJS::Context::~Context):
  • kjs/function.cpp: (KJS::ActivationImp::LazyArgumentsObject::createArgumentsObject): (KJS::ActivationImp::LazyArgumentsObject::mark): (KJS::): (KJS::ActivationImp::argumentsGetter): (KJS::ActivationImp::mark):
  • kjs/function.h: (KJS::ActivationImp::LazyArgumentsObject::LazyArgumentsObject): (KJS::ActivationImp::LazyArgumentsObject::getOrCreate): (KJS::ActivationImp::LazyArgumentsObject::resetArguments): (KJS::ActivationImp::LazyArgumentsObject::setArgumentsObject): (KJS::ActivationImp::LazyArgumentsObject::argumentsObject): (KJS::ActivationImp::LazyArgumentsObject::setFunction): (KJS::ActivationImp::LazyArgumentsObject::function): (KJS::ActivationImp::LazyArgumentsObject::createdArgumentsObject): (KJS::ActivationImp::LazyArgumentsObject::): (KJS::ActivationImp::ActivationImp::ActivationImp): (KJS::ActivationImp::resetArguments):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/function.h

    r27025 r27068  
    144144  class ActivationImp : public JSObject {
    145145  public:
    146     ActivationImp(FunctionImp* function, const List& arguments);
     146    class LazyArgumentsObject {
     147    public:
     148        LazyArgumentsObject(FunctionImp* f, const List& a)
     149            : arguments(a)
     150        {
     151            ASSERT(f);
     152            setFunction(f);
     153        }
     154
     155        Arguments* getOrCreate(ExecState* exec, ActivationImp* activationImp)
     156        {
     157            if (!createdArgumentsObject())
     158                createArgumentsObject(exec, activationImp);
     159            return argumentsObject();
     160        }
     161
     162        void resetArguments() { arguments.reset(); }
     163        void mark();
     164
     165    private:
     166        static const uintptr_t TagMask = 1; // Pointer alignment leaves this bit open for tagging.
     167       
     168        void setArgumentsObject(Arguments* a)
     169        {
     170            u.argumentsObject = a;
     171            u.bits |= TagMask;
     172        }
     173
     174        Arguments* argumentsObject()
     175        {
     176            ASSERT(createdArgumentsObject());
     177            return reinterpret_cast<Arguments*>(u.bits & ~TagMask);
     178        }
     179
     180        void setFunction(FunctionImp* f) { u.function = f; }
     181        FunctionImp* function()
     182        {
     183            ASSERT(!createdArgumentsObject());
     184            return u.function;
     185        }
     186
     187        bool createdArgumentsObject() { return (u.bits & TagMask) != 0; }
     188        void createArgumentsObject(ExecState*, ActivationImp*);
     189
     190        List arguments;
     191        union {
     192            // The low bit in this union is a flag: 0 means the union holds a
     193            // FunctionImp*; 1 means the union holds an Arguments*.
     194            uintptr_t bits;
     195            FunctionImp* function;
     196            Arguments* argumentsObject;
     197        } u;
     198    };
     199   
     200    ActivationImp::ActivationImp(FunctionImp* function, const List& arguments)
     201        : m_lazyArgumentsObject(function, arguments)
     202    {
     203    }
    147204
    148205    virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
     
    157214    bool isActivation() { return true; }
    158215
    159     void releaseArguments() { _arguments.reset(); }
     216    void resetArguments() { m_lazyArgumentsObject.resetArguments(); }
    160217
    161218  private:
    162219    static PropertySlot::GetValueFunc getArgumentsGetter();
    163220    static JSValue* argumentsGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot& slot);
    164     void createArgumentsObject(ExecState*);
    165 
    166     FunctionImp* _function;
    167     List _arguments;
    168     mutable Arguments* _argumentsObject;
     221   
     222    LazyArgumentsObject m_lazyArgumentsObject;
    169223  };
    170224
Note: See TracChangeset for help on using the changeset viewer.