Changeset 37125 in webkit for trunk/JavaScriptCore/VM/Machine.cpp


Ignore:
Timestamp:
Sep 30, 2008, 4:46:29 PM (17 years ago)
Author:
Darin Adler
Message:

2008-09-30 Darin Adler <Darin Adler>

Reviewed by Geoff Garen.

Replaced the m_prev field of ExecState with a bit in the
call frame pointer to indicate "host" call frames.

  • VM/Machine.cpp: (JSC::makeHostCallFramePointer): Added. Sets low bit. (JSC::isHostCallFrame): Added. Checks low bit. (JSC::stripHostCallFrameBit): Added. Clears low bit. (JSC::Machine::unwindCallFrame): Replaced null check that was formerly used to detect host call frames with an isHostCallFrame check. (JSC::Machine::execute): Pass in a host call frame pointer rather than always passing 0 when starting execution from the host. This allows us to follow the entire call frame pointer chain when desired, or to stop at the host calls when that's desired. (JSC::Machine::privateExecute): Replaced null check that was formerly used to detect host call frames with an isHostCallFrame check. (JSC::Machine::retrieveCaller): Ditto. (JSC::Machine::retrieveLastCaller): Ditto. (JSC::Machine::callFrame): Removed the code to walk up m_prev pointers and replaced it with code that uses the caller pointer and uses the stripHostCallFrameBit function.
  • kjs/ExecState.cpp: Removed m_prev.
  • kjs/ExecState.h: Ditto.
File:
1 edited

Legend:

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

    r37089 r37125  
    106106#endif // #ENABLE(CTI)
    107107
     108static const intptr_t HostCallFrameMask = 1;
     109
     110static inline Register* makeHostCallFramePointer(Register* callFrame)
     111{
     112    return reinterpret_cast<Register*>(reinterpret_cast<intptr_t>(callFrame) | HostCallFrameMask);
     113}
     114
     115static inline bool isHostCallFrame(Register* callFrame)
     116{
     117    return reinterpret_cast<intptr_t>(callFrame) & HostCallFrameMask;
     118}
     119
     120static inline Register* stripHostCallFrameBit(Register* callFrame)
     121{
     122    return reinterpret_cast<Register*>(reinterpret_cast<intptr_t>(callFrame) & ~HostCallFrameMask);
     123}
     124
    108125// Returns the depth of the scope chain within a given call frame.
    109126static int depth(CodeBlock* codeBlock, ScopeChain& sc)
     
    793810    void* returnPC = r[RegisterFile::ReturnPC].v();
    794811    r = r[RegisterFile::CallerRegisters].r();
    795     if (!r)
     812    if (isHostCallFrame(r))
    796813        return false;
    797814
     
    897914    Register* r = m_registerFile.base() + oldSize + codeBlock->numParameters + RegisterFile::CallFrameHeaderSize;
    898915    r[codeBlock->thisRegister] = thisObj;
    899     initializeCallFrame(r, codeBlock, 0, scopeChain, 0, 0, 0, 0);
     916    initializeCallFrame(r, codeBlock, 0, scopeChain, makeHostCallFramePointer(0), 0, 0, 0);
    900917
    901918    if (codeBlock->needsFullScopeChain)
     
    962979    }
    963980    // a 0 codeBlock indicates a built-in caller
    964     initializeCallFrame(r, codeBlock, 0, scopeChain, 0, 0, argc, function);
     981    initializeCallFrame(r, codeBlock, 0, scopeChain, makeHostCallFramePointer(exec->m_callFrame), 0, argc, function);
    965982
    966983    ExecState newExec(exec, r);
     
    10451062    // a 0 codeBlock indicates a built-in caller
    10461063    r[codeBlock->thisRegister] = thisObj;
    1047     initializeCallFrame(r, codeBlock, 0, scopeChain, 0, 0, 0, 0);
     1064    initializeCallFrame(r, codeBlock, 0, scopeChain, makeHostCallFramePointer(exec->m_callFrame), 0, 0, 0);
    10481065
    10491066    if (codeBlock->needsFullScopeChain)
     
    33633380        exec->m_callFrame = r;
    33643381       
    3365         if (!r)
     3382        if (isHostCallFrame(r))
    33663383            return returnValue;
    33673384
     
    38543871
    38553872    Register* callerR = r[RegisterFile::CallerRegisters].r();
    3856     if (!callerR)
     3873    if (isHostCallFrame(callerR))
    38573874        return jsNull();
    38583875
     
    38723889    Register* r = exec->m_callFrame;
    38733890    Register* callerR = r[RegisterFile::CallerRegisters].r();
    3874     if (!callerR)
     3891    if (isHostCallFrame(callerR))
    38753892        return;
    38763893
     
    38933910Register* Machine::callFrame(ExecState* exec, InternalFunction* function) const
    38943911{
    3895     for (; exec; exec = exec->m_prev)
    3896         for (Register* r = exec->m_callFrame; r; r = r[RegisterFile::CallerRegisters].r())
    3897             if (r[RegisterFile::Callee].jsValue(exec) == function)
    3898                 return r;
    3899                
     3912    for (Register* r = exec->m_callFrame; r; r = stripHostCallFrameBit(r[RegisterFile::CallerRegisters].r()))
     3913        if (r[RegisterFile::Callee].getJSValue() == function)
     3914            return r;
    39003915    return 0;
    39013916}
Note: See TracChangeset for help on using the changeset viewer.