Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert unnecessary changes to VM shutdown #10328

Merged
merged 2 commits into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 10 additions & 28 deletions runtime/vm/jniinv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1084,38 +1084,20 @@ jint JNICALL AttachCurrentThreadAsDaemon(JavaVM * vm, void ** p_env, void * thr_

#if (defined(J9VM_OPT_SIDECAR))
/* run the shutdown method in java.lang.Shutdown */
void sidecarShutdown(J9VMThread* shutdownThread)
{
void sidecarShutdown(J9VMThread* shutdownThread) {
J9JavaVM * vm = shutdownThread->javaVM;
omrthread_monitor_t mutex = vm->runtimeFlagsMutex;
J9NameAndSignature nas;

nas.name = (J9UTF8*)&j9_shutdown;
nas.signature = (J9UTF8*)&j9_void_void;

/* Set a flag to allow System.exit to run from within finalizers run by the shutdown code */

if (NULL != mutex) {
omrthread_monitor_enter(mutex);
}
vm->runtimeFlags |= J9_RUNTIME_CLEANUP;
if (NULL != mutex) {
omrthread_monitor_exit(mutex);
}

enterVMFromJNI(shutdownThread);
runStaticMethod(shutdownThread, (U_8*)"java/lang/Shutdown", &nas, 0, NULL);
internalExceptionDescribe(shutdownThread);
releaseVMAccess(shutdownThread);
if (!(vm->runtimeFlags & J9_RUNTIME_CLEANUP)) {
J9NameAndSignature nas;

/* Unset the flag so System.exit is no longer allowed (particularly while the VMDeath JMVTI event is in progress) */
nas.name = (J9UTF8*)&j9_shutdown;
nas.signature = (J9UTF8*)&j9_void_void;

if (NULL != mutex) {
omrthread_monitor_enter(mutex);
}
vm->runtimeFlags &= ~J9_RUNTIME_CLEANUP;
if (NULL != mutex) {
omrthread_monitor_exit(mutex);
vm->runtimeFlags |= J9_RUNTIME_CLEANUP;
enterVMFromJNI(shutdownThread);
runStaticMethod(shutdownThread, (U_8*)"java/lang/Shutdown", &nas, 0, NULL);
internalExceptionDescribe(shutdownThread);
releaseVMAccess(shutdownThread);
}
}
#endif /* J9VM_OPT_SIDECAR */
Expand Down
41 changes: 14 additions & 27 deletions runtime/vm/jvminit.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ void OMRNORETURN exitJavaVM(J9VMThread * vmThread, IDATA rc)

if (vm != NULL) {
PORT_ACCESS_FROM_JAVAVM(vm);
omrthread_monitor_t mutex = vm->runtimeFlagsMutex;

#if defined(J9VM_INTERP_ATOMIC_FREE_JNI)
/* exitJavaVM is always called from a JNI context */
Expand All @@ -502,40 +501,28 @@ void OMRNORETURN exitJavaVM(J9VMThread * vmThread, IDATA rc)

/* we only let the shutdown code run once */

if (NULL != mutex) {
omrthread_monitor_enter(mutex);
if(vm->runtimeFlagsMutex != NULL) {
omrthread_monitor_enter(vm->runtimeFlagsMutex);
}

if (J9_ARE_ANY_BITS_SET(vm->runtimeFlags, J9_RUNTIME_EXIT_STARTED)) {
/* CLEANUP indicates that the VM is running the exit hooks/finalizers
* on exit - exit must be allowed in this case, but only from a finalizer
* thread (for simplicity, just check for a system thread as no other
* VM-owned threads will be attempting exit).
*
* CLEANUP will only ever be set once EXIT_STARTED has been set,
* so setting the `J9_RUNTIME_EXIT_STARTED` flag again below is harmless.
*/
if (J9_ARE_NO_BITS_SET(vmThread->privateFlags, J9_PRIVATE_FLAGS_SYSTEM_THREAD)
|| J9_ARE_NO_BITS_SET(vm->runtimeFlags, J9_RUNTIME_CLEANUP)
) {
if (NULL != mutex) {
omrthread_monitor_exit(mutex);
}
if(vm->runtimeFlags & J9_RUNTIME_EXIT_STARTED) {
if (vm->runtimeFlagsMutex != NULL) {
omrthread_monitor_exit(vm->runtimeFlagsMutex);
}

if (vmThread->publicFlags & J9_PUBLIC_FLAGS_VM_ACCESS) {
internalReleaseVMAccess(vmThread);
}
if (vmThread->publicFlags & J9_PUBLIC_FLAGS_VM_ACCESS) {
internalReleaseVMAccess(vmThread);
}

/* Do nothing. Wait for the process to exit. */
while (1) {
omrthread_suspend();
}
/* Do nothing. Wait for the process to exit. */
while (1) {
omrthread_suspend();
}
}

vm->runtimeFlags |= J9_RUNTIME_EXIT_STARTED;
if (NULL != mutex) {
omrthread_monitor_exit(mutex);
if(vm->runtimeFlagsMutex != NULL) {
omrthread_monitor_exit(vm->runtimeFlagsMutex);
}

#ifdef J9VM_OPT_SIDECAR
Expand Down