1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 16:24:59 +00:00
serenity/Userland/Libraries/LibJS/JIT/NativeExecutable.h
Simon Wanner 68f4d21de2 LibJS: Lazily collect stack trace information
The previous implementation was calling `backtrace()` for every
function call, which is quite slow.

Instead, this implementation provides VM::stack_trace() which unwinds
the native stack, maps it through NativeExecutable::get_source_range
and combines it with source ranges from interpreted call frames.
2023-11-02 07:37:41 +01:00

48 lines
1.3 KiB
C++

/*
* Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Noncopyable.h>
#include <AK/Types.h>
#include <LibJS/Bytecode/Instruction.h>
#include <LibJS/Runtime/Completion.h>
namespace JS::JIT {
struct BytecodeMapping {
size_t native_offset;
size_t block_index;
size_t bytecode_offset;
// Special block index for labels outside any blocks.
static constexpr auto EXECUTABLE = NumericLimits<size_t>::max();
static constexpr auto EXECUTABLE_LABELS = AK::Array { "entry"sv, "common_exit"sv };
};
class NativeExecutable {
AK_MAKE_NONCOPYABLE(NativeExecutable);
AK_MAKE_NONMOVABLE(NativeExecutable);
public:
NativeExecutable(void* code, size_t size, Vector<BytecodeMapping>);
~NativeExecutable();
void run(VM&) const;
void dump_disassembly(Bytecode::Executable const& executable) const;
BytecodeMapping const& find_mapping_entry(size_t native_offset) const;
Optional<UnrealizedSourceRange> get_source_range(Bytecode::Executable const& executable, FlatPtr address) const;
ReadonlyBytes code_bytes() const { return { m_code, m_size }; }
private:
void* m_code { nullptr };
size_t m_size { 0 };
Vector<BytecodeMapping> m_mapping;
mutable OwnPtr<Bytecode::InstructionStreamIterator> m_instruction_stream_iterator;
};
}