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

Changeset 113136 in webkit


Ignore:
Timestamp:
Apr 3, 2012, 9:25:56 PM (14 years ago)
Author:
fpizlo@apple.com
Message:

jsr/sret should be removed
https://bugs.webkit.org/show_bug.cgi?id=82986
<rdar://problem/11017015>

Reviewed by Sam Weinig and Geoff Garen.

Replaces jsr/sret with finally block inlining.

  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::dump):

  • bytecode/Opcode.h:

(JSC):
(JSC::padOpcodeName):

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::pushFinallyContext):
(JSC::BytecodeGenerator::emitComplexJumpScopes):
(JSC):

  • bytecompiler/BytecodeGenerator.h:

(FinallyContext):
(BytecodeGenerator):

  • bytecompiler/NodesCodegen.cpp:

(JSC::TryNode::emitBytecode):

  • interpreter/Interpreter.cpp:

(JSC::Interpreter::privateExecute):

  • jit/JIT.cpp:

(JSC::JIT::privateCompileMainPass):
(JSC::JIT::privateCompile):

  • jit/JIT.h:

(JIT):

  • jit/JITOpcodes.cpp:

(JSC):

  • jit/JITOpcodes32_64.cpp:

(JSC):

  • llint/LowLevelInterpreter32_64.asm:
  • llint/LowLevelInterpreter64.asm:
