⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 179746 in webkit


Ignore:
Timestamp:
Feb 6, 2015, 8:04:39 AM (12 years ago)
Author:
fpizlo@apple.com
Message:

Remove BytecodeGenerator::preserveLastVar() and replace it with a more robust mechanism for preserving non-temporary registers
https://bugs.webkit.org/show_bug.cgi?id=141211

Reviewed by Mark Lam.

Previously, the way non-temporary registers were preserved (i.e. not reclaimed anytime
we did newTemporary()) by calling preserveLastVar() after all non-temps are created. It
would raise the refcount on the last (highest-numbered) variable created, and rely on
the fact that register reclamation started at higher-numbered registers and worked its
way down. So any retained register would block any lower-numbered registers from being
reclaimed.

Also, preserveLastVar() sets a thing called m_firstConstantIndex. It's unused.

This removes preserveLastVar() and makes addVar() retain each register it creates. This
is more explicit, since addVar() is the mechanism for creating non-temporary registers.

To make this work I had to remove an assertion that Register::setIndex() can only be
called when the refcount is zero. This method might be called after a var is created to
change its index. This previously worked because preserveLastVar() would be called after
we had already made all index changes, so the vars would still have refcount zero. Now
they have refcount 1. I think it's OK to lose this assertion; I can't remember this
assertion ever firing in a way that alerted me to a serious issue.

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::BytecodeGenerator):
(JSC::BytecodeGenerator::preserveLastVar): Deleted.

  • bytecompiler/BytecodeGenerator.h:

(JSC::BytecodeGenerator::addVar):

  • bytecompiler/RegisterID.h:

(JSC::RegisterID::setIndex):

Location:
trunk/Source/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r179743 r179746  
     12015-02-04  Filip Pizlo  <fpizlo@apple.com>
     2
     3        Remove BytecodeGenerator::preserveLastVar() and replace it with a more robust mechanism for preserving non-temporary registers
     4        https://bugs.webkit.org/show_bug.cgi?id=141211
     5
     6        Reviewed by Mark Lam.
     7
     8        Previously, the way non-temporary registers were preserved (i.e. not reclaimed anytime
     9        we did newTemporary()) by calling preserveLastVar() after all non-temps are created. It
     10        would raise the refcount on the last (highest-numbered) variable created, and rely on
     11        the fact that register reclamation started at higher-numbered registers and worked its
     12        way down. So any retained register would block any lower-numbered registers from being
     13        reclaimed.
     14       
     15        Also, preserveLastVar() sets a thing called m_firstConstantIndex. It's unused.
     16       
     17        This removes preserveLastVar() and makes addVar() retain each register it creates. This
     18        is more explicit, since addVar() is the mechanism for creating non-temporary registers.
     19       
     20        To make this work I had to remove an assertion that Register::setIndex() can only be
     21        called when the refcount is zero. This method might be called after a var is created to
     22        change its index. This previously worked because preserveLastVar() would be called after
     23        we had already made all index changes, so the vars would still have refcount zero. Now
     24        they have refcount 1. I think it's OK to lose this assertion; I can't remember this
     25        assertion ever firing in a way that alerted me to a serious issue.
     26       
     27        * bytecompiler/BytecodeGenerator.cpp:
     28        (JSC::BytecodeGenerator::BytecodeGenerator):
     29        (JSC::BytecodeGenerator::preserveLastVar): Deleted.
     30        * bytecompiler/BytecodeGenerator.h:
     31        (JSC::BytecodeGenerator::addVar):
     32        * bytecompiler/RegisterID.h:
     33        (JSC::RegisterID::setIndex):
     34
    1352015-02-06  Andreas Kling  <akling@apple.com>
    236
  • trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp

    r179372 r179746  
    152152}
    153153
    154 void BytecodeGenerator::preserveLastVar()
    155 {
    156     if ((m_firstConstantIndex = m_calleeRegisters.size()) != 0)
    157         m_lastVar = &m_calleeRegisters.last();
    158 }
    159 
    160154BytecodeGenerator::BytecodeGenerator(VM& vm, ProgramNode* programNode, UnlinkedProgramCodeBlock* codeBlock, DebuggerMode debuggerMode, ProfilerMode profilerMode)
    161155    : m_shouldEmitDebugHooks(Options::forceDebuggerBytecodeGeneration() || debuggerMode == DebuggerOn)
     
    429423        addParameter(simpleParameter->boundProperty(), index);
    430424    }
    431     preserveLastVar();
    432425
    433426    // We declare the callee's name last because it should lose to a var, function, and/or parameter declaration.
     
    494487    }
    495488    codeBlock->adoptVariables(variables);
    496     preserveLastVar();
    497489}
    498490
  • trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h

    r178926 r179746  
    631631        {
    632632            ++m_codeBlock->m_numVars;
    633             return newRegister();
     633            RegisterID* result = newRegister();
     634            ASSERT(VirtualRegister(result->index()).toLocal() == m_codeBlock->m_numVars - 1);
     635            result->ref(); // We should never free this slot.
     636            return result;
    634637        }
    635638
     
    778781        SegmentedVector<Label, 32> m_labels;
    779782        LabelScopeStore m_labelScopes;
    780         RefPtr<RegisterID> m_lastVar;
    781783        int m_finallyDepth;
    782784        int m_localScopeDepth;
     
    792794        SegmentedVector<TryData, 8> m_tryData;
    793795
    794         int m_firstConstantIndex;
    795796        int m_nextConstantOffset;
    796797
  • trunk/Source/JavaScriptCore/bytecompiler/RegisterID.h

    r165676 r179746  
    7171        void setIndex(int index)
    7272        {
    73             ASSERT(!m_refCount);
    7473#ifndef NDEBUG
    7574            m_didSetIndex = true;
Note: See TracChangeset for help on using the changeset viewer.