Ignore:
Timestamp:
Sep 23, 2010, 11:49:56 AM (15 years ago)
Author:
[email protected]
Message:

Only copy captured variables into activation
https://bugs.webkit.org/show_bug.cgi?id=46330

Reviewed by Geoff Garen

We now track free variable information which means that
we no longer need to copy every variable defined in a
function. With this patch activations only retain those
variables needed for correctness. In order to interact
safely with the inspector this means that JSActivation
now provides its own lookup functions so it can avoid
trying to read or write to variables that have been
optimised out.

  • bytecode/CodeBlock.h:
  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::BytecodeGenerator):

  • parser/Nodes.h:

(JSC::ScopeNode::capturedVariableCount):
(JSC::ScopeNode::captures):

  • runtime/Arguments.h:

(JSC::JSActivation::copyRegisters):

  • runtime/Executable.cpp:

(JSC::FunctionExecutable::FunctionExecutable):
(JSC::FunctionExecutable::compileForCallInternal):
(JSC::FunctionExecutable::compileForConstructInternal):

  • runtime/Executable.h:

(JSC::FunctionExecutable::capturedVariableCount):

  • runtime/JSActivation.cpp:

(JSC::JSActivation::markChildren):
(JSC::JSActivation::symbolTableGet):
(JSC::JSActivation::symbolTablePut):
(JSC::JSActivation::getOwnPropertyNames):
(JSC::JSActivation::symbolTablePutWithAttributes):

  • runtime/JSActivation.h:
File:
1 edited

Legend:

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

    r63267 r68171  
    6363    markStack.appendValues(registerArray, count);
    6464
    65     size_t numVars = d()->functionExecutable->variableCount();
     65    size_t numVars = d()->functionExecutable->capturedVariableCount();
    6666
    6767    // Skip the call frame, which sits between the parameters and vars.
    6868    markStack.appendValues(registerArray + count + RegisterFile::CallFrameHeaderSize, numVars, MayContainNullValues);
     69}
     70
     71inline bool JSActivation::symbolTableGet(const Identifier& propertyName, PropertySlot& slot)
     72{
     73    SymbolTableEntry entry = symbolTable().inlineGet(propertyName.impl());
     74    if (!entry.isNull()) {
     75        ASSERT(entry.getIndex() < static_cast<int>(d()->functionExecutable->capturedVariableCount()));
     76        slot.setRegisterSlot(&registerAt(entry.getIndex()));
     77        return true;
     78    }
     79    return false;
     80}
     81
     82inline bool JSActivation::symbolTablePut(const Identifier& propertyName, JSValue value)
     83{
     84    ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
     85   
     86    SymbolTableEntry entry = symbolTable().inlineGet(propertyName.impl());
     87    if (entry.isNull())
     88        return false;
     89    if (entry.isReadOnly())
     90        return true;
     91    ASSERT(entry.getIndex() < static_cast<int>(d()->functionExecutable->capturedVariableCount()));
     92    registerAt(entry.getIndex()) = value;
     93    return true;
     94}
     95
     96void JSActivation::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
     97{
     98    SymbolTable::const_iterator end = symbolTable().end();
     99    for (SymbolTable::const_iterator it = symbolTable().begin(); it != end; ++it) {
     100        ASSERT(it->second.getIndex() < static_cast<int>(d()->functionExecutable->capturedVariableCount()));
     101        if (!(it->second.getAttributes() & DontEnum) || (mode == IncludeDontEnumProperties))
     102            propertyNames.add(Identifier(exec, it->first.get()));
     103    }
     104    // Skip the JSVariableObject implementation of getOwnPropertyNames
     105    JSObject::getOwnPropertyNames(exec, propertyNames, mode);
     106}
     107
     108inline bool JSActivation::symbolTablePutWithAttributes(const Identifier& propertyName, JSValue value, unsigned attributes)
     109{
     110    ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
     111   
     112    SymbolTable::iterator iter = symbolTable().find(propertyName.impl());
     113    if (iter == symbolTable().end())
     114        return false;
     115    SymbolTableEntry& entry = iter->second;
     116    ASSERT(!entry.isNull());
     117    if (entry.getIndex() >= static_cast<int>(d()->functionExecutable->capturedVariableCount()))
     118        return false;
     119    entry.setAttributes(attributes);
     120    registerAt(entry.getIndex()) = value;
     121    return true;
    69122}
    70123
Note: See TracChangeset for help on using the changeset viewer.