8346195: Fix static initialization problem in GDIHashtable #22736
+12
−11
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.
There has been a latent problem in
GDIHashtable
since time immemorial, but due to sheer luck it has not caused any issues for us. However, I managed to provoke it when I was doing some build changes.This is the problem:
In
GDIHashtable
, there is a static fieldGDIHashtable::BatchDestructionManager manager
, which is initialized inGDIHashtable.cpp
.In
AwtPen
, there is a static fieldGDIHashtable cache
, which is initialized inawt_Pen.cpp
.The
GDIHashtable
constructor callsmanager.add(this)
.For this to work, the manager must have been initialized prior to the AwtPen. However, the order of which static initializers are run between different compilation units are not well-defined, and we've just been lucky so far that it works.
This problem is known as the "Static Initialization Order Fiasco", see e.g. https://en.cppreference.com/w/cpp/language/siof
I have solved this by encapsulating the static manager instance in a method, which guarantees that it has been initialized before use. This seemed to me to be the cleanest solution.
Progress
Issue
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/22736/head:pull/22736
$ git checkout pull/22736
Update a local copy of the PR:
$ git checkout pull/22736
$ git pull https://git.openjdk.org/jdk.git pull/22736/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 22736
View PR using the GUI difftool:
$ git pr show -t 22736
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/22736.diff
Using Webrev
Link to Webrev Comment