3030#include " mmomrhook.h"
3131#include " modronapi.hpp"
3232
33+ #define BEFORE_GC 0
34+ #define AFTER_GC 1
35+
3336/* *
3437 * Register GC-related JFR hooks.
3538 *
3639 * This function registers all garbage collection related hooks for JFR event recording:
37- * - jfrPublioGCEndHook (corresponding to public OMR hook)
38- * - jfrPrivateGCEndHook (corresponding to private OMR hook)
40+ * - jfrGCCycleStartHook (corresponding to public OMR GC cycle start trigger)
41+ * - jfrPublicGCEndHook (corresponding to public OMR GC cycle end trigger)
42+ * - jfrPrivateGCEndHook (corresponding to private OMR GC cycle end trigger)
3943 *
4044 * @param vm[in] The Java VM
4145 * @return 0 on success, non-zero on failure
@@ -46,6 +50,9 @@ jfrRegisterGCHooks(J9JavaVM *vm)
4650 J9HookInterface** gcOmrHooks = vm->memoryManagerFunctions ->j9gc_get_omr_hook_interface (vm->omrVM );
4751 J9HookInterface** gcPrivateHooks = vm->memoryManagerFunctions ->j9gc_get_private_hook_interface (vm);
4852
53+ if ((*gcOmrHooks)->J9HookRegisterWithCallSite (gcOmrHooks, J9HOOK_MM_OMR_GC_CYCLE_START , jfrGCCycleStartHook, OMR_GET_CALLSITE (), NULL )) {
54+ return -1 ;
55+ }
4956 if ((*gcOmrHooks)->J9HookRegisterWithCallSite (gcOmrHooks, J9HOOK_MM_OMR_GC_CYCLE_END , jfrPublicGCEndHook, OMR_GET_CALLSITE (), NULL )) {
5057 return -1 ;
5158 }
@@ -62,9 +69,32 @@ jfrRegisterGCHooks(J9JavaVM *vm)
6269}
6370
6471/* *
65- * JFR GC Hook corresponding to public OMR hook data.
72+ * JFR GC Hook corresponding to public OMR cycle start trigger.
73+ *
74+ * This function emits all garbage collection related JFR events on the public OMR cycle start trigger.
75+ *
76+ * @param hook[in] the VM hook interface
77+ * @param eventNum[in] the event number
78+ * @param eventData[in] the event data
79+ * @param userData[in] the registered user data
80+ */
81+ void
82+ jfrGCCycleStartHook (J9HookInterface **hook, UDATA eventNum, void *eventData, void *userData)
83+ {
84+ MM_GCCycleStartEvent *event = (MM_GCCycleStartEvent *)eventData;
85+ OMR_VMThread *omrVMThread = (OMR_VMThread *)event->omrVMThread ;
86+ J9VMThread *currentThread = (J9VMThread *)omrVMThread->_language_vmthread ;
87+ J9JavaVM *javaVM = currentThread->javaVM ;
88+ J9InternalVMFunctions *vmFuncs = javaVM->internalVMFunctions ;
89+
90+ /* Emit heap summary with gcWhenID = BeforeGC */
91+ vmFuncs->jfrGCHeapSummary (omrVMThread, BEFORE_GC );
92+ }
93+
94+ /* *
95+ * JFR GC Hook corresponding to public OMR cycle end trigger.
6696 *
67- * This function calls all garbage collection related JFR event recording functions on the public OMR hook .
97+ * This function emits all garbage collection related JFR events on the public OMR cycle end trigger .
6898 *
6999 * @param hook[in] the VM hook interface
70100 * @param eventNum[in] the event number
@@ -88,9 +118,9 @@ jfrPublicGCEndHook(J9HookInterface **hook, UDATA eventNum, void *eventData, void
88118}
89119
90120/* *
91- * JFR GC Hook corresponding to private OMR hook data .
121+ * JFR GC Hook corresponding to private OMR cycle end trigger .
92122 *
93- * This function calls all garbage collection related JFR event recording functions on the public OMR hook .
123+ * This function emits all garbage collection related JFR events on the private OMR cycle end trigger .
94124 *
95125 * @param hook[in] the VM hook interface
96126 * @param eventNum[in] the event number
@@ -107,6 +137,8 @@ jfrPrivateGCEndHook(J9HookInterface **hook, UDATA eventNum, void *eventData, voi
107137 J9InternalVMFunctions *vmFuncs = javaVM->internalVMFunctions ;
108138
109139 vmFuncs->jfrGarbageCollection (omrVMThread);
140+ /* Emit heap summary with gcWhenID = AfterGC */
141+ vmFuncs->jfrGCHeapSummary (omrVMThread, AFTER_GC );
110142
111143}
112144
@@ -124,6 +156,7 @@ jfrDeregisterGCHooks(J9JavaVM *vm)
124156 J9HookInterface** gcOmrHooks = vm->memoryManagerFunctions ->j9gc_get_omr_hook_interface (vm->omrVM );
125157 J9HookInterface** gcPrivateHooks = vm->memoryManagerFunctions ->j9gc_get_private_hook_interface (vm);
126158
159+ (*gcOmrHooks)->J9HookUnregister (gcOmrHooks, J9HOOK_MM_OMR_GC_CYCLE_START , jfrGCCycleStartHook, NULL );
127160 (*gcOmrHooks)->J9HookUnregister (gcOmrHooks, J9HOOK_MM_OMR_GC_CYCLE_END , jfrPublicGCEndHook, NULL );
128161 (*gcPrivateHooks)->J9HookUnregister (gcPrivateHooks, J9HOOK_MM_PRIVATE_GC_POST_CYCLE_END , jfrPrivateGCEndHook, NULL );
129162}
0 commit comments