MachineStackMarker.h [plain text]
#pragma once
#include "RegisterState.h"
#include <wtf/Lock.h>
#include <wtf/ScopedLambda.h>
#include <wtf/ThreadGroup.h>
namespace JSC {
class CodeBlockSet;
class ConservativeRoots;
class Heap;
class JITStubRoutineSet;
struct CurrentThreadState {
void* stackOrigin { nullptr };
void* stackTop { nullptr };
RegisterState* registerState { nullptr };
};
class MachineThreads {
WTF_MAKE_FAST_ALLOCATED;
WTF_MAKE_NONCOPYABLE(MachineThreads);
public:
MachineThreads();
void gatherConservativeRoots(ConservativeRoots&, JITStubRoutineSet&, CodeBlockSet&, CurrentThreadState*, Thread*);
bool addCurrentThread() { return m_threadGroup->addCurrentThread() == ThreadGroupAddResult::NewlyAdded; }
WordLock& getLock() { return m_threadGroup->getLock(); }
const ListHashSet<Ref<Thread>>& threads(const AbstractLocker& locker) const { return m_threadGroup->threads(locker); }
private:
void gatherFromCurrentThread(ConservativeRoots&, JITStubRoutineSet&, CodeBlockSet&, CurrentThreadState&);
void tryCopyOtherThreadStack(Thread&, void*, size_t capacity, size_t*);
bool tryCopyOtherThreadStacks(const AbstractLocker&, void*, size_t capacity, size_t*, Thread&);
std::shared_ptr<ThreadGroup> m_threadGroup;
};
#define DECLARE_AND_COMPUTE_CURRENT_THREAD_STATE(stateName) \
CurrentThreadState stateName; \
stateName.stackTop = &stateName; \
stateName.stackOrigin = Thread::current().stack().origin(); \
ALLOCATE_AND_GET_REGISTER_STATE(stateName ## _registerState); \
stateName.registerState = &stateName ## _registerState
int callWithCurrentThreadState(const ScopedLambda<void(CurrentThreadState&)>&);
}