Skip to content

Commit aab5dcb

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 aab5dcb

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/emulate.c

Lines changed: 5 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,16 @@ 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("JIT: Translation failed for block pc=0x%08x, using interpreter",
1220+
block->pc_start);
12161221
}
12171222
set_reset(&pc_set);
12181223
has_loops = false;

src/jit.c

Lines changed: 14 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,8 @@ 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("JIT: Flushing code cache (n_blocks=%d, n_jumps=%d, offset=%u)",
2172+
state->n_blocks, state->n_jumps, state->offset);
21692173
should_flush = false;
21702174
state->offset = state->org_size;
21712175
state->n_blocks = 0;
@@ -2199,6 +2203,7 @@ static void translate(struct jit_state *state, riscv_t *rv, block_t *block)
21992203

22002204
static void resolve_jumps(struct jit_state *state)
22012205
{
2206+
rv_log_debug("JIT: Resolving %d jumps", state->n_jumps);
22022207
for (int i = 0; i < state->n_jumps; i++) {
22032208
struct jump jump = state->jumps[i];
22042209
int target_loc;
@@ -2221,6 +2226,8 @@ static void resolve_jumps(struct jit_state *state)
22212226
(if (jump.target_satp == state->offset_map[i].satp), )
22222227
{
22232228
target_loc = state->offset_map[i].offset;
2229+
rv_log_debug("JIT: Jump %d resolved to block pc=0x%08x, offset=%d",
2230+
i, jump.target_pc, target_loc);
22242231
break;
22252232
}
22262233
}
@@ -2312,12 +2319,15 @@ void jit_translate(riscv_t *rv, block_t *block)
23122319
) {
23132320
block->offset = state->offset_map[i].offset;
23142321
block->hot = true;
2322+
rv_log_debug("JIT: Cache hit for block pc=0x%08x, offset=%u",
2323+
block->pc_start, block->offset);
23152324
return;
23162325
}
23172326
}
23182327
assert(NULL);
23192328
__UNREACHABLE;
23202329
}
2330+
rv_log_debug("JIT: Starting translation for block pc=0x%08x", block->pc_start);
23212331
restart:
23222332
memset(state->jumps, 0, MAX_JUMPS * sizeof(struct jump));
23232333
state->n_jumps = 0;
@@ -2327,11 +2337,15 @@ void jit_translate(riscv_t *rv, block_t *block)
23272337
/* Mark block as not translated since translation was incomplete */
23282338
block->hot = false;
23292339
/* Don't reset offset - it will be set correctly on restart */
2340+
rv_log_debug("JIT: Translation triggered flush for block pc=0x%08x",
2341+
block->pc_start);
23302342
code_cache_flush(state, rv);
23312343
goto restart;
23322344
}
23332345
resolve_jumps(state);
23342346
block->hot = true;
2347+
rv_log_debug("JIT: Translation completed for block pc=0x%08x, offset=%u, size=%u",
2348+
block->pc_start, block->offset, state->offset - block->offset);
23352349
}
23362350

23372351
struct jit_state *jit_state_init(size_t size)

0 commit comments

Comments
 (0)