Changeset 234082 in webkit


Ignore:
Timestamp:
Jul 21, 2018 6:10:43 AM (6 years ago)
Author:
Yusuke Suzuki
Message:

[JSC] Use Function / ScopedLambda / RecursableLambda instead of std::function
https://bugs.webkit.org/show_bug.cgi?id=187472

Reviewed by Mark Lam.

Source/JavaScriptCore:

std::function allocates memory from standard malloc instead of bmalloc. Instead of
using that, we should use WTF::{Function,ScopedLambda,RecursableLambda}.

This patch attempts to replace std::function with the above WTF function types.
If the function's lifetime can be the same to the stack, we can use ScopedLambda, which
is really efficient. Otherwise, we should use WTF::Function.
For recurring use cases, we can use RecursableLambda.

  • assembler/MacroAssembler.cpp:

(JSC::stdFunctionCallback):
(JSC::MacroAssembler::probe):

  • assembler/MacroAssembler.h:
  • b3/air/AirDisassembler.cpp:

(JSC::B3::Air::Disassembler::dump):

  • b3/air/AirDisassembler.h:
  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::BytecodeGenerator):
(JSC::BytecodeGenerator::initializeDefaultParameterValuesAndSetupFunctionScopeStack):
(JSC::BytecodeGenerator::emitEnumeration):

  • bytecompiler/BytecodeGenerator.h:
  • bytecompiler/NodesCodegen.cpp:

(JSC::ArrayNode::emitBytecode):
(JSC::ApplyFunctionCallDotNode::emitBytecode):
(JSC::ForOfNode::emitBytecode):

  • dfg/DFGSpeculativeJIT.cpp:

(JSC::DFG::SpeculativeJIT::addSlowPathGeneratorLambda):
(JSC::DFG::SpeculativeJIT::compileMathIC):

  • dfg/DFGSpeculativeJIT.h:
  • dfg/DFGSpeculativeJIT64.cpp:

(JSC::DFG::SpeculativeJIT::compile):

  • dfg/DFGValidate.cpp:
  • ftl/FTLCompile.cpp:

(JSC::FTL::compile):

  • heap/HeapSnapshotBuilder.cpp:

(JSC::HeapSnapshotBuilder::json):

  • heap/HeapSnapshotBuilder.h:
  • interpreter/StackVisitor.cpp:

(JSC::StackVisitor::Frame::dump const):

  • interpreter/StackVisitor.h:
  • runtime/PromiseDeferredTimer.h:
  • runtime/VM.cpp:

(JSC::VM::whenIdle):
(JSC::enableProfilerWithRespectToCount):
(JSC::disableProfilerWithRespectToCount):

  • runtime/VM.h:
  • runtime/VMEntryScope.cpp:

(JSC::VMEntryScope::addDidPopListener):

  • runtime/VMEntryScope.h:
  • tools/HeapVerifier.cpp:

(JSC::HeapVerifier::verifyCellList):
(JSC::HeapVerifier::validateCell):
(JSC::HeapVerifier::validateJSCell):

  • tools/HeapVerifier.h:

Source/WTF:

  • wtf/ScopedLambda.h:

(WTF::ScopedLambda<ResultType):

