Skip to content

Commit

Permalink
[JSC] Avoid allocating heap Function for forEachDebugger
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=244741

Reviewed by Devin Rousso.

We should keep NativeExecutable creation cheap. This patch moves VM::forEachDebugger to
VMInlines, and avoid allocating heap data structure for Function.

* Source/JavaScriptCore/runtime/NativeExecutable.cpp:
* Source/JavaScriptCore/runtime/VM.cpp:
(JSC::VM::forEachDebugger): Deleted.
* Source/JavaScriptCore/runtime/VM.h:
* Source/JavaScriptCore/runtime/VMInlines.h:
(JSC::VM::forEachDebugger):

Canonical link: https://commits.webkit.org/254125@main
  • Loading branch information
Constellation committed Sep 3, 2022
1 parent 0ac614b commit 2d6f6e3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions Source/JavaScriptCore/runtime/NativeExecutable.cpp
Expand Up @@ -29,6 +29,7 @@
#include "Debugger.h"
#include "ExecutableBaseInlines.h"
#include "JSCInlines.h"
#include "VMInlines.h"

namespace JSC {

Expand Down
9 changes: 0 additions & 9 deletions Source/JavaScriptCore/runtime/VM.cpp
Expand Up @@ -1485,15 +1485,6 @@ void VM::removeDebugger(Debugger& debugger)
m_debuggers.remove(&debugger);
}

void VM::forEachDebugger(Function<void(Debugger&)>&& callback)
{
if (LIKELY(m_debuggers.isEmpty()))
return;

for (auto* debugger = m_debuggers.head(); debugger; debugger = debugger->next())
callback(*debugger);
}

void QueuedTask::run()
{
if (!m_job.isObject())
Expand Down
3 changes: 2 additions & 1 deletion Source/JavaScriptCore/runtime/VM.h
Expand Up @@ -904,7 +904,8 @@ class VM : public ThreadSafeRefCounted<VM>, public DoublyLinkedListNode<VM> {

void addDebugger(Debugger&);
void removeDebugger(Debugger&);
void forEachDebugger(Function<void(Debugger&)>&&);
template<typename Func>
void forEachDebugger(const Func&);

private:
VM(VMType, HeapType, WTF::RunLoop* = nullptr, bool* success = nullptr);
Expand Down
11 changes: 11 additions & 0 deletions Source/JavaScriptCore/runtime/VMInlines.h
Expand Up @@ -25,6 +25,7 @@

#pragma once

#include "Debugger.h"
#include "EntryFrame.h"
#include "FuzzerAgent.h"
#include "ProfilerDatabase.h"
Expand Down Expand Up @@ -97,4 +98,14 @@ inline void VM::setFuzzerAgent(std::unique_ptr<FuzzerAgent>&& fuzzerAgent)
m_fuzzerAgent = WTFMove(fuzzerAgent);
}

template<typename Func>
inline void VM::forEachDebugger(const Func& callback)
{
if (LIKELY(m_debuggers.isEmpty()))
return;

for (auto* debugger = m_debuggers.head(); debugger; debugger = debugger->next())
callback(*debugger);
}

} // namespace JSC

0 comments on commit 2d6f6e3

Please sign in to comment.