Skip to content

Commit 9381d3b

Browse files
committed
Stabilize wasm runtime-cache tests by clearing in-process JIT cache
1 parent a70c989 commit 9381d3b

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/dsl_jit_backend_wasm32.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,19 @@ typedef struct {
511511
static me_dsl_jit_wasm_pos_cache_entry g_dsl_jit_wasm_pos_cache[ME_DSL_JIT_WASM_POS_CACHE_SLOTS];
512512
static int g_dsl_jit_wasm_pos_cache_cursor = 0;
513513

514+
void dsl_jit_wasm_pos_cache_reset_for_tests(void) {
515+
for (int i = 0; i < ME_DSL_JIT_WASM_POS_CACHE_SLOTS; i++) {
516+
if (g_dsl_jit_wasm_pos_cache[i].valid) {
517+
if (g_dsl_jit_wasm_pos_cache[i].fn_idx != 0) {
518+
dsl_wasm_jit_free_dispatch(g_dsl_jit_wasm_pos_cache[i].fn_idx);
519+
}
520+
free(g_dsl_jit_wasm_pos_cache[i].scratch);
521+
memset(&g_dsl_jit_wasm_pos_cache[i], 0, sizeof(g_dsl_jit_wasm_pos_cache[i]));
522+
}
523+
}
524+
g_dsl_jit_wasm_pos_cache_cursor = 0;
525+
}
526+
514527
static int dsl_jit_wasm_pos_cache_find_slot(uint64_t key) {
515528
for (int i = 0; i < ME_DSL_JIT_WASM_POS_CACHE_SLOTS; i++) {
516529
if (g_dsl_jit_wasm_pos_cache[i].valid && g_dsl_jit_wasm_pos_cache[i].key == key) {

src/dsl_jit_runtime_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ bool dsl_jit_cc_promote_self_symbols_global(void);
263263
#if ME_USE_WASM32_JIT
264264
bool dsl_jit_compile_wasm32(me_dsl_compiled_program *program, uint64_t key);
265265
bool dsl_jit_wasm_pos_cache_bind_program(me_dsl_compiled_program *program, uint64_t key);
266+
void dsl_jit_wasm_pos_cache_reset_for_tests(void);
266267
void dsl_wasm_jit_free_dispatch(int idx);
267268
void dsl_register_wasm_jit_helpers(me_wasm_jit_instantiate_helper instantiate_helper,
268269
me_wasm_jit_free_helper free_helper);

tests/test_dsl_jit_runtime_cache.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,6 +2151,7 @@ static int test_wasm_reserved_index_cache_key_differentiation(void) {
21512151
printf(" FAILED: setenv ME_DSL_JIT=1 failed\n");
21522152
goto cleanup;
21532153
}
2154+
dsl_jit_wasm_pos_cache_reset_for_tests();
21542155
test_wasm_runtime_cache_reset_instantiate_count();
21552156

21562157
if (me_compile(src_global, NULL, 0, ME_FLOAT64, &err, &expr) != ME_COMPILE_SUCCESS || !expr) {
@@ -2264,6 +2265,7 @@ static int test_wasm_runtime_cache_eviction_policy(void) {
22642265
printf(" FAILED: setenv ME_DSL_JIT=1 failed\n");
22652266
goto cleanup;
22662267
}
2268+
dsl_jit_wasm_pos_cache_reset_for_tests();
22672269
test_wasm_runtime_cache_reset_instantiate_count();
22682270

22692271
if (snprintf(src, sizeof(src),
@@ -2482,14 +2484,17 @@ static int test_wasm_instantiate_warning_policy(void) {
24822484
printf("\n=== DSL JIT Runtime Cache Test: wasm instantiate warning policy ===\n");
24832485

24842486
static const char *src_default =
2487+
"# me:compiler=cc\n"
24852488
"def kernel_warn_default(x):\n"
24862489
" y = x + 41.0\n"
24872490
" return y\n";
24882491
static const char *src_on =
2492+
"# me:compiler=cc\n"
24892493
"def kernel_warn_on(x):\n"
24902494
" y = x + 42.0\n"
24912495
" return y\n";
24922496
static const char *src_trace =
2497+
"# me:compiler=cc\n"
24932498
"def kernel_warn_trace(x):\n"
24942499
" y = x + 43.0\n"
24952500
" return y\n";

0 commit comments

Comments
 (0)