Avoid jacop-related crashes due to destructor execution order #133
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 Fedora switched from building with OpenJDK 8 to OpenJDK 11 a few months ago, the mp package started failing its tests. The jacop-test binary, in particular, started segfaulting. I finally got around to diagnosing the issue.
In
solvers/jacop/java.h
, there is a class namedJVM
which contains aJavaVM pointer
(jvm_
) and an environment (env_
). There is also a static instance of this class, namedinstance_
, which is initialized on the fly when it is first accessed. TheJVM
destructor is insolvers/jacop/java.cc
:After the jacop tests have run, the test program exits. This triggers execution of destructors for static and global objects. At some point, the
ImageFileReaderTable
destructor is run. This is an object in OpenJDK'slibjimage.so
. After that, the destructor for the staticinstance_
object is run, which results in a call toDestroyJavaVM()
, which then loadsjava.lang.Shutdown
. Part of the class loading process is to check for image resources associated with the class. This check accesses the already destroyedImageFileReaderTable
, thereby causing a segfault. See https://bugzilla.redhat.com/show_bug.cgi?id=1858054 for more information.This commit is probably not the best solution, but it does avoid the segfault. The trick is that
atexit
-registered functions are run before global object destructors. Consider this more of a bug report with an ugly workaround attached than a real pull request. :-)