Location:
trunk/Source
Files:
26 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r234075 r234082  
     12018-07-21  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        [JSC] Use Function / ScopedLambda / RecursableLambda instead of std::function
     4        https://bugs.webkit.org/show_bug.cgi?id=187472
     5
     6        Reviewed by Mark Lam.
     7
     8        std::function allocates memory from standard malloc instead of bmalloc. Instead of
     9        using that, we should use WTF::{Function,ScopedLambda,RecursableLambda}.
     10
     11        This patch attempts to replace std::function with the above WTF function types.
     12        If the function's lifetime can be the same to the stack, we can use ScopedLambda, which
     13        is really efficient. Otherwise, we should use WTF::Function.
     14        For recurring use cases, we can use RecursableLambda.
     15
     16        * assembler/MacroAssembler.cpp:
     17        (JSC::stdFunctionCallback):
     18        (JSC::MacroAssembler::probe):
     19        * assembler/MacroAssembler.h:
     20        * b3/air/AirDisassembler.cpp:
     21        (JSC::B3::Air::Disassembler::dump):
     22        * b3/air/AirDisassembler.h:
     23        * bytecompiler/BytecodeGenerator.cpp:
     24        (JSC::BytecodeGenerator::BytecodeGenerator):
     25        (JSC::BytecodeGenerator::initializeDefaultParameterValuesAndSetupFunctionScopeStack):
     26        (JSC::BytecodeGenerator::emitEnumeration):
     27        * bytecompiler/BytecodeGenerator.h:
     28        * bytecompiler/NodesCodegen.cpp:
     29        (JSC::ArrayNode::emitBytecode):
     30        (JSC::ApplyFunctionCallDotNode::emitBytecode):
     31        (JSC::ForOfNode::emitBytecode):
     32        * dfg/DFGSpeculativeJIT.cpp:
     33        (JSC::DFG::SpeculativeJIT::addSlowPathGeneratorLambda):
     34        (JSC::DFG::SpeculativeJIT::compileMathIC):
     35        * dfg/DFGSpeculativeJIT.h:
     36        * dfg/DFGSpeculativeJIT64.cpp:
     37        (JSC::DFG::SpeculativeJIT::compile):
     38        * dfg/DFGValidate.cpp:
     39        * ftl/FTLCompile.cpp:
     40        (JSC::FTL::compile):
     41        * heap/HeapSnapshotBuilder.cpp:
     42        (JSC::HeapSnapshotBuilder::json):
     43        * heap/HeapSnapshotBuilder.h:
     44        * interpreter/StackVisitor.cpp:
     45        (JSC::StackVisitor::Frame::dump const):
     46        * interpreter/StackVisitor.h:
     47        * runtime/PromiseDeferredTimer.h:
     48        * runtime/VM.cpp:
     49        (JSC::VM::whenIdle):
     50        (JSC::enableProfilerWithRespectToCount):
     51        (JSC::disableProfilerWithRespectToCount):
     52        * runtime/VM.h:
     53        * runtime/VMEntryScope.cpp:
     54        (JSC::VMEntryScope::addDidPopListener):
     55        * runtime/VMEntryScope.h:
     56        * tools/HeapVerifier.cpp:
     57        (JSC::HeapVerifier::verifyCellList):
     58        (JSC::HeapVerifier::validateCell):
     59        (JSC::HeapVerifier::validateJSCell):
     60        * tools/HeapVerifier.h:
     61
    1622018-07-20  Michael Saboff  <msaboff@apple.com>
    263
  • trunk/Source/JavaScriptCore/assembler/MacroAssembler.cpp

    r229969 r234082  
    5454static void stdFunctionCallback(Probe::Context& context)
    5555{
    56     auto func = context.arg<const std::function<void(Probe::Context&)>*>();
     56    auto func = context.arg<const Function<void(Probe::Context&)>*>();
    5757    (*func)(context);
    5858}
    5959   
    60 void MacroAssembler::probe(std::function<void(Probe::Context&)> func)
     60void MacroAssembler::probe(Function<void(Probe::Context&)> func)
    6161{
    62     probe(stdFunctionCallback, new std::function<void(Probe::Context&)>(func));
     62    probe(stdFunctionCallback, new Function<void(Probe::Context&)>(WTFMove(func)));
    6363}
    6464#endif // ENABLE(MASM_PROBE)
  • trunk/Source/JavaScriptCore/assembler/MacroAssembler.h

    r231290 r234082  
    19551955    void probe(Probe::Function, void* arg);
    19561956
    1957     JS_EXPORT_PRIVATE void probe(std::function<void(Probe::Context&)>);
     1957    JS_EXPORT_PRIVATE void probe(Function<void(Probe::Context&)>);
    19581958
    19591959    // Let's you print from your JIT generated code.
  • trunk/Source/JavaScriptCore/b3/air/AirDisassembler.cpp

    r230748 r234082  
    7070}
    7171
    72 void Disassembler::dump(Code& code, PrintStream& out, LinkBuffer& linkBuffer, const char* airPrefix, const char* asmPrefix, std::function<void(Inst&)> doToEachInst)
     72void Disassembler::dump(Code& code, PrintStream& out, LinkBuffer& linkBuffer, const char* airPrefix, const char* asmPrefix, const ScopedLambda<void(Inst&)>& doToEachInst)
    7373{
    7474    auto dumpAsmRange = [&] (CCallHelpers::Label startLabel, CCallHelpers::Label endLabel) {
  • trunk/Source/JavaScriptCore/b3/air/AirDisassembler.h

    r213233 r234082  
    5151    void addInst(Inst*, CCallHelpers::Label, CCallHelpers::Label);
    5252
    53     void dump(Code&, PrintStream&, LinkBuffer&, const char* airPrefix, const char* asmPrefix, std::function<void(Inst&)> doToEachInst);
     53    void dump(Code&, PrintStream&, LinkBuffer&, const char* airPrefix, const char* asmPrefix, const ScopedLambda<void(Inst&)>& doToEachInst);
    5454
    5555private:
  • trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp

    r233855 r234082  
    341341        functionNode->varDeclarations().markAllVariablesAsCaptured();
    342342   
    343     auto captures = [&] (UniquedStringImpl* uid) -> bool {
     343    auto captures = scopedLambda<bool (UniquedStringImpl*)>([&] (UniquedStringImpl* uid) -> bool {
    344344        if (!shouldCaptureSomeOfTheThings)
    345345            return false;
     
    352352        }
    353353        return functionNode->captures(uid);
    354     };
     354    });
    355355    auto varKind = [&] (UniquedStringImpl* uid) -> VarKind {
    356356        return captures(uid) ? VarKind::Scope : VarKind::Stack;
     
    976976void BytecodeGenerator::initializeDefaultParameterValuesAndSetupFunctionScopeStack(
    977977    FunctionParameters& parameters, bool isSimpleParameterList, FunctionNode* functionNode, SymbolTable* functionSymbolTable,
    978     int symbolTableConstantIndex, const std::function<bool (UniquedStringImpl*)>& captures, bool shouldCreateArgumentsVariableInParameterScope)
     978    int symbolTableConstantIndex, const ScopedLambda<bool (UniquedStringImpl*)>& captures, bool shouldCreateArgumentsVariableInParameterScope)
    979979{
    980980    Vector<std::pair<Identifier, RefPtr<RegisterID>>> valuesToMoveIntoVars;
     
    42904290}
    42914291
    4292 void BytecodeGenerator::emitEnumeration(ThrowableExpressionData* node, ExpressionNode* subjectNode, const std::function<void(BytecodeGenerator&, RegisterID*)>& callBack, ForOfNode* forLoopNode, RegisterID* forLoopSymbolTable)
     4292void BytecodeGenerator::emitEnumeration(ThrowableExpressionData* node, ExpressionNode* subjectNode, const ScopedLambda<void(BytecodeGenerator&, RegisterID*)>& callBack, ForOfNode* forLoopNode, RegisterID* forLoopSymbolTable)
    42934293{
    42944294    bool isForAwait = forLoopNode ? forLoopNode->isForAwait() : false;
  • trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h

    r233657 r234082  
    749749            RegisterID* valueRegister, RegisterID* getterRegister, RegisterID* setterRegister, unsigned options, const JSTextPosition&);
    750750
    751         void emitEnumeration(ThrowableExpressionData* enumerationNode, ExpressionNode* subjectNode, const std::function<void(BytecodeGenerator&, RegisterID*)>& callBack, ForOfNode* = nullptr, RegisterID* forLoopSymbolTable = nullptr);
     751        void emitEnumeration(ThrowableExpressionData* enumerationNode, ExpressionNode* subjectNode, const ScopedLambda<void(BytecodeGenerator&, RegisterID*)>& callBack, ForOfNode* = nullptr, RegisterID* forLoopSymbolTable = nullptr);
    752752
    753753        RegisterID* emitGetTemplateObject(RegisterID* dst, TaggedTemplateNode*);
     
    11101110        void initializeParameters(FunctionParameters&);
    11111111        void initializeVarLexicalEnvironment(int symbolTableConstantIndex, SymbolTable* functionSymbolTable, bool hasCapturedVariables);
    1112         void initializeDefaultParameterValuesAndSetupFunctionScopeStack(FunctionParameters&, bool isSimpleParameterList, FunctionNode*, SymbolTable*, int symbolTableConstantIndex, const std::function<bool (UniquedStringImpl*)>& captures, bool shouldCreateArgumentsVariableInParameterScope);
     1112        void initializeDefaultParameterValuesAndSetupFunctionScopeStack(FunctionParameters&, bool isSimpleParameterList, FunctionNode*, SymbolTable*, int symbolTableConstantIndex, const ScopedLambda<bool (UniquedStringImpl*)>& captures, bool shouldCreateArgumentsVariableInParameterScope);
    11131113        void initializeArrowFunctionContextScopeIfNeeded(SymbolTable* functionSymbolTable = nullptr, bool canReuseLexicalEnvironment = false);
    11141114        bool needsDerivedConstructorInArrowFunctionLexicalEnvironment();
  • trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp

    r233855 r234082  
    458458handleSpread:
    459459    RefPtr<RegisterID> index = generator.emitLoad(generator.newTemporary(), jsNumber(length));
    460     auto spreader = [array, index](BytecodeGenerator& generator, RegisterID* value)
     460    auto spreader = scopedLambda<void(BytecodeGenerator&, RegisterID*)>([array, index](BytecodeGenerator& generator, RegisterID* value)
    461461    {
    462462        generator.emitDirectPutByVal(array.get(), index.get(), value);
    463463        generator.emitInc(index.get());
    464     };
     464    });
    465465    for (; n; n = n->next()) {
    466466        if (n->elision())
     
    14561456                RefPtr<RegisterID> argumentsRegister = generator.emitLoad(generator.newTemporary(), jsUndefined());
    14571457               
    1458                 auto extractor = [&thisRegister, &argumentsRegister, &index](BytecodeGenerator& generator, RegisterID* value)
     1458                auto extractor = scopedLambda<void(BytecodeGenerator&, RegisterID*)>([&thisRegister, &argumentsRegister, &index](BytecodeGenerator& generator, RegisterID* value)
    14591459                {
    14601460                    Ref<Label> haveThis = generator.newLabel();
     
    14721472                    generator.emitLoad(index.get(), jsNumber(2));
    14731473                    generator.emitLabel(end.get());
    1474                 };
     1474                });
    14751475                generator.emitEnumeration(this, spread->expression(), extractor);
    14761476                generator.emitCallVarargsInTailPosition(returnValue.get(), realFunction.get(), thisRegister.get(), argumentsRegister.get(), generator.newTemporary(), 0, divot(), divotStart(), divotEnd(), DebuggableCall::Yes);
     
    32173217    RegisterID* forLoopSymbolTable = nullptr;
    32183218    generator.pushLexicalScope(this, BytecodeGenerator::TDZCheckOptimization::Optimize, BytecodeGenerator::NestedScopeType::IsNested, &forLoopSymbolTable);
    3219     auto extractor = [this, dst](BytecodeGenerator& generator, RegisterID* value)
     3219    auto extractor = scopedLambda<void(BytecodeGenerator&, RegisterID*)>([this, dst](BytecodeGenerator& generator, RegisterID* value)
    32203220    {
    32213221        if (m_lexpr->isResolveNode()) {
     
    32683268        generator.emitProfileControlFlow(m_statement->startOffset());
    32693269        generator.emitNode(dst, m_statement);
    3270     };
     3270    });
    32713271    generator.emitEnumeration(this, m_expr, extractor, this, forLoopSymbolTable);
    32723272    generator.popLexicalScope(this);
  • trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp

    r234060 r234082  
    389389}
    390390
    391 void SpeculativeJIT::addSlowPathGenerator(std::function<void()> lambda)
    392 {
    393     m_slowPathLambdas.append(SlowPathLambda{ lambda, m_currentNode, static_cast<unsigned>(m_stream->size()) });
     391void SpeculativeJIT::addSlowPathGeneratorLambda(Function<void()>&& lambda)
     392{
     393    m_slowPathLambdas.append(SlowPathLambda{ WTFMove(lambda), m_currentNode, static_cast<unsigned>(m_stream->size()) });
    394394}
    395395
     
    39013901        auto done = m_jit.label();
    39023902
    3903         addSlowPathGenerator([=, savePlans = WTFMove(savePlans)] () {
     3903        addSlowPathGeneratorLambda([=, savePlans = WTFMove(savePlans)] () {
    39043904            addICGenerationState->slowPathJumps.link(&m_jit);
    39053905            addICGenerationState->slowPathStart = m_jit.label();
     
    46094609        auto done = m_jit.label();
    46104610
    4611         addSlowPathGenerator([=, savePlans = WTFMove(savePlans)] () {
     4611        addSlowPathGeneratorLambda([=, savePlans = WTFMove(savePlans)] () {
    46124612            icGenerationState->slowPathJumps.link(&m_jit);
    46134613            icGenerationState->slowPathStart = m_jit.label();
  • trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h

    r232461 r234082  
    357357
    358358    void addSlowPathGenerator(std::unique_ptr<SlowPathGenerator>);
    359     void addSlowPathGenerator(std::function<void()>);
     359    void addSlowPathGeneratorLambda(Function<void()>&&);
    360360    void runSlowPathGenerators(PCToCodeOriginMapBuilder&);
    361361   
     
    17211721    Vector<std::unique_ptr<SlowPathGenerator>, 8> m_slowPathGenerators;
    17221722    struct SlowPathLambda {
    1723         std::function<void()> generator;
     1723        Function<void()> generator;
    17241724        Node* currentNode;
    17251725        unsigned streamIndex;
  • trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp

    r232461 r234082  
    45664566        unsigned bytecodeIndex = node->origin.semantic.bytecodeIndex;
    45674567
    4568         addSlowPathGenerator([=]() {
     4568        addSlowPathGeneratorLambda([=]() {
    45694569            callTierUp.link(&m_jit);
    45704570
     
    46184618        m_jit.jitCode()->bytecodeIndexToStreamIndex.add(bytecodeIndex, streamIndex);
    46194619
    4620         addSlowPathGenerator([=]() {
     4620        addSlowPathGeneratorLambda([=]() {
    46214621            forceOSREntry.link(&m_jit);
    46224622            overflowedCounter.link(&m_jit);
  • trunk/Source/JavaScriptCore/dfg/DFGValidate.cpp

    r232741 r234082  
    378378        // Validate clobbered states.
    379379        struct DefLambdaAdaptor {
    380             std::function<void(PureValue)> pureValue;
    381             std::function<void(HeapLocation, LazyNode)> locationAndNode;
     380            Function<void(PureValue)> pureValue;
     381            Function<void(HeapLocation, LazyNode)> locationAndNode;
    382382
    383383            void operator()(PureValue value) const
  • trunk/Source/JavaScriptCore/ftl/FTLCompile.cpp

    r230748 r234082  
    4949#include "PCToCodeOriginMap.h"
    5050#include "ScratchRegisterAllocator.h"
    51 #include <wtf/Function.h>
     51#include <wtf/RecursableLambda.h>
    5252
    5353namespace JSC { namespace FTL {
     
    216216
    217217            HashSet<B3::Value*> localPrintedValues;
    218             WTF::Function<void(B3::Value*)> printValueRecursive = [&] (B3::Value* value) {
     218            auto printValueRecursive = recursableLambda([&] (auto self, B3::Value* value) -> void {
    219219                if (printedValues.contains(value) || localPrintedValues.contains(value))
    220220                    return;
     
    222222                localPrintedValues.add(value);
    223223                for (unsigned i = 0; i < value->numChildren(); i++)
    224                     printValueRecursive(value->child(i));
     224                    self(value->child(i));
    225225                out.print(b3Prefix);
    226226                value->deepDump(state.proc.get(), out);
    227227                out.print("\n");
    228             };
     228            });
    229229
    230230            printValueRecursive(currentB3Value);
     
    232232        };
    233233
    234         auto forEachInst = [&] (B3::Air::Inst& inst) {
     234        auto forEachInst = scopedLambda<void(B3::Air::Inst&)>([&] (B3::Air::Inst& inst) {
    235235            printB3Value(inst.origin);
    236         };
     236        });
    237237
    238238        disassembler->dump(state.proc->code(), out, linkBuffer, airPrefix, asmPrefix, forEachInst);
  • trunk/Source/JavaScriptCore/heap/HeapSnapshotBuilder.cpp

    r233765 r234082  
    200200}
    201201
    202 String HeapSnapshotBuilder::json(std::function<bool (const HeapSnapshotNode&)> allowNodeCallback)
     202String HeapSnapshotBuilder::json(Function<bool (const HeapSnapshotNode&)> allowNodeCallback)
    203203{
    204204    VM& vm = m_profiler.vm();
  • trunk/Source/JavaScriptCore/heap/HeapSnapshotBuilder.h

    r217843 r234082  
    122122
    123123    String json();
    124     String json(std::function<bool (const HeapSnapshotNode&)> allowNodeCallback);
     124    String json(Function<bool (const HeapSnapshotNode&)> allowNodeCallback);
    125125
    126126private:
  • trunk/Source/JavaScriptCore/interpreter/StackVisitor.cpp

    r233122 r234082  
    427427}
    428428
    429 void StackVisitor::Frame::dump(PrintStream& out, Indenter indent, std::function<void(PrintStream&)> prefix) const
     429void StackVisitor::Frame::dump(PrintStream& out, Indenter indent, WTF::Function<void(PrintStream&)> prefix) const
    430430{
    431431    if (!this->callFrame()) {
  • trunk/Source/JavaScriptCore/interpreter/StackVisitor.h

    r224272 r234082  
    2929#include "VMEntryRecord.h"
    3030#include "WasmIndexOrName.h"
    31 #include <functional>
     31#include <wtf/Function.h>
    3232#include <wtf/Indenter.h>
    3333#include <wtf/text/WTFString.h>
     
    101101       
    102102        void dump(PrintStream&, Indenter = Indenter()) const;
    103         void dump(PrintStream&, Indenter, std::function<void(PrintStream&)> prefix) const;
     103        void dump(PrintStream&, Indenter, WTF::Function<void(PrintStream&)> prefix) const;
    104104
    105105    private:
  • trunk/Source/JavaScriptCore/runtime/PromiseDeferredTimer.h

    r231194 r234082  
    5353    bool cancelPendingPromise(JSPromiseDeferred*);
    5454
    55     typedef std::function<void()> Task;
     55    using Task = Function<void()>;
    5656    void scheduleWorkSoon(JSPromiseDeferred*, Task&&);
    5757
  • trunk/Source/JavaScriptCore/runtime/VM.cpp

    r233236 r234082  
    754754}
    755755
    756 void VM::whenIdle(std::function<void()> callback)
     756void VM::whenIdle(Function<void()>&& callback)
    757757{
    758758    if (!entryScope) {
     
    761761    }
    762762
    763     entryScope->addDidPopListener(callback);
     763    entryScope->addDidPopListener(WTFMove(callback));
    764764}
    765765
     
    10241024}
    10251025
    1026 static bool enableProfilerWithRespectToCount(unsigned& counter, std::function<void()> doEnableWork)
     1026template<typename Func>
     1027static bool enableProfilerWithRespectToCount(unsigned& counter, const Func& doEnableWork)
    10271028{
    10281029    bool needsToRecompile = false;
     
    10361037}
    10371038
    1038 static bool disableProfilerWithRespectToCount(unsigned& counter, std::function<void()> doDisableWork)
     1039template<typename Func>
     1040static bool disableProfilerWithRespectToCount(unsigned& counter, const Func& doDisableWork)
    10391041{
    10401042    RELEASE_ASSERT(counter > 0);
  • trunk/Source/JavaScriptCore/runtime/VM.h

    r233236 r234082  
    797797    CodeCache* codeCache() { return m_codeCache.get(); }
    798798
    799     JS_EXPORT_PRIVATE void whenIdle(std::function<void()>);
     799    JS_EXPORT_PRIVATE void whenIdle(Function<void()>&&);
    800800
    801801    JS_EXPORT_PRIVATE void deleteAllCode(DeleteAllCodeEffort);
  • trunk/Source/JavaScriptCore/runtime/VMEntryScope.cpp

    r233378 r234082  
    6565}
    6666
    67 void VMEntryScope::addDidPopListener(std::function<void ()> listener)
     67void VMEntryScope::addDidPopListener(Function<void ()>&& listener)
    6868{
    69     m_didPopListeners.append(listener);
     69    m_didPopListeners.append(WTFMove(listener));
    7070}
    7171
  • trunk/Source/JavaScriptCore/runtime/VMEntryScope.h

    r232074 r234082  
    4242    JSGlobalObject* globalObject() const { return m_globalObject; }
    4343
    44     void addDidPopListener(std::function<void ()>);
     44    void addDidPopListener(Function<void ()>&&);
    4545
    4646private:
    4747    VM& m_vm;
    4848    JSGlobalObject* m_globalObject;
    49     Vector<std::function<void ()>> m_didPopListeners;
     49    Vector<Function<void ()>> m_didPopListeners;
    5050};
    5151
  • trunk/Source/JavaScriptCore/tools/HeapVerifier.cpp

    r233236 r234082  
    154154
    155155    bool listNamePrinted = false;
    156     auto printHeaderIfNeeded = [&] () {
     156    auto printHeaderIfNeeded = scopedLambda<void()>([&] () {
    157157        if (listNamePrinted)
    158158            return;
     
    162162        listNamePrinted = true;
    163163        m_didPrintLogs = true;
    164     };
     164    });
    165165   
    166166    bool success = true;
     
    182182bool HeapVerifier::validateCell(HeapCell* cell, VM* expectedVM)
    183183{
    184     auto printNothing = [] () { };
     184    auto printNothing = scopedLambda<void()>([] () { });
    185185
    186186    if (cell->isZapped()) {
     
    196196}
    197197
    198 bool HeapVerifier::validateJSCell(VM* expectedVM, JSCell* cell, CellProfile* profile, CellList* list, std::function<void()> printHeaderIfNeeded, const char* prefix)
    199 {
    200     auto printHeaderAndCell = [cell, profile, printHeaderIfNeeded, prefix] () {
     198bool HeapVerifier::validateJSCell(VM* expectedVM, JSCell* cell, CellProfile* profile, CellList* list, const ScopedLambda<void()>& printHeaderIfNeeded, const char* prefix)
     199{
     200    auto printHeaderAndCell = [cell, profile, &printHeaderIfNeeded, prefix] () {
    201201        printHeaderIfNeeded();
    202202        dataLog(prefix, "cell ", RawPointer(cell));
  • trunk/Source/JavaScriptCore/tools/HeapVerifier.h

    r229309 r234082  
    2929#include "Heap.h"
    3030#include <wtf/MonotonicTime.h>
     31#include <wtf/ScopedLambda.h>
    3132#include <wtf/UniqueArray.h>
    3233
     
    100101    CellList* cellListForGathering(Phase);
    101102    bool verifyCellList(Phase, CellList&);
    102     static bool validateJSCell(VM* expectedVM, JSCell*, CellProfile*, CellList*, std::function<void()> printHeaderIfNeeded, const char* prefix = "");
     103    static bool validateJSCell(VM* expectedVM, JSCell*, CellProfile*, CellList*, const ScopedLambda<void()>& printHeaderIfNeeded, const char* prefix = "");
    103104
    104105    void printVerificationHeader();
  • trunk/Source/WTF/ChangeLog

    r233912 r234082  
     12018-07-21  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        [JSC] Use Function / ScopedLambda / RecursableLambda instead of std::function
     4        https://bugs.webkit.org/show_bug.cgi?id=187472
     5
     6        Reviewed by Mark Lam.
     7
     8        * wtf/ScopedLambda.h:
     9        (WTF::ScopedLambda<ResultType):
     10
    1112018-07-18  Michael Catanzaro  <mcatanzaro@igalia.com>
    212
  • trunk/Source/WTF/wtf/ScopedLambda.h

    r225524 r234082  
    2727#define ScopedLambda_h
    2828
     29#include <wtf/ForbidHeapAllocation.h>
     30
    2931namespace WTF {
    3032
     
    4446template<typename ResultType, typename... ArgumentTypes>
    4547class ScopedLambda<ResultType (ArgumentTypes...)> {
     48    WTF_FORBID_HEAP_ALLOCATION;
    4649public:
    4750    ScopedLambda(ResultType (*impl)(void* arg, ArgumentTypes...) = nullptr, void* arg = nullptr)
Note: See TracChangeset for help on using the changeset viewer.