Skip to content

Commit

Permalink
Merge pull request #7422 from JasonFengJ9/hookunreserve
Browse files Browse the repository at this point in the history
Add J9HookInterface.J9HookUnreserve() to clear flag J9HOOK_FLAG_RESERVED
  • Loading branch information
babsingh authored Jul 24, 2024
2 parents 6002b4a + 8159d04 commit d18121d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions include_core/omrhookable.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ typedef struct J9HookInterface {
void (*J9HookDispatch)(struct J9HookInterface **hookInterface, uintptr_t eventNum, void *eventData);
intptr_t (*J9HookDisable)(struct J9HookInterface **hookInterface, uintptr_t eventNum);
intptr_t (*J9HookReserve)(struct J9HookInterface **hookInterface, uintptr_t eventNum);
void (*J9HookUnreserve)(struct J9HookInterface **hookInterface, uintptr_t eventNum);
intptr_t (*J9HookRegister)(struct J9HookInterface **hookInterface, uintptr_t eventNum, J9HookFunction function, void *userData, ...);
intptr_t (*J9HookRegisterWithCallSite)(struct J9HookInterface **hookInterface, uintptr_t eventNum, J9HookFunction function, const char *callsite, void *userData, ...);
void (*J9HookUnregister)(struct J9HookInterface **hookInterface, uintptr_t eventNum, J9HookFunction function, void *userData);
Expand Down
22 changes: 22 additions & 0 deletions util/hookable/hookable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ static intptr_t J9HookDisable(struct J9HookInterface **hookInterface, uintptr_t
static intptr_t J9HookIsEnabled(struct J9HookInterface **hookInterface, uintptr_t taggedEventNum);
static void J9HookDispatch(struct J9HookInterface **hookInterface, uintptr_t taggedEventNum, void *eventData);
static intptr_t J9HookReserve(struct J9HookInterface **hookInterface, uintptr_t taggedEventNum);
static void J9HookUnreserve(struct J9HookInterface **hookInterface, uintptr_t taggedEventNum);
static uintptr_t J9HookAllocateAgentID(struct J9HookInterface **hookInterface);
static void J9HookDeallocateAgentID(struct J9HookInterface **hookInterface, uintptr_t agentID);

static const J9HookInterface hookFunctionTable = {
J9HookDispatch,
J9HookDisable,
J9HookReserve,
J9HookUnreserve,
J9HookRegister,
J9HookRegisterWithCallSite,
J9HookUnregister,
Expand Down Expand Up @@ -345,6 +347,26 @@ J9HookReserve(struct J9HookInterface **hookInterface, uintptr_t taggedEventNum)
return rc;
}

/*
* Clear the J9HOOK_FLAG_RESERVED flag from an event.
* This flag can be removed regardless of current flag(s) of the event,
* J9HOOK_FLAG_RESERVED, J9HOOK_FLAG_HOOKED or J9HOOK_FLAG_DISABLED.
*
* This function should not be called directly. It should be called through the hook interface.
*/
static void
J9HookUnreserve(struct J9HookInterface **hookInterface, uintptr_t taggedEventNum)
{
J9CommonHookInterface *commonInterface = (J9CommonHookInterface *)hookInterface;
uintptr_t eventNum = taggedEventNum & J9HOOK_EVENT_NUM_MASK;

omrthread_monitor_enter(commonInterface->lock);

HOOK_FLAGS(commonInterface, eventNum) &= ~J9HOOK_FLAG_RESERVED;

omrthread_monitor_exit(commonInterface->lock);
}

static intptr_t
J9HookRegisterWithCallSitePrivate(struct J9HookInterface **hookInterface, uintptr_t taggedEventNum, J9HookFunction function, const char *callsite, void *userData, uintptr_t agentID)
{
Expand Down

0 comments on commit d18121d

Please sign in to comment.