@@ -36,7 +36,7 @@ extern "C" {
36
36
// TODO: allow configureable values
37
37
#define J9JFR_THREAD_BUFFER_SIZE (1024 *1024 )
38
38
#define J9JFR_GLOBAL_BUFFER_SIZE (10 * J9JFR_THREAD_BUFFER_SIZE)
39
- #define J9JFR_SAMPLING_RATE 1000
39
+ #define J9JFR_SAMPLING_RATE 10
40
40
41
41
static UDATA jfrEventSize (J9JFREvent *jfrEvent);
42
42
static void tearDownJFR (J9JavaVM *vm);
@@ -53,6 +53,7 @@ static void jfrThreadEnd(J9HookInterface **hook, UDATA eventNum, void *eventData
53
53
static void jfrVMInitialized (J9HookInterface **hook, UDATA eventNum, void *eventData, void *userData);
54
54
static void initializeEventFields (J9VMThread *currentThread, J9JFREvent *jfrEvent, UDATA eventType);
55
55
static int J9THREAD_PROC jfrSamplingThreadProc (void *entryArg);
56
+ static void jfrExecutionSampleCallback (J9VMThread *currentThread, IDATA handlerKey, void *userData);
56
57
static void initializeJFRConstantEvents (J9JavaVM *vm);
57
58
static void freeJFRConstantEvents (J9JavaVM *vm);
58
59
@@ -556,6 +557,12 @@ initializeJFR(J9JavaVM *vm)
556
557
J9HookInterface **vmHooks = getVMHookInterface (vm);
557
558
U_8 *buffer = NULL ;
558
559
560
+ /* Register async handler for execution samples */
561
+ vm->jfrAsyncKey = J9RegisterAsyncEvent (vm, jfrExecutionSampleCallback, NULL );
562
+ if (vm->jfrAsyncKey < 0 ) {
563
+ goto fail;
564
+ }
565
+
559
566
if ((*vmHooks)->J9HookRegisterWithCallSite (vmHooks, J9HOOK_VM_THREAD_CREATED, jfrThreadCreated, OMR_GET_CALLSITE (), NULL )) {
560
567
goto fail;
561
568
}
@@ -668,6 +675,11 @@ tearDownJFR(J9JavaVM *vm)
668
675
j9mem_free_memory (vm->jfrState .metaDataBlobFile );
669
676
vm->jfrState .metaDataBlobFile = NULL ;
670
677
vm->jfrState .metaDataBlobFileSize = 0 ;
678
+ if (vm->jfrAsyncKey >= 0 ) {
679
+ J9UnregisterAsyncEvent (vm, vm->jfrAsyncKey );
680
+ vm->jfrAsyncKey = -1 ;
681
+ }
682
+
671
683
}
672
684
673
685
/* *
@@ -732,6 +744,12 @@ jfrExecutionSample(J9VMThread *currentThread, J9VMThread *sampleThread)
732
744
}
733
745
}
734
746
747
+ static void
748
+ jfrExecutionSampleCallback (J9VMThread *currentThread, IDATA handlerKey, void *userData)
749
+ {
750
+ jfrExecutionSample (currentThread, currentThread);
751
+ }
752
+
735
753
static int J9THREAD_PROC
736
754
jfrSamplingThreadProc (void *entryArg)
737
755
{
@@ -743,19 +761,7 @@ jfrSamplingThreadProc(void *entryArg)
743
761
vm->jfrSamplerState = J9JFR_SAMPLER_STATE_RUNNING;
744
762
omrthread_monitor_notify_all (vm->jfrSamplerMutex );
745
763
while (J9JFR_SAMPLER_STATE_STOP != vm->jfrSamplerState ) {
746
- omrthread_monitor_exit (vm->jfrSamplerMutex );
747
- internalEnterVMFromJNI (currentThread);
748
- acquireExclusiveVMAccess (currentThread);
749
- J9VMThread *walkThread = J9_LINKED_LIST_START_DO (vm->mainThread );
750
- while (NULL != walkThread) {
751
- if (VM_VMHelpers::threadCanRunJavaCode (walkThread)) {
752
- jfrExecutionSample (currentThread, walkThread);
753
- }
754
- walkThread = J9_LINKED_LIST_NEXT_DO (vm->mainThread , walkThread);
755
- }
756
- releaseExclusiveVMAccess (currentThread);
757
- internalExitVMToJNI (currentThread);
758
- omrthread_monitor_enter (vm->jfrSamplerMutex );
764
+ J9SignalAsyncEvent (vm, NULL , vm->jfrAsyncKey );
759
765
omrthread_monitor_wait_timed (vm->jfrSamplerMutex , J9JFR_SAMPLING_RATE, 0 );
760
766
}
761
767
omrthread_monitor_exit (vm->jfrSamplerMutex );
0 commit comments