Remove generic experimental hooks

This commit is contained in:
Slobodan Predolac
2026-05-12 15:34:09 -07:00
parent 3f9d8ca3d0
commit ff2c2548a3
20 changed files with 25 additions and 1636 deletions

View File

@@ -1,7 +1,6 @@
#include "test/jemalloc_test.h"
#include "jemalloc/internal/ctl.h"
#include "jemalloc/internal/hook.h"
#include "jemalloc/internal/util.h"
TEST_BEGIN(test_mallctl_errors) {
@@ -1216,79 +1215,6 @@ TEST_BEGIN(test_stats_arenas_hpa_shard_slabs) {
}
TEST_END
static void
alloc_hook(void *extra, UNUSED hook_alloc_t type, UNUSED void *result,
UNUSED uintptr_t result_raw, UNUSED uintptr_t args_raw[3]) {
*(bool *)extra = true;
}
static void
dalloc_hook(void *extra, UNUSED hook_dalloc_t type, UNUSED void *address,
UNUSED uintptr_t args_raw[3]) {
*(bool *)extra = true;
}
TEST_BEGIN(test_hooks) {
bool hook_called = false;
hooks_t hooks = {&alloc_hook, &dalloc_hook, NULL, &hook_called};
void *handle = NULL;
size_t sz = sizeof(handle);
int err = mallctl(
"experimental.hooks.install", &handle, &sz, &hooks, sizeof(hooks));
expect_d_eq(err, 0, "Hook installation failed");
expect_ptr_ne(handle, NULL, "Hook installation gave null handle");
void *ptr = mallocx(1, 0);
expect_true(hook_called, "Alloc hook not called");
hook_called = false;
free(ptr);
expect_true(hook_called, "Free hook not called");
err = mallctl(
"experimental.hooks.remove", NULL, NULL, &handle, sizeof(handle));
expect_d_eq(err, 0, "Hook removal failed");
hook_called = false;
ptr = mallocx(1, 0);
free(ptr);
expect_false(hook_called, "Hook called after removal");
}
TEST_END
TEST_BEGIN(test_hooks_exhaustion) {
bool hook_called = false;
hooks_t hooks = {&alloc_hook, &dalloc_hook, NULL, &hook_called};
void *handle;
void *handles[HOOK_MAX];
size_t sz = sizeof(handle);
int err;
for (int i = 0; i < HOOK_MAX; i++) {
handle = NULL;
err = mallctl("experimental.hooks.install", &handle, &sz,
&hooks, sizeof(hooks));
expect_d_eq(err, 0, "Error installation hooks");
expect_ptr_ne(handle, NULL, "Got NULL handle");
handles[i] = handle;
}
err = mallctl(
"experimental.hooks.install", &handle, &sz, &hooks, sizeof(hooks));
expect_d_eq(err, EAGAIN, "Should have failed hook installation");
for (int i = 0; i < HOOK_MAX; i++) {
err = mallctl("experimental.hooks.remove", NULL, NULL,
&handles[i], sizeof(handles[i]));
expect_d_eq(err, 0, "Hook removal failed");
}
/* Insertion failed, but then we removed some; it should work now. */
handle = NULL;
err = mallctl(
"experimental.hooks.install", &handle, &sz, &hooks, sizeof(hooks));
expect_d_eq(err, 0, "Hook insertion failed");
expect_ptr_ne(handle, NULL, "Got NULL handle");
err = mallctl(
"experimental.hooks.remove", NULL, NULL, &handle, sizeof(handle));
expect_d_eq(err, 0, "Hook removal failed");
}
TEST_END
TEST_BEGIN(test_thread_idle) {
/*
* We're cheating a little bit in this test, and inferring things about
@@ -1483,7 +1409,6 @@ main(void) {
test_arenas_lextent_constants, test_arenas_create,
test_arenas_lookup, test_prof_active, test_stats_arenas,
test_stats_arenas_hpa_shard_counters,
test_stats_arenas_hpa_shard_slabs, test_hooks,
test_hooks_exhaustion, test_thread_idle, test_thread_peak,
test_stats_arenas_hpa_shard_slabs, test_thread_idle, test_thread_peak,
test_thread_event_hook);
}