[Java.Runtime.Environment] Don't Destroy the JVM by default. #65
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When
JniRuntime.CreationOptions.DestroyRuntimeOnDispose
is true,JavaVM::DestroyJavaVM()
will be invoked when theJniRuntime
instance is disposed or finalized.
JreRuntime.CreateJreVM()
would always setDestroyRuntimeOnDispose
to true, because it calledJNI_CreateJavaVM()
, so of course you'd want to destroy theJava VM, right?
Which brings us to unit tests. I don't know of any "before all test
fixtures run" and "after all test fixtures run" extension points,
which means:
tests have finished executing.
Which really means that the
JreRuntime
instance is finalized,which sets us up for the unholy trifecta of AppDomain unloads,
finalizers, and JVM shutdown:
For unknown reasons, ~randomly, when running the unit tests (e.g.
make run-tests
), the test runner will hang, indefinitely.Attaching
lldb
and triggering a backtrace shows the unholy trifecta:Finalization:
JVM destruction:
AppDomain unload:
This randomly results in deadlock, and hung Jenkins bots.
Fix this behavior by altering
JreRuntime.CreateJreVM()
to notoverride the value of
JniRuntime.CreationOptions.DestroyRuntimeOnDispose
. This allows theconstructor of the
JreRuntime
instance to decide whether or not theJVM is destroyed.
In the case of TestJVM, we don't want to destroy the JVM.
This prevents the JVM from being destroyed, which in turn prevents the
hang during process shutdown.