@@ -440,15 +440,19 @@ jfrVMShutdown(J9HookInterface **hook, UDATA eventNum, void *eventData, void *use
440
440
{
441
441
J9VMShutdownEvent *event = (J9VMShutdownEvent *)eventData;
442
442
J9VMThread *currentThread = event->vmThread ;
443
+ bool needsVMAccess = J9_ARE_NO_BITS_SET (currentThread->publicFlags , J9_PUBLIC_FLAGS_VM_ACCESS);
443
444
bool acquiredExclusive = false ;
444
445
445
446
#if defined(DEBUG)
446
447
PORT_ACCESS_FROM_VMC (currentThread);
447
448
j9tty_printf (PORTLIB, " \n !!! shutdown %p\n " , currentThread);
448
449
#endif /* defined(DEBUG) */
449
450
450
- if (J9_XACCESS_NONE == currentThread-> javaVM -> exclusiveAccessState ) {
451
+ if (needsVMAccess ) {
451
452
internalAcquireVMAccess (currentThread);
453
+ }
454
+
455
+ if (J9_XACCESS_NONE == currentThread->javaVM ->exclusiveAccessState ) {
452
456
acquireExclusiveVMAccess (currentThread);
453
457
acquiredExclusive = true ;
454
458
}
@@ -459,10 +463,13 @@ jfrVMShutdown(J9HookInterface **hook, UDATA eventNum, void *eventData, void *use
459
463
460
464
if (acquiredExclusive) {
461
465
releaseExclusiveVMAccess (currentThread);
462
- internalReleaseVMAccess (currentThread);
463
466
}
464
467
465
468
tearDownJFR (currentThread->javaVM );
469
+
470
+ if (needsVMAccess) {
471
+ internalReleaseVMAccess (currentThread);
472
+ }
466
473
}
467
474
468
475
/* *
@@ -762,8 +769,13 @@ void
762
769
tearDownJFR (J9JavaVM *vm)
763
770
{
764
771
PORT_ACCESS_FROM_JAVAVM (vm);
772
+ J9VMThread *currentThread = currentVMThread (vm);
765
773
J9HookInterface **vmHooks = getVMHookInterface (vm);
766
774
775
+ Assert_VM_mustHaveVMAccess (currentThread);
776
+
777
+ internalReleaseVMAccess (currentThread);
778
+
767
779
/* Stop the sampler thread */
768
780
if (NULL != vm->jfrSamplerMutex ) {
769
781
omrthread_monitor_enter (vm->jfrSamplerMutex );
@@ -778,6 +790,9 @@ tearDownJFR(J9JavaVM *vm)
778
790
omrthread_monitor_destroy (vm->jfrSamplerMutex );
779
791
vm->jfrSamplerMutex = NULL ;
780
792
}
793
+
794
+ internalAcquireVMAccess (currentThread);
795
+
781
796
vm->jfrState .isStarted = FALSE ;
782
797
vm->jfrSamplerState = J9JFR_SAMPLER_STATE_UNINITIALIZED;
783
798
0 commit comments