Ignore:
Timestamp:
Jun 27, 2008, 3:35:33 PM (17 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

2008-06-27 Geoffrey Garen <[email protected]>

Reviewed by Oliver Hunt.


One RegisterFile to rule them all!


SunSpider reports a 0.2% speedup.

This patch removes the RegisterFileStack abstraction and replaces it with
a single register file that


(a) allocates a fixed storage area, including a fixed area for global
vars, so that no operation may cause the register file to reallocate


and

(b) swaps between global storage areas when executing code in different
global objects.


This patch also changes the layout of the register file so that all call
frames, including call frames for global code, get a header. This is
required to support re-entrant global code. It also just makes things simpler.


  • VM/CodeGenerator.cpp: (KJS::CodeGenerator::addGlobalVar): New function. Differs from addVar in that


(a) global vars don't contribute to a CodeBlock's numLocals count, since
global storage is fixed and allocated at startup


and


(b) references to global vars get shifted to elide intermediate stack
between "r" and the global storage area.


  • VM/Machine.cpp: (KJS::Machine::dumpRegisters): Updated this function to match the new register file layout, and added the ability to dump exact identifiers for the different parts of a call frame.


(KJS::Machine::unwindCallFrame): Updated this function to match the new
register file layout.


(KJS::Machine::execute): Updated this function to initialize a call frame
header for global code, and to swap global storage areas when switching
to execution in a new global object.


(KJS::Machine::privateExecute): Got rid of "safeForReentry" and re-reading
of registerBase because the register file is always safe for reentry now,
and registerBase never changes.


  • VM/Machine.h: Moved the call frame header enum from Machine to RegisterFile, to resolve a header dependency problem (a good sign that the enum belonged in RegisterFile all along!)
  • VM/RegisterFile.cpp:
  • VM/RegisterFile.h: Changed RegisterFile to mmap a fixed size register area. This allows us to avoid re-allocting the register file later on. Instead, we rely on the OS to allocate physical pages to the register file as necessary.
  • VM/RegisterFileStack.cpp: Removed. Tada!
  • VM/RegisterFileStack.h: Removed. Tada!
  • kjs/DebuggerCallFrame.cpp: Updated this class to match the new register file layout, greatly simplifying it in the process.
  • kjs/JSActivation.h:
  • kjs/JSActivation.cpp: Moved some of this logic up to JSVariableObject, since the global object now needs to be able to tear off its registers just like the activation object.
  • kjs/JSFunction.cpp: No need to fiddle with the register file anymore.
  • kjs/JSGlobalObject.h:
  • kjs/JSGlobalObject.cpp: Updated JSGlobalObject to support moving its global storage area into and out of the register file.
  • kjs/PropertySlot.cpp: No need to fiddle with the register file anymore.
  • kjs/collector.cpp: Renamed markStackObjectConservatively to markConservatively, since we don't just mark stack objects this way.


Also, added code to mark the machine's register file.

  • kjs/config.h: Moved some platforms #defines from here...
  • wtf/Platform.h: ...to here, to support mmap/VirtualAlloc detection in RegisterFile.h.

LayoutTests:

2008-06-26 Geoffrey Garen <[email protected]>

Reviewed by Oliver Hunt.


Added a test for what happens when a script exceeds the limit on declared
global variables.

  • fast/js/global-var-limit-expected.txt: Added.
  • fast/js/global-var-limit.html: Added.
  • fast/js/global-recursion-on-full-stack-expected.txt: Updated for new (slightly more correct) behavior. Since the stack overflow happens in the middle of a try/catch block, it should be caught, instead of logged to the console.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/VM/RegisterFile.cpp

    r34372 r34838  
    3030#include "RegisterFile.h"
    3131
    32 #include "RegisterFileStack.h"
    33 #include "Register.h"
    34 
    35 using namespace std;
    36 
    3732namespace KJS {
    3833
    39 size_t RegisterFile::newBuffer(size_t size, size_t capacity, size_t minCapacity, size_t maxSize, size_t offset)
     34RegisterFile::~RegisterFile()
    4035{
    41     capacity = (max(minCapacity, min(maxSize, max<size_t>(16, capacity + capacity / 4 + 1))));
    42     Register* newBuffer = static_cast<Register*>(fastCalloc(capacity, sizeof(Register))); // zero-filled memory
    43 
    44     if (m_buffer)
    45         memcpy(newBuffer + offset, m_buffer, size * sizeof(Register));
    46 
    47     setBuffer(newBuffer);
    48     return capacity;
    49 }
    50 
    51 bool RegisterFile::growBuffer(size_t minCapacity, size_t maxSize)
    52 {
    53     if (minCapacity > m_maxSize)
    54         return false;
    55 
    56     size_t numGlobalSlots = this->numGlobalSlots();
    57     size_t size = m_size + numGlobalSlots;
    58     size_t capacity = m_capacity + numGlobalSlots;
    59     minCapacity += numGlobalSlots;
    60 
    61     capacity = newBuffer(size, capacity, minCapacity, maxSize, 0);
    62 
    63     setBase(m_buffer + numGlobalSlots);
    64     m_capacity = capacity - numGlobalSlots;
    65     return true;
    66 }
    67 
    68 void RegisterFile::addGlobalSlots(size_t count)
    69 {
    70     if (!count)
    71         return;
    72     ASSERT(safeForReentry());
    73     size_t numGlobalSlots = this->numGlobalSlots();
    74     size_t size = m_size + numGlobalSlots;
    75     size_t capacity = m_capacity + numGlobalSlots;
    76     size_t minCapacity = size + count;
    77 
    78     if (minCapacity < capacity)
    79         memmove(m_buffer + count, m_buffer, size * sizeof(Register));
    80     else
    81         capacity = newBuffer(size, capacity, minCapacity, m_maxSize, count);
    82 
    83     numGlobalSlots += count;
    84 
    85     setBase(m_buffer + numGlobalSlots);
    86     m_capacity = capacity - numGlobalSlots;
    87 }
    88 
    89 void RegisterFile::copyGlobals(RegisterFile* src)
    90 {
    91     ASSERT(src->numGlobalSlots() > 0); // Global code should always allocate at least a "this" slot.
    92     size_t numSlotsToCopy = src->numGlobalSlots() - 1; // Don't propogate the nested "this" value back to the parent register file.
    93     if (!numSlotsToCopy)
    94         return;
    95     memcpy(m_buffer, src->m_buffer, numSlotsToCopy * sizeof(Register));
    96 }
    97 
    98 void RegisterFile::setBase(Register* base)
    99 {
    100     m_base = base;
    101     if (m_baseObserver)
    102         m_baseObserver->baseChanged(this);
    103 }
    104 
    105 void RegisterFile::clear()
    106 {
    107     setBase(m_buffer);
    108     m_size = 0;
     36#if HAVE(MMAP)
     37    munmap(m_buffer, m_capacity + m_maxGlobals);
     38#elif HAVE(VIRTUALALLOC)
     39    // FIXME: Use VirtualFree.
     40    fastFree(m_buffer);
     41#else
     42    #error "Don't know how to release virtual memory on this platform."
     43#endif
    10944}
    11045
Note: See TracChangeset for help on using the changeset viewer.