Location:
trunk/Source/JavaScriptCore
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r113126 r113136  
     12012-04-02  Filip Pizlo  <fpizlo@apple.com>
     2
     3        jsr/sret should be removed
     4        https://bugs.webkit.org/show_bug.cgi?id=82986
     5        <rdar://problem/11017015>
     6
     7        Reviewed by Sam Weinig and Geoff Garen.
     8       
     9        Replaces jsr/sret with finally block inlining.
     10
     11        * bytecode/CodeBlock.cpp:
     12        (JSC::CodeBlock::dump):
     13        * bytecode/Opcode.h:
     14        (JSC):
     15        (JSC::padOpcodeName):
     16        * bytecompiler/BytecodeGenerator.cpp:
     17        (JSC::BytecodeGenerator::pushFinallyContext):
     18        (JSC::BytecodeGenerator::emitComplexJumpScopes):
     19        (JSC):
     20        * bytecompiler/BytecodeGenerator.h:
     21        (FinallyContext):
     22        (BytecodeGenerator):
     23        * bytecompiler/NodesCodegen.cpp:
     24        (JSC::TryNode::emitBytecode):
     25        * interpreter/Interpreter.cpp:
     26        (JSC::Interpreter::privateExecute):
     27        * jit/JIT.cpp:
     28        (JSC::JIT::privateCompileMainPass):
     29        (JSC::JIT::privateCompile):
     30        * jit/JIT.h:
     31        (JIT):
     32        * jit/JITOpcodes.cpp:
     33        (JSC):
     34        * jit/JITOpcodes32_64.cpp:
     35        (JSC):
     36        * llint/LowLevelInterpreter32_64.asm:
     37        * llint/LowLevelInterpreter64.asm:
     38
    1392012-04-03  Mark Rowe  <mrowe@apple.com>
    240
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.cpp

    r111264 r113136  
    12471247            int k0 = (++it)->u.operand;
    12481248            dataLog("[%4d] throw_reference_error\t %s\n", location, constantName(exec, k0, getConstant(k0)).data());
    1249             break;
    1250         }
    1251         case op_jsr: {
    1252             int retAddrDst = (++it)->u.operand;
    1253             int offset = (++it)->u.operand;
    1254             dataLog("[%4d] jsr\t\t %s, %d(->%d)\n", location, registerName(exec, retAddrDst).data(), offset, location + offset);
    1255             break;
    1256         }
    1257         case op_sret: {
    1258             int retAddrSrc = (++it)->u.operand;
    1259             dataLog("[%4d] sret\t\t %s\n", location, registerName(exec, retAddrSrc).data());
    12601249            break;
    12611250        }
  • trunk/Source/JavaScriptCore/bytecode/Opcode.h

    r109007 r113136  
    190190        macro(op_throw_reference_error, 2) \
    191191        \
    192         macro(op_jsr, 3) \
    193         macro(op_sret, 2) \
    194         \
    195192        macro(op_debug, 4) \
    196193        macro(op_profile_will_call, 2) \
  • trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp

    r112555 r113136  
    11/*
    2  * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
     2 * Copyright (C) 2008, 2009, 2012 Apple Inc. All rights reserved.
    33 * Copyright (C) 2008 Cameron Zwarich <cwzwarich@uwaterloo.ca>
    44 * Copyright (C) 2012 Igalia, S.L.
     
    20052005}
    20062006
    2007 void BytecodeGenerator::pushFinallyContext(Label* target, RegisterID* retAddrDst)
     2007void BytecodeGenerator::pushFinallyContext(StatementNode* finallyBlock)
    20082008{
    20092009    ControlFlowContext scope;
    20102010    scope.isFinallyBlock = true;
    2011     FinallyContext context = { target, retAddrDst };
     2011    FinallyContext context = {
     2012        finallyBlock,
     2013        m_scopeContextStack.size(),
     2014        m_switchContextStack.size(),
     2015        m_forInContextStack.size(),
     2016        m_labelScopes.size(),
     2017        m_finallyDepth,
     2018        m_dynamicScopeDepth
     2019    };
    20122020    scope.finallyContext = context;
    20132021    m_scopeContextStack.append(scope);
     
    21352143            emitLabel(nextInsn.get());
    21362144        }
    2137 
     2145       
     2146        Vector<ControlFlowContext> savedScopeContextStack;
     2147        Vector<SwitchInfo> savedSwitchContextStack;
     2148        Vector<ForInContext> savedForInContextStack;
     2149        SegmentedVector<LabelScope, 8> savedLabelScopes;
    21382150        while (topScope > bottomScope && topScope->isFinallyBlock) {
    2139             emitJumpSubroutine(topScope->finallyContext.retAddrDst, topScope->finallyContext.finallyAddr);
     2151            // Save the current state of the world while instating the state of the world
     2152            // for the finally block.
     2153            FinallyContext finallyContext = topScope->finallyContext;
     2154            bool flipScopes = finallyContext.scopeContextStackSize != m_scopeContextStack.size();
     2155            bool flipSwitches = finallyContext.switchContextStackSize != m_switchContextStack.size();
     2156            bool flipForIns = finallyContext.forInContextStackSize != m_forInContextStack.size();
     2157            bool flipLabelScopes = finallyContext.labelScopesSize != m_labelScopes.size();
     2158            int topScopeIndex = -1;
     2159            int bottomScopeIndex = -1;
     2160            if (flipScopes) {
     2161                topScopeIndex = topScope - m_scopeContextStack.begin();
     2162                bottomScopeIndex = bottomScope - m_scopeContextStack.begin();
     2163                savedScopeContextStack = m_scopeContextStack;
     2164                m_scopeContextStack.shrink(finallyContext.scopeContextStackSize);
     2165            }
     2166            if (flipSwitches) {
     2167                savedSwitchContextStack = m_switchContextStack;
     2168                m_switchContextStack.shrink(finallyContext.switchContextStackSize);
     2169            }
     2170            if (flipForIns) {
     2171                savedForInContextStack = m_forInContextStack;
     2172                m_forInContextStack.shrink(finallyContext.forInContextStackSize);
     2173            }
     2174            if (flipLabelScopes) {
     2175                savedLabelScopes = m_labelScopes;
     2176                while (m_labelScopes.size() > finallyContext.labelScopesSize)
     2177                    m_labelScopes.removeLast();
     2178            }
     2179            int savedFinallyDepth = m_finallyDepth;
     2180            m_finallyDepth = finallyContext.finallyDepth;
     2181            int savedDynamicScopeDepth = m_dynamicScopeDepth;
     2182            m_dynamicScopeDepth = finallyContext.dynamicScopeDepth;
     2183           
     2184            // Emit the finally block.
     2185            emitNode(finallyContext.finallyBlock);
     2186           
     2187            // Restore the state of the world.
     2188            if (flipScopes) {
     2189                m_scopeContextStack = savedScopeContextStack;
     2190                topScope = &m_scopeContextStack[topScopeIndex]; // assert it's within bounds
     2191                bottomScope = m_scopeContextStack.begin() + bottomScopeIndex; // don't assert, since it the index might be -1.
     2192            }
     2193            if (flipSwitches)
     2194                m_switchContextStack = savedSwitchContextStack;
     2195            if (flipForIns)
     2196                m_forInContextStack = savedForInContextStack;
     2197            if (flipLabelScopes)
     2198                m_labelScopes = savedLabelScopes;
     2199            m_finallyDepth = savedFinallyDepth;
     2200            m_dynamicScopeDepth = savedDynamicScopeDepth;
     2201           
    21402202            --topScope;
    21412203        }
     
    22152277    emitOpcode(op_throw_reference_error);
    22162278    instructions().append(addConstantValue(jsString(globalData(), message))->index());
    2217 }
    2218 
    2219 PassRefPtr<Label> BytecodeGenerator::emitJumpSubroutine(RegisterID* retAddrDst, Label* finally)
    2220 {
    2221     size_t begin = instructions().size();
    2222 
    2223     emitOpcode(op_jsr);
    2224     instructions().append(retAddrDst->index());
    2225     instructions().append(finally->bind(begin, instructions().size()));
    2226     emitLabel(newLabel().get()); // Record the fact that the next instruction is implicitly labeled, because op_sret will return to it.
    2227     return finally;
    2228 }
    2229 
    2230 void BytecodeGenerator::emitSubroutineReturn(RegisterID* retAddrSrc)
    2231 {
    2232     emitOpcode(op_sret);
    2233     instructions().append(retAddrSrc->index());
    22342279}
    22352280
  • trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h

    r110033 r113136  
    11/*
    2  * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
     2 * Copyright (C) 2008, 2009, 2012 Apple Inc. All rights reserved.
    33 * Copyright (C) 2008 Cameron Zwarich <cwzwarich@uwaterloo.ca>
    44 * Copyright (C) 2012 Igalia, S.L.
     
    7272
    7373    struct FinallyContext {
    74         Label* finallyAddr;
    75         RegisterID* retAddrDst;
     74        StatementNode* finallyBlock;
     75        unsigned scopeContextStackSize;
     76        unsigned switchContextStackSize;
     77        unsigned forInContextStackSize;
     78        unsigned labelScopesSize;
     79        int finallyDepth;
     80        int dynamicScopeDepth;
    7681    };
    7782
     
    480485        PassRefPtr<Label> emitJumpScopes(Label* target, int targetScopeDepth);
    481486
    482         PassRefPtr<Label> emitJumpSubroutine(RegisterID* retAddrDst, Label*);
    483         void emitSubroutineReturn(RegisterID* retAddrSrc);
    484 
    485487        RegisterID* emitGetPropertyNames(RegisterID* dst, RegisterID* base, RegisterID* i, RegisterID* size, Label* breakTarget);
    486488        RegisterID* emitNextPropertyName(RegisterID* dst, RegisterID* base, RegisterID* i, RegisterID* size, RegisterID* iter, Label* target);
     
    505507        bool hasFinaliser() { return m_finallyDepth != 0; }
    506508
    507         void pushFinallyContext(Label* target, RegisterID* returnAddrDst);
     509        void pushFinallyContext(StatementNode* finallyBlock);
    508510        void popFinallyContext();
    509511
  • trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp

    r112555 r113136  
    22*  Copyright (C) 1999-2002 Harri Porten (porten@kde.org)
    33*  Copyright (C) 2001 Peter Kelly (pmk@post.com)
    4 *  Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
     4*  Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2012 Apple Inc. All rights reserved.
    55*  Copyright (C) 2007 Cameron Zwarich (cwzwarich@uwaterloo.ca)
    66*  Copyright (C) 2007 Maks Orlovich
     
    17281728    if (generator.scopeDepth()) {
    17291729        RefPtr<Label> l0 = generator.newLabel();
    1730         if (generator.hasFinaliser() && !r0->isTemporary()) {
     1730        if (generator.hasFinaliser()) {
    17311731            returnRegister = generator.emitMove(generator.newTemporary(), r0);
    17321732            r0 = returnRegister.get();
     
    19581958
    19591959    RefPtr<Label> tryStartLabel = generator.newLabel();
    1960     RefPtr<Label> finallyStart;
    1961     RefPtr<RegisterID> finallyReturnAddr;
    1962     if (m_finallyBlock) {
    1963         finallyStart = generator.newLabel();
    1964         finallyReturnAddr = generator.newTemporary();
    1965         generator.pushFinallyContext(finallyStart.get(), finallyReturnAddr.get());
    1966     }
     1960    if (m_finallyBlock)
     1961        generator.pushFinallyContext(m_finallyBlock);
    19671962
    19681963    generator.emitLabel(tryStartLabel.get());
     
    19861981    if (m_finallyBlock) {
    19871982        generator.popFinallyContext();
    1988         // there may be important registers live at the time we jump
    1989         // to a finally block (such as for a return or throw) so we
    1990         // ref the highest register ever used as a conservative
    1991         // approach to not clobbering anything important
    1992         RefPtr<RegisterID> highestUsedRegister = generator.highestUsedRegister();
     1983
    19931984        RefPtr<Label> finallyEndLabel = generator.newLabel();
    19941985
    1995         // Normal path: invoke the finally block, then jump over it.
    1996         generator.emitJumpSubroutine(finallyReturnAddr.get(), finallyStart.get());
     1986        // Normal path: run the finally code, and jump to the end.
     1987        generator.emitNode(dst, m_finallyBlock);
    19971988        generator.emitJump(finallyEndLabel.get());
    19981989
     
    20001991        RefPtr<Label> here = generator.emitLabel(generator.newLabel().get());
    20011992        RefPtr<RegisterID> tempExceptionRegister = generator.emitCatch(generator.newTemporary(), tryStartLabel.get(), here.get());
    2002         generator.emitJumpSubroutine(finallyReturnAddr.get(), finallyStart.get());
     1993        generator.emitNode(dst, m_finallyBlock);
    20031994        generator.emitThrow(tempExceptionRegister.get());
    2004 
    2005         // The finally block.
    2006         generator.emitLabel(finallyStart.get());
    2007         generator.emitNode(dst, m_finallyBlock);
    2008         generator.emitSubroutineReturn(finallyReturnAddr.get());
    20091995
    20101996        generator.emitLabel(finallyEndLabel.get());
  • trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp

    r111739 r113136  
    51875187        NEXT_INSTRUCTION();
    51885188    }
    5189     DEFINE_OPCODE(op_jsr) {
    5190         /* jsr retAddrDst(r) target(offset)
    5191 
    5192            Places the address of the next instruction into the retAddrDst
    5193            register and jumps to offset target from the current instruction.
    5194         */
    5195         int retAddrDst = vPC[1].u.operand;
    5196         int target = vPC[2].u.operand;
    5197         callFrame->r(retAddrDst) = vPC + OPCODE_LENGTH(op_jsr);
    5198 
    5199         vPC += target;
    5200         NEXT_INSTRUCTION();
    5201     }
    5202     DEFINE_OPCODE(op_sret) {
    5203         /* sret retAddrSrc(r)
    5204 
    5205          Jumps to the address stored in the retAddrSrc register. This
    5206          differs from op_jmp because the target address is stored in a
    5207          register, not as an immediate.
    5208         */
    5209         int retAddrSrc = vPC[1].u.operand;
    5210         vPC = callFrame->r(retAddrSrc).vPC();
    5211         NEXT_INSTRUCTION();
    5212     }
    52135189    DEFINE_OPCODE(op_debug) {
    52145190        /* debug debugHookID(n) firstLine(n) lastLine(n)
  • trunk/Source/JavaScriptCore/jit/JIT.cpp

    r110122 r113136  
    284284        DEFINE_OP(op_jngreater)
    285285        DEFINE_OP(op_jngreatereq)
    286         DEFINE_OP(op_jsr)
    287286        DEFINE_OP(op_jtrue)
    288287        DEFINE_OP(op_loop)
     
    341340        DEFINE_OP(op_rshift)
    342341        DEFINE_OP(op_urshift)
    343         DEFINE_OP(op_sret)
    344342        DEFINE_OP(op_strcat)
    345343        DEFINE_OP(op_stricteq)
     
    666664    }
    667665
    668     // Link absolute addresses for jsr
    669     for (Vector<JSRInfo>::iterator iter = m_jsrSites.begin(); iter != m_jsrSites.end(); ++iter)
    670         patchBuffer.patch(iter->storeLocation, patchBuffer.locationOf(iter->target).executableAddress());
    671 
    672666    m_codeBlock->setNumberOfStructureStubInfos(m_propertyAccessCompilationInfo.size());
    673667    for (unsigned i = 0; i < m_propertyAccessCompilationInfo.size(); ++i) {
  • trunk/Source/JavaScriptCore/jit/JIT.h

    r112192 r113136  
    281281
    282282    private:
    283         struct JSRInfo {
    284             DataLabelPtr storeLocation;
    285             Label target;
    286 
    287             JSRInfo(DataLabelPtr storeLocation, Label targetLocation)
    288                 : storeLocation(storeLocation)
    289                 , target(targetLocation)
    290             {
    291             }
    292         };
    293 
    294283        JIT(JSGlobalData*, CodeBlock* = 0);
    295284
     
    830819        void emit_op_jngreater(Instruction*);
    831820        void emit_op_jngreatereq(Instruction*);
    832         void emit_op_jsr(Instruction*);
    833821        void emit_op_jtrue(Instruction*);
    834822        void emit_op_loop(Instruction*);
     
    884872        void emit_op_ret_object_or_this(Instruction*);
    885873        void emit_op_rshift(Instruction*);
    886         void emit_op_sret(Instruction*);
    887874        void emit_op_strcat(Instruction*);
    888875        void emit_op_stricteq(Instruction*);
     
    10671054
    10681055        unsigned m_bytecodeOffset;
    1069         Vector<JSRInfo> m_jsrSites;
    10701056        Vector<SlowCaseEntry> m_slowCases;
    10711057        Vector<SwitchRecord> m_switches;
  • trunk/Source/JavaScriptCore/jit/JITOpcodes.cpp

    r110122 r113136  
    743743}
    744744
    745 void JIT::emit_op_jsr(Instruction* currentInstruction)
    746 {
    747     int retAddrDst = currentInstruction[1].u.operand;
    748     int target = currentInstruction[2].u.operand;
    749     DataLabelPtr storeLocation = storePtrWithPatch(TrustedImmPtr(0), Address(callFrameRegister, sizeof(Register) * retAddrDst));
    750     addJump(jump(), target);
    751     m_jsrSites.append(JSRInfo(storeLocation, label()));
    752     killLastResultRegister();
    753 }
    754 
    755 void JIT::emit_op_sret(Instruction* currentInstruction)
    756 {
    757     jump(Address(callFrameRegister, sizeof(Register) * currentInstruction[1].u.operand));
    758     killLastResultRegister();
    759 }
    760 
    761745void JIT::emit_op_eq(Instruction* currentInstruction)
    762746{
  • trunk/Source/JavaScriptCore/jit/JITOpcodes32_64.cpp

    r111481 r113136  
    922922}
    923923
    924 void JIT::emit_op_jsr(Instruction* currentInstruction)
    925 {
    926     int retAddrDst = currentInstruction[1].u.operand;
    927     int target = currentInstruction[2].u.operand;
    928     DataLabelPtr storeLocation = storePtrWithPatch(TrustedImmPtr(0), Address(callFrameRegister, sizeof(Register) * retAddrDst));
    929     addJump(jump(), target);
    930     m_jsrSites.append(JSRInfo(storeLocation, label()));
    931 }
    932 
    933 void JIT::emit_op_sret(Instruction* currentInstruction)
    934 {
    935     jump(Address(callFrameRegister, sizeof(Register) * currentInstruction[1].u.operand));
    936 }
    937 
    938924void JIT::emit_op_eq(Instruction* currentInstruction)
    939925{
  • trunk/Source/JavaScriptCore/llint/LowLevelInterpreter32_64.asm

    r110383 r113136  
    15721572
    15731573
    1574 _llint_op_jsr:
    1575     traceExecution()
    1576     loadi 4[PC], t0
    1577     addi 3 * 4, PC, t1
    1578     storei t1, [cfr, t0, 8]
    1579     dispatchBranch(8[PC])
    1580 
    1581 
    1582 _llint_op_sret:
    1583     traceExecution()
    1584     loadi 4[PC], t0
    1585     loadp [cfr, t0, 8], PC
    1586     dispatch(0)
    1587 
    1588 
    15891574_llint_op_end:
    15901575    traceExecution()
  • trunk/Source/JavaScriptCore/llint/LowLevelInterpreter64.asm

    r111481 r113136  
    14301430
    14311431
    1432 _llint_op_jsr:
    1433     traceExecution()
    1434     loadis 8[PB, PC, 8], t0
    1435     addi 3, PC, t1
    1436     storei t1, [cfr, t0, 8]
    1437     dispatchInt(16[PB, PC, 8])
    1438 
    1439 
    1440 _llint_op_sret:
    1441     traceExecution()
    1442     loadis 8[PB, PC, 8], t0
    1443     loadi [cfr, t0, 8], PC
    1444     dispatch(0)
    1445 
    1446 
    14471432_llint_op_end:
    14481433    traceExecution()
Note: See TracChangeset for help on using the changeset viewer.