Changeset 185022 in webkit


Ignore:
Timestamp:
May 29, 2015, 5:19:01 PM (10 years ago)
Author:
mark.lam@apple.com
Message:

Refactoring HandlerInfo and UnlinkedHandlerInfo.
https://bugs.webkit.org/show_bug.cgi?id=145480

Reviewed by Benjamin Poulain.

HandlerInfo and UnlinkedHandlerInfo have common parts, but are not currently
expressed as 2 unrelated structs that happen to have near identical fields.
We can refactor them to better express their relationship. We can also add
some convenience functions to make the code that uses them a little more
readable.

  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::dumpBytecode):
(JSC::CodeBlock::CodeBlock):
(JSC::CodeBlock::handlerForBytecodeOffset):

  • bytecode/HandlerInfo.h:

(JSC::UnlinkedHandlerInfo::UnlinkedHandlerInfo):
(JSC::HandlerInfo::initialize):

  • I chose to include CodeLocationLabel arg even though it is unused by by non-JIT builds. This makes the call site cleaner to read.
  • bytecode/UnlinkedCodeBlock.h:

(JSC::UnlinkedSimpleJumpTable::add):
(JSC::UnlinkedInstruction::UnlinkedInstruction):
(JSC::UnlinkedCodeBlock::numberOfExceptionHandlers):
(JSC::UnlinkedCodeBlock::addExceptionHandler):
(JSC::UnlinkedCodeBlock::exceptionHandler):
(JSC::UnlinkedCodeBlock::symbolTable):

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::generate):

Location:
trunk/Source/JavaScriptCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r185002 r185022  
     12015-05-29  Mark Lam  <mark.lam@apple.com>
     2
     3        Refactoring HandlerInfo and UnlinkedHandlerInfo.
     4        https://bugs.webkit.org/show_bug.cgi?id=145480
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        HandlerInfo and UnlinkedHandlerInfo have common parts, but are not currently
     9        expressed as 2 unrelated structs that happen to have near identical fields.
     10        We can refactor them to better express their relationship.  We can also add
     11        some convenience functions to make the code that uses them a little more
     12        readable.
     13
     14        * bytecode/CodeBlock.cpp:
     15        (JSC::CodeBlock::dumpBytecode):
     16        (JSC::CodeBlock::CodeBlock):
     17        (JSC::CodeBlock::handlerForBytecodeOffset):
     18        * bytecode/HandlerInfo.h:
     19        (JSC::UnlinkedHandlerInfo::UnlinkedHandlerInfo):
     20        (JSC::HandlerInfo::initialize):
     21        - I chose to include CodeLocationLabel arg even though it is unused by
     22          by non-JIT builds.  This makes the call site cleaner to read.
     23
     24        * bytecode/UnlinkedCodeBlock.h:
     25        (JSC::UnlinkedSimpleJumpTable::add):
     26        (JSC::UnlinkedInstruction::UnlinkedInstruction):
     27        (JSC::UnlinkedCodeBlock::numberOfExceptionHandlers):
     28        (JSC::UnlinkedCodeBlock::addExceptionHandler):
     29        (JSC::UnlinkedCodeBlock::exceptionHandler):
     30        (JSC::UnlinkedCodeBlock::symbolTable):
     31        * bytecompiler/BytecodeGenerator.cpp:
     32        (JSC::BytecodeGenerator::generate):
     33
    1342015-05-28  Filip Pizlo  <fpizlo@apple.com>
    235
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.cpp

    r184828 r185022  
    655655        unsigned i = 0;
    656656        do {
    657             out.printf("\t %d: { start: [%4d] end: [%4d] target: [%4d] depth: [%4d] }\n", i + 1, m_rareData->m_exceptionHandlers[i].start, m_rareData->m_exceptionHandlers[i].end, m_rareData->m_exceptionHandlers[i].target, m_rareData->m_exceptionHandlers[i].scopeDepth);
     657            HandlerInfo& handler = m_rareData->m_exceptionHandlers[i];
     658            out.printf("\t %d: { start: [%4d] end: [%4d] target: [%4d] depth: [%4d] }\n",
     659                i + 1, handler.start, handler.end, handler.target, handler.scopeDepth);
    658660            ++i;
    659661        } while (i < m_rareData->m_exceptionHandlers.size());
     
    18201822            size_t nonLocalScopeDepth = scope->depth();
    18211823            for (size_t i = 0; i < count; i++) {
    1822                 const UnlinkedHandlerInfo& handler = unlinkedCodeBlock->exceptionHandler(i);
    1823                 m_rareData->m_exceptionHandlers[i].start = handler.start;
    1824                 m_rareData->m_exceptionHandlers[i].end = handler.end;
    1825                 m_rareData->m_exceptionHandlers[i].target = handler.target;
    1826                 m_rareData->m_exceptionHandlers[i].scopeDepth = nonLocalScopeDepth + handler.scopeDepth;
    1827 #if ENABLE(JIT)
    1828                 m_rareData->m_exceptionHandlers[i].nativeCode = CodeLocationLabel(MacroAssemblerCodePtr::createFromExecutableAddress(LLInt::getCodePtr(op_catch)));
    1829 #endif
     1824                const UnlinkedHandlerInfo& unlinkedHandler = unlinkedCodeBlock->exceptionHandler(i);
     1825                HandlerInfo& handler = m_rareData->m_exceptionHandlers[i];
     1826                handler.initialize(unlinkedHandler, nonLocalScopeDepth,
     1827                    CodeLocationLabel(MacroAssemblerCodePtr::createFromExecutableAddress(LLInt::getCodePtr(op_catch))));
    18301828            }
    18311829        }
     
    28862884    Vector<HandlerInfo>& exceptionHandlers = m_rareData->m_exceptionHandlers;
    28872885    for (size_t i = 0; i < exceptionHandlers.size(); ++i) {
     2886        HandlerInfo& handler = exceptionHandlers[i];
    28882887        // Handlers are ordered innermost first, so the first handler we encounter
    28892888        // that contains the source address is the correct handler to use.
    2890         if (exceptionHandlers[i].start <= bytecodeOffset && exceptionHandlers[i].end > bytecodeOffset)
    2891             return &exceptionHandlers[i];
     2889        if (handler.start <= bytecodeOffset && handler.end > bytecodeOffset)
     2890            return &handler;
    28922891    }
    28932892
  • trunk/Source/JavaScriptCore/bytecode/HandlerInfo.h

    r164424 r185022  
    3131namespace JSC {
    3232
    33 struct HandlerInfo {
     33struct HandlerInfoBase {
    3434    uint32_t start;
    3535    uint32_t end;
    3636    uint32_t target;
    3737    uint32_t scopeDepth;
     38};
     39
     40struct UnlinkedHandlerInfo : public HandlerInfoBase {
     41    UnlinkedHandlerInfo(uint32_t start, uint32_t end, uint32_t target, uint32_t scopeDepth)
     42    {
     43        this->start = start;
     44        this->end = end;
     45        this->target = target;
     46        this->scopeDepth = scopeDepth;
     47    }
     48};
     49
     50struct HandlerInfo : public HandlerInfoBase {
     51    void initialize(const UnlinkedHandlerInfo& unlinkedInfo, size_t nonLocalScopeDepth, CodeLocationLabel label)
     52    {
     53        start = unlinkedInfo.start;
     54        end = unlinkedInfo.end;
     55        target = unlinkedInfo.target;
     56        scopeDepth = unlinkedInfo.scopeDepth + nonLocalScopeDepth;
     57#if ENABLE(JIT)
     58        nativeCode = label;
     59#else
     60        UNUSED_PARAM(label);
     61#endif
     62    }
     63
    3864#if ENABLE(JIT)
    3965    CodeLocationLabel nativeCode;
  • trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h

    r183972 r185022  
    3131#include "CodeType.h"
    3232#include "ExpressionRangeInfo.h"
     33#include "HandlerInfo.h"
    3334#include "Identifier.h"
    3435#include "JSCell.h"
     
    247248};
    248249
    249 struct UnlinkedHandlerInfo {
    250     uint32_t start;
    251     uint32_t end;
    252     uint32_t target;
    253     uint32_t scopeDepth;
    254 };
    255 
    256250struct UnlinkedInstruction {
    257251    UnlinkedInstruction() { u.operand = 0; }
     
    428422    // Exception handling support
    429423    size_t numberOfExceptionHandlers() const { return m_rareData ? m_rareData->m_exceptionHandlers.size() : 0; }
    430     void addExceptionHandler(const UnlinkedHandlerInfo& hanler) { createRareDataIfNecessary(); return m_rareData->m_exceptionHandlers.append(hanler); }
     424    void addExceptionHandler(const UnlinkedHandlerInfo& handler) { createRareDataIfNecessary(); return m_rareData->m_exceptionHandlers.append(handler); }
    431425    UnlinkedHandlerInfo& exceptionHandler(int index) { ASSERT(m_rareData); return m_rareData->m_exceptionHandlers[index]; }
    432426
  • trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp

    r184868 r185022  
    130130       
    131131        ASSERT(range.tryData->targetScopeDepth != UINT_MAX);
    132         UnlinkedHandlerInfo info = {
    133             static_cast<uint32_t>(start), static_cast<uint32_t>(end),
    134             static_cast<uint32_t>(range.tryData->target->bind()),
    135             range.tryData->targetScopeDepth
    136         };
     132        UnlinkedHandlerInfo info(static_cast<uint32_t>(start), static_cast<uint32_t>(end),
     133            static_cast<uint32_t>(range.tryData->target->bind()), range.tryData->targetScopeDepth);
    137134        m_codeBlock->addExceptionHandler(info);
    138135    }
Note: See TracChangeset for help on using the changeset viewer.