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

8263138: Initialization of sun.font.SunFontManager.platformFontMap is not thread safe #2762

Conversation

turbanoff
Copy link
Member

@turbanoff turbanoff commented Feb 27, 2021


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8263138: Initialization of sun.font.SunFontManager.platformFontMap is not thread safe

Reviewers

Download

$ git fetch https://git.openjdk.java.net/jdk pull/2762/head:pull/2762
$ git checkout pull/2762

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 27, 2021

👋 Welcome back turbanoff! 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 Feb 27, 2021

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

  • 2d

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 2d label Feb 27, 2021
if (platformFontMap == null) {
platformFontMap = populateHardcodedFileNameMap();
SunFontManager.platformFontMap = platformFontMap;
Copy link
Member

@mrserb mrserb Feb 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure it is enough for "thread-safe initialization". The "platformFontMap" might not be null, but its content can be broken/incomplete at this point.

Copy link
Contributor

@liach liach Feb 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#2691 (comment)

In short, previously platformFontMap references were field set/gets and may be inconsistent due to concurrency. It is now moved to a local variable; also the map modifications have been moved to fields to avoid concurrency issues with hash map as far as I can see.

Copy link
Member

@mrserb mrserb Feb 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thread may create the local platformFontMap, then set the static SunFontManager.platformFontMap field, and then initialize the platformFontMap or mix these operations. The second thread may see non-null SunFontManager.platformFontMap which is not still initialized.

Copy link
Member Author

@turbanoff turbanoff Feb 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made volatile to guarantee memory visibility if thread saw non-null value.

Copy link
Member

@mrserb mrserb Mar 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have any other questions, will file a bug and run the tests.

@mrserb
Copy link
Member

mrserb commented Mar 7, 2021

@prrace
Copy link
Contributor

prrace commented Mar 7, 2021

I don't know why making this volatile is doing anything.
Let's discuss this further.

@turbanoff turbanoff changed the title [PATCH] Thread-safe initialization of SunFontManager.platformFontMap 8263138 Initialization of sun.font.SunFontManager.platformFontMap is not thread safe Mar 7, 2021
@turbanoff turbanoff changed the title 8263138 Initialization of sun.font.SunFontManager.platformFontMap is not thread safe 8263138: Initialization of sun.font.SunFontManager.platformFontMap is not thread safe Mar 7, 2021
@openjdk openjdk bot added the rfr label Mar 7, 2021
@mlbridge
Copy link

mlbridge bot commented Mar 7, 2021

Webrevs

@openjdk
Copy link

openjdk bot commented Mar 9, 2021

@turbanoff This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8263138: Initialization of sun.font.SunFontManager.platformFontMap is not thread safe

Reviewed-by: aivanov, kizune, serb

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 146 new commits pushed to the master branch:

  • 32cbd19: 8263105: security-libs doclint cleanup
  • 6971c23: 8262351: Extra '0' in java.util.Formatter for '%012a' conversion with a sign character
  • c6d74bd: 8262910: Cleanup THREAD/TRAPS/naming and typing issues in ObjectMonitor and related code
  • 57f16f9: 8262377: Parallel class resolution loses constant pool error
  • b482733: 8259218: (fs) Add links in from overloaded methods in java.nio.file.Files
  • acda812: 8263333: Improve links from core reflection to JLS and JVMS
  • 9399e1b: 8261918: two runtime/cds/appcds/VerifierTest failed with "Unable to use shared archive"
  • 7e52a6e: 8263380: Unintended use of Objects.nonNull in VarHandles
  • 4b5be40: 8238812: assert(false) failed: bad AD file
  • b2a2ddf: 8262438: sun/security/ssl/SSLLogger/LoggingFormatConsistency.java failed with "SocketException: Socket is closed"
  • ... and 136 more: https://git.openjdk.java.net/jdk/compare/03d888f463c0a6e3fee70ed8ad606fc0a3082636...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@aivanov-jdk, @azuev-java, @mrserb) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready label Mar 9, 2021
@mrserb
Copy link
Member

mrserb commented Mar 9, 2021

I don't know why making this volatile is doing anything.
Let's discuss this further.

It will prevent the possibility that one thread will store the non-null value to the SunFontManager.platformFontMap and only after that complete initialization of object stored in that field due to code optimizations. It is similar to the volatile DCL:
see "broken multithreaded version" example:
https://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Java

mrserb
mrserb approved these changes Mar 10, 2021
@turbanoff
Copy link
Member Author

turbanoff commented Mar 11, 2021

/integrate

@openjdk openjdk bot added the sponsor label Mar 11, 2021
@openjdk
Copy link

openjdk bot commented Mar 11, 2021

@turbanoff
Your change (at version f1911b4) is now ready to be sponsored by a Committer.

@mrserb
Copy link
Member

mrserb commented Mar 12, 2021

@prrace Do you have any objections to integrating this change?

@mrserb
Copy link
Member

mrserb commented Mar 20, 2021

/sponsor

@openjdk openjdk bot closed this Mar 20, 2021
@openjdk openjdk bot added integrated and removed sponsor ready rfr labels Mar 20, 2021
@openjdk
Copy link

openjdk bot commented Mar 20, 2021

@mrserb @turbanoff Since your change was applied there have been 297 commits pushed to the master branch:

  • 5b8233b: 8263871: On sem_destroy() failing we should assert
  • 96e5c3f: 8263890: Broken links to Unicode.org
  • 4d9517d: 8263834: Work around gdb for HashtableEntry
  • 6fa6557: 8263825: Remove unused and commented out member from NTLMException
  • 77ebc11: 8263892: More modifier order fixes in java.base
  • 80d3ea0: 8263885: Use the blessed modifier order in java.sql/rowset/transation.xa
  • 6737135: 8262083: vmTestbase/nsk/jvmti/SetEventNotificationMode/setnotif001/TestDescription.java failed with "No notification: event JVMTI_EVENT_FRAME_POP (61)"
  • 57fc8e9: 8262080: vmTestbase/nsk/jdi/Event/request/request001/TestDescription.java failed with "ERROR: new event is not ThreadStartEvent"
  • 0b5216a: 8263545: Convert jpackage to use Stream.toList()
  • ed701ea: 8262271: SA: Add new stress test that tests getting the stack trace of an active thread
  • ... and 287 more: https://git.openjdk.java.net/jdk/compare/03d888f463c0a6e3fee70ed8ad606fc0a3082636...master

Your commit was automatically rebased without conflicts.

Pushed as commit ab66d69.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@turbanoff turbanoff deleted the thread_safe_initialization_of_SunFontManager.platformFontMap branch Sep 15, 2021
@openjdk openjdk bot added the client label Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2d client integrated
6 participants