LibJS/JIT: Add simple compile-time flags for logging & dumping code

This commit is contained in:
Andreas Kling 2023-10-27 11:18:13 +02:00
parent 3b239b64ff
commit ae273e8e20
Notes: sideshowbarker 2024-07-16 20:21:48 +09:00

View file

@ -15,6 +15,10 @@
#include <sys/mman.h>
#include <unistd.h>
#define LOG_JIT_SUCCESS 1
#define LOG_JIT_FAILURE 1
#define DUMP_JIT_MACHINE_CODE_TO_STDOUT 0
#define TRY_OR_SET_EXCEPTION(expression) \
({ \
/* Ignore -Wshadow to allow nesting the macro. */ \
@ -939,8 +943,10 @@ OwnPtr<NativeExecutable> Compiler::compile(Bytecode::Executable& bytecode_execut
#undef DO_COMPILE_COMMON_UNARY_OP
default:
dbgln("\033[31;1mJIT compilation failed\033[0m: {}", bytecode_executable.name);
dbgln("Unsupported bytecode op: {}", op.to_deprecated_string(bytecode_executable));
if constexpr (LOG_JIT_FAILURE) {
dbgln("\033[31;1mJIT compilation failed\033[0m: {}", bytecode_executable.name);
dbgln("Unsupported bytecode op: {}", op.to_deprecated_string(bytecode_executable));
}
return nullptr;
}
@ -975,13 +981,16 @@ OwnPtr<NativeExecutable> Compiler::compile(Bytecode::Executable& bytecode_execut
}
}
size_t res = write(STDOUT_FILENO, compiler.m_output.data(), compiler.m_output.size());
if (!res) { }
if constexpr (DUMP_JIT_MACHINE_CODE_TO_STDOUT) {
(void)write(STDOUT_FILENO, compiler.m_output.data(), compiler.m_output.size());
}
memcpy(executable_memory, compiler.m_output.data(), compiler.m_output.size());
mprotect(executable_memory, compiler.m_output.size(), PROT_READ | PROT_EXEC);
dbgln("\033[32;1mJIT compilation succeeded!\033[0m {}", bytecode_executable.name);
if constexpr (LOG_JIT_SUCCESS) {
dbgln("\033[32;1mJIT compilation succeeded!\033[0m {}", bytecode_executable.name);
}
return make<NativeExecutable>(executable_memory, compiler.m_output.size());
}