From ae273e8e200ac41080354ff4a2e3ec6d461048fd Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 27 Oct 2023 11:18:13 +0200 Subject: [PATCH] LibJS/JIT: Add simple compile-time flags for logging & dumping code --- Userland/Libraries/LibJS/JIT/Compiler.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index 47406d6446..18f2b6fd4b 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -15,6 +15,10 @@ #include #include +#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 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 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(executable_memory, compiler.m_output.size()); }