Title: [185022] trunk/Source/_javascript_Core
Revision
185022
Author
[email protected]
Date
2015-05-29 17:19:01 -0700 (Fri, 29 May 2015)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (185021 => 185022)


--- trunk/Source/_javascript_Core/ChangeLog	2015-05-30 00:11:48 UTC (rev 185021)
+++ trunk/Source/_javascript_Core/ChangeLog	2015-05-30 00:19:01 UTC (rev 185022)
@@ -1,3 +1,36 @@
+2015-05-29  Mark Lam  <[email protected]>
+
+        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):
+
 2015-05-28  Filip Pizlo  <[email protected]>
 
         Non-speculative Branch should be fast in the FTL

Modified: trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp (185021 => 185022)


--- trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp	2015-05-30 00:11:48 UTC (rev 185021)
+++ trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp	2015-05-30 00:19:01 UTC (rev 185022)
@@ -654,7 +654,9 @@
         out.printf("\nException Handlers:\n");
         unsigned i = 0;
         do {
-            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);
+            HandlerInfo& handler = m_rareData->m_exceptionHandlers[i];
+            out.printf("\t %d: { start: [%4d] end: [%4d] target: [%4d] depth: [%4d] }\n",
+                i + 1, handler.start, handler.end, handler.target, handler.scopeDepth);
             ++i;
         } while (i < m_rareData->m_exceptionHandlers.size());
     }
@@ -1819,14 +1821,10 @@
             m_rareData->m_exceptionHandlers.resizeToFit(count);
             size_t nonLocalScopeDepth = scope->depth();
             for (size_t i = 0; i < count; i++) {
-                const UnlinkedHandlerInfo& handler = unlinkedCodeBlock->exceptionHandler(i);
-                m_rareData->m_exceptionHandlers[i].start = handler.start;
-                m_rareData->m_exceptionHandlers[i].end = handler.end;
-                m_rareData->m_exceptionHandlers[i].target = handler.target;
-                m_rareData->m_exceptionHandlers[i].scopeDepth = nonLocalScopeDepth + handler.scopeDepth;
-#if ENABLE(JIT)
-                m_rareData->m_exceptionHandlers[i].nativeCode = CodeLocationLabel(MacroAssemblerCodePtr::createFromExecutableAddress(LLInt::getCodePtr(op_catch)));
-#endif
+                const UnlinkedHandlerInfo& unlinkedHandler = unlinkedCodeBlock->exceptionHandler(i);
+                HandlerInfo& handler = m_rareData->m_exceptionHandlers[i];
+                handler.initialize(unlinkedHandler, nonLocalScopeDepth,
+                    CodeLocationLabel(MacroAssemblerCodePtr::createFromExecutableAddress(LLInt::getCodePtr(op_catch))));
             }
         }
 
@@ -2885,10 +2883,11 @@
     
     Vector<HandlerInfo>& exceptionHandlers = m_rareData->m_exceptionHandlers;
     for (size_t i = 0; i < exceptionHandlers.size(); ++i) {
+        HandlerInfo& handler = exceptionHandlers[i];
         // Handlers are ordered innermost first, so the first handler we encounter
         // that contains the source address is the correct handler to use.
-        if (exceptionHandlers[i].start <= bytecodeOffset && exceptionHandlers[i].end > bytecodeOffset)
-            return &exceptionHandlers[i];
+        if (handler.start <= bytecodeOffset && handler.end > bytecodeOffset)
+            return &handler;
     }
 
     return 0;

Modified: trunk/Source/_javascript_Core/bytecode/HandlerInfo.h (185021 => 185022)


--- trunk/Source/_javascript_Core/bytecode/HandlerInfo.h	2015-05-30 00:11:48 UTC (rev 185021)
+++ trunk/Source/_javascript_Core/bytecode/HandlerInfo.h	2015-05-30 00:19:01 UTC (rev 185022)
@@ -30,12 +30,38 @@
 
 namespace JSC {
 
-struct HandlerInfo {
+struct HandlerInfoBase {
     uint32_t start;
     uint32_t end;
     uint32_t target;
     uint32_t scopeDepth;
+};
+
+struct UnlinkedHandlerInfo : public HandlerInfoBase {
+    UnlinkedHandlerInfo(uint32_t start, uint32_t end, uint32_t target, uint32_t scopeDepth)
+    {
+        this->start = start;
+        this->end = end;
+        this->target = target;
+        this->scopeDepth = scopeDepth;
+    }
+};
+
+struct HandlerInfo : public HandlerInfoBase {
+    void initialize(const UnlinkedHandlerInfo& unlinkedInfo, size_t nonLocalScopeDepth, CodeLocationLabel label)
+    {
+        start = unlinkedInfo.start;
+        end = unlinkedInfo.end;
+        target = unlinkedInfo.target;
+        scopeDepth = unlinkedInfo.scopeDepth + nonLocalScopeDepth;
 #if ENABLE(JIT)
+        nativeCode = label;
+#else
+        UNUSED_PARAM(label);
+#endif
+    }
+
+#if ENABLE(JIT)
     CodeLocationLabel nativeCode;
 #endif
 };

Modified: trunk/Source/_javascript_Core/bytecode/UnlinkedCodeBlock.h (185021 => 185022)


--- trunk/Source/_javascript_Core/bytecode/UnlinkedCodeBlock.h	2015-05-30 00:11:48 UTC (rev 185021)
+++ trunk/Source/_javascript_Core/bytecode/UnlinkedCodeBlock.h	2015-05-30 00:19:01 UTC (rev 185022)
@@ -30,6 +30,7 @@
 #include "CodeSpecializationKind.h"
 #include "CodeType.h"
 #include "ExpressionRangeInfo.h"
+#include "HandlerInfo.h"
 #include "Identifier.h"
 #include "JSCell.h"
 #include "JSString.h"
@@ -246,13 +247,6 @@
     }
 };
 
-struct UnlinkedHandlerInfo {
-    uint32_t start;
-    uint32_t end;
-    uint32_t target;
-    uint32_t scopeDepth;
-};
-
 struct UnlinkedInstruction {
     UnlinkedInstruction() { u.operand = 0; }
     UnlinkedInstruction(OpcodeID opcode) { u.opcode = opcode; }
@@ -427,7 +421,7 @@
 
     // Exception handling support
     size_t numberOfExceptionHandlers() const { return m_rareData ? m_rareData->m_exceptionHandlers.size() : 0; }
-    void addExceptionHandler(const UnlinkedHandlerInfo& hanler) { createRareDataIfNecessary(); return m_rareData->m_exceptionHandlers.append(hanler); }
+    void addExceptionHandler(const UnlinkedHandlerInfo& handler) { createRareDataIfNecessary(); return m_rareData->m_exceptionHandlers.append(handler); }
     UnlinkedHandlerInfo& exceptionHandler(int index) { ASSERT(m_rareData); return m_rareData->m_exceptionHandlers[index]; }
 
     SymbolTable* symbolTable() const { return m_symbolTable.get(); }

Modified: trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.cpp (185021 => 185022)


--- trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.cpp	2015-05-30 00:11:48 UTC (rev 185021)
+++ trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.cpp	2015-05-30 00:19:01 UTC (rev 185022)
@@ -129,11 +129,8 @@
             continue;
         
         ASSERT(range.tryData->targetScopeDepth != UINT_MAX);
-        UnlinkedHandlerInfo info = {
-            static_cast<uint32_t>(start), static_cast<uint32_t>(end),
-            static_cast<uint32_t>(range.tryData->target->bind()),
-            range.tryData->targetScopeDepth
-        };
+        UnlinkedHandlerInfo info(static_cast<uint32_t>(start), static_cast<uint32_t>(end),
+            static_cast<uint32_t>(range.tryData->target->bind()), range.tryData->targetScopeDepth);
         m_codeBlock->addExceptionHandler(info);
     }
     
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to