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

8346195: Fix static initialization problem in GDIHashtable #22736

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

magicus
Copy link
Member

@magicus magicus commented Dec 13, 2024

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 field GDIHashtable::BatchDestructionManager manager, which is initialized in GDIHashtable.cpp.

In AwtPen, there is a static field GDIHashtable cache, which is initialized in awt_Pen.cpp.

The GDIHashtable constructor calls manager.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

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8346195: Fix static initialization problem in GDIHashtable (Bug - P2)

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

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 13, 2024

👋 Welcome back ihse! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Dec 13, 2024

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 13, 2024
@openjdk
Copy link

openjdk bot commented Dec 13, 2024

@magicus The following label will be automatically applied to this pull request:

  • client

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the client client-libs-dev@openjdk.org label Dec 13, 2024
@mlbridge
Copy link

mlbridge bot commented Dec 13, 2024

Webrevs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client-libs-dev@openjdk.org rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

1 participant