Skip to content

Commit e6005e5

Browse files
committed
Add diagnostic logging to JIT compilation pipeline
This introduces debug-level logging throughout the JITC to facilitate troubleshooting of intermittent compilation and execution failures on Arm64.
1 parent e72134d commit e6005e5

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/emulate.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ extern struct target_ops gdbstub_ops;
2424
#endif
2525

2626
#include "decode.h"
27+
#include "log.h"
2728
#include "mpool.h"
2829
#include "riscv.h"
2930
#include "riscv_private.h"
@@ -1207,12 +1208,18 @@ void rv_step(void *arg)
12071208
jit_translate(rv, block);
12081209
/* Only execute if translation succeeded (block is hot) */
12091210
if (block->hot) {
1211+
rv_log_debug("JIT: Executing block pc=0x%08x, offset=%u",
1212+
block->pc_start, block->offset);
12101213
((exec_block_func_t) state->buf)(
12111214
rv, (uintptr_t) (state->buf + block->offset));
12121215
prev = NULL;
12131216
continue;
12141217
}
12151218
/* Fall through to interpreter if translation failed */
1219+
rv_log_debug(
1220+
"JIT: Translation failed for block pc=0x%08x, using "
1221+
"interpreter",
1222+
block->pc_start);
12161223
}
12171224
set_reset(&pc_set);
12181225
has_loops = false;

src/jit.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "decode.h"
4343
#include "io.h"
4444
#include "jit.h"
45+
#include "log.h"
4546
#include "riscv.h"
4647
#include "riscv_private.h"
4748
#include "utils.h"
@@ -593,6 +594,7 @@ static void update_branch_imm(struct jit_state *state,
593594
assert((imm & 3) == 0);
594595
uint32_t insn;
595596
imm >>= 2;
597+
rv_log_debug("JIT: Patching branch at offset=%u, imm=%d", offset, imm << 2);
596598
#if defined(__APPLE__) && defined(__aarch64__)
597599
/* Must be in write mode to read/write MAP_JIT memory on Apple ARM64 */
598600
pthread_jit_write_protect_np(false);
@@ -2166,6 +2168,9 @@ void clear_hot(block_t *block)
21662168

21672169
static void code_cache_flush(struct jit_state *state, riscv_t *rv)
21682170
{
2171+
rv_log_debug(
2172+
"JIT: Flushing code cache (n_blocks=%d, n_jumps=%d, offset=%u)",
2173+
state->n_blocks, state->n_jumps, state->offset);
21692174
should_flush = false;
21702175
state->offset = state->org_size;
21712176
state->n_blocks = 0;
@@ -2199,6 +2204,7 @@ static void translate(struct jit_state *state, riscv_t *rv, block_t *block)
21992204

22002205
static void resolve_jumps(struct jit_state *state)
22012206
{
2207+
rv_log_debug("JIT: Resolving %d jumps", state->n_jumps);
22022208
for (int i = 0; i < state->n_jumps; i++) {
22032209
struct jump jump = state->jumps[i];
22042210
int target_loc;
@@ -2221,6 +2227,10 @@ static void resolve_jumps(struct jit_state *state)
22212227
(if (jump.target_satp == state->offset_map[i].satp), )
22222228
{
22232229
target_loc = state->offset_map[i].offset;
2230+
rv_log_debug(
2231+
"JIT: Jump %d resolved to block pc=0x%08x, "
2232+
"offset=%d",
2233+
i, jump.target_pc, target_loc);
22242234
break;
22252235
}
22262236
}
@@ -2312,12 +2322,16 @@ void jit_translate(riscv_t *rv, block_t *block)
23122322
) {
23132323
block->offset = state->offset_map[i].offset;
23142324
block->hot = true;
2325+
rv_log_debug("JIT: Cache hit for block pc=0x%08x, offset=%u",
2326+
block->pc_start, block->offset);
23152327
return;
23162328
}
23172329
}
23182330
assert(NULL);
23192331
__UNREACHABLE;
23202332
}
2333+
rv_log_debug("JIT: Starting translation for block pc=0x%08x",
2334+
block->pc_start);
23212335
restart:
23222336
memset(state->jumps, 0, MAX_JUMPS * sizeof(struct jump));
23232337
state->n_jumps = 0;
@@ -2327,11 +2341,16 @@ void jit_translate(riscv_t *rv, block_t *block)
23272341
/* Mark block as not translated since translation was incomplete */
23282342
block->hot = false;
23292343
/* Don't reset offset - it will be set correctly on restart */
2344+
rv_log_debug("JIT: Translation triggered flush for block pc=0x%08x",
2345+
block->pc_start);
23302346
code_cache_flush(state, rv);
23312347
goto restart;
23322348
}
23332349
resolve_jumps(state);
23342350
block->hot = true;
2351+
rv_log_debug(
2352+
"JIT: Translation completed for block pc=0x%08x, offset=%u, size=%u",
2353+
block->pc_start, block->offset, state->offset - block->offset);
23352354
}
23362355

23372356
struct jit_state *jit_state_init(size_t size)

0 commit comments

Comments
 (0)