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

8277216: Examine InstanceKlass::_misc_flags for concurrency issues #6851

Closed
wants to merge 5 commits into from

Conversation

coleenp
Copy link
Contributor

@coleenp coleenp commented Dec 15, 2021

Recent bug in misc_flags showed that they are not set concurrently and could cause bugs. Most of the misc_flags are set at classfile parsing time or at a safepoint and never reset. This change adds an assert that the flag is set once. See CR for more details.
Tested with tier1-3.


Progress

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

Issue

  • JDK-8277216: Examine InstanceKlass::_misc_flags for concurrency issues

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/6851/head:pull/6851
$ git checkout pull/6851

Update a local copy of the PR:
$ git checkout pull/6851
$ git pull https://git.openjdk.java.net/jdk pull/6851/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 6851

View PR using the GUI difftool:
$ git pr show -t 6851

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/6851.diff

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Dec 15, 2021

👋 Welcome back coleenp! 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 openjdk bot added the rfr label Dec 15, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Dec 15, 2021

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

  • hotspot

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 hotspot label Dec 15, 2021
@mlbridge
Copy link

@mlbridge mlbridge bot commented Dec 15, 2021

Webrevs

Copy link
Member

@hseigel hseigel left a comment

The changes look good.
Harold

@openjdk
Copy link

@openjdk openjdk bot commented Dec 15, 2021

@coleenp 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:

8277216: Examine InstanceKlass::_misc_flags for concurrency issues

Reviewed-by: hseigel, dholmes

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 21 new commits pushed to the master branch:

  • 8f5fdd8: 8278587: StringTokenizer(String, String, boolean) documentation bug
  • 20db780: 8277868: Use Comparable.compare() instead of surrogate code
  • 937126b: 8278551: Shenandoah: Adopt WorkerThread::worker_id() to replace Shenandoah specific implementation
  • f15a59c: 8278756: Parallel: Drop PSOldGen::_reserved
  • 271d26f: 8278601: Parallel: Remove redundant code in ObjectStartArray::initialize
  • e0700bf: 8278763: Parallel: Remove grows_up/grows_down in PSVirtualSpace
  • aae5639: 8278642: Refactor java.util.Formatter
  • 7edcd34: 8278534: Remove some unnecessary code in MethodLiveness::init_basic_blocks
  • 0bddd8a: 8278050: Armenian text isn't rendered on macOS if text layout is performed
  • f6fbb5a: 8278471: Remove unreached rules in AddNode::IdealIL
  • ... and 11 more: https://git.openjdk.java.net/jdk/compare/04dbdd36dd04bf40737cb8c2f13d5b75303d2b1a...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.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready label Dec 15, 2021
@dholmes-ora
Copy link
Member

@dholmes-ora dholmes-ora commented Dec 16, 2021

Hi Coleen,

I like the intent here but the assertions only partially work. Given something like:

void set_has_nonstatic_fields(bool b)    {
assert(!has_nonstatic_fields(), "set once");

then you can still call the set function multiple times if passing false as the argument.

@dholmes-ora
Copy link
Member

@dholmes-ora dholmes-ora commented Dec 16, 2021

Could we not simply reserve the _misc_flags for only those properties set at class parsing and then consider them "frozen" with a new debug field bool _misc_flags_frozen that we can check in an assertion in the various set functions?

@dholmes-ora
Copy link
Member

@dholmes-ora dholmes-ora commented Dec 16, 2021

Or ... assuming these flags are always off by default and only ever turned on, then the set functions should not be taking any argument and should just simply set the given flag bit. Then the asserts would work fine.

@coleenp
Copy link
Contributor Author

@coleenp coleenp commented Dec 16, 2021

Setting misc_flags to false repeatedly isn't going to break anything wrt. concurrency.
If you look at the CR, there are misc_flags that are not set during parsing. We could separate them to parsing ones and not parsing ones (two u1 flags) maybe. Seemed not worth the effort.
I looked at making the setting functions for misc_flags not take a bool but then I'd have to do this in ClassFileParser, which seemed more verbose:
ik->set_has_nonstatic_fields(_field_info->_has_nonstatic_fields);
change to:
if (_field_info->_has_nonstatic_fields) {
set_has_nonstatic_fields();
}

So worse, for not a very compelling reason.

I'm actually not that happy with moving misc_flags (set has_resolved_methods) to access_flags in order to get atomic semantics. I want access flags to be things in the class file not control information (control information should be in the metadata instead). If I redid this change, that's what I'd do but it affects more than Klass access_flags.

Yes, except I can't because Method::_access_flags sets and resets atomic flags used during compilation and it would take more space to have a _misc_flags that's used atomically in Method.

This change helps us not fall into the trap that caused the bug that I recently fixed. It doesn't solve all future problems.

@dholmes-ora
Copy link
Member

@dholmes-ora dholmes-ora commented Dec 16, 2021

Setting misc_flags to false repeatedly isn't going to break anything wrt. concurrency.

Setting any of the bits concurrently is broken. If one piece of code is turning on bit N and another turning off bit M then the latter can cause the former to be lost.

Copy link
Member

@dholmes-ora dholmes-ora left a comment

There is more potential for tightening things up around these flags, but the additional assertions are a step in the right direction even if they don't guard against all possible changes that could lead to breakage.

Thanks,
David

@coleenp
Copy link
Contributor Author

@coleenp coleenp commented Dec 16, 2021

Setting misc_flags to false repeatedly isn't going to break anything wrt. concurrency.

Setting any of the bits concurrently is broken. If one piece of code is turning on bit N and another turning off bit M then the >latter can cause the former to be lost.

Yes, that's why I changed the code to do nothing if passed false.

Thanks for the code review, David.

@dholmes-ora
Copy link
Member

@dholmes-ora dholmes-ora commented Dec 17, 2021

Yes, that's why I changed the code to do nothing if passed false.

Sorry Coleen, that completely escaped my notice. :(

@coleenp
Copy link
Contributor Author

@coleenp coleenp commented Dec 17, 2021

Sorry Coleen, that completely escaped my notice. :(
Rarely does that happen.

Thanks for the code review Harold and David.
/integrate

@openjdk
Copy link

@openjdk openjdk bot commented Dec 17, 2021

Going to push as commit 3607a5c.
Since your change was applied there have been 31 commits pushed to the master branch:

  • abab173: 8278568: Consolidate filler objects
  • 6412d57: 8278560: X509KeyManagerImpl::getAliases might return a good key with others
  • 247ea71: 8278826: Print error if Shenandoah flags are empty (instead of crashing)
  • 8c73ec1: 8278891: G1: Call reset in G1RegionMarkStatsCache constructor
  • 634afe8: Merge
  • be6b90d: 8278574: update --help-extra message to include default value of --finalization option
  • aec1b03: 8278389: SuspendibleThreadSet::_suspend_all should be volatile/atomic
  • e82310f: 8278575: update jcmd GC.finalizer_info to list finalization status
  • 7ce4aa8: 8276982: VM.class_hierarchy jcmd help output and man page text needs clarifications/improvements
  • 197c9f5: 8268573: Remove expired flags in JDK 19
  • ... and 21 more: https://git.openjdk.java.net/jdk/compare/04dbdd36dd04bf40737cb8c2f13d5b75303d2b1a...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated label Dec 17, 2021
@openjdk openjdk bot closed this Dec 17, 2021
@openjdk openjdk bot removed ready rfr labels Dec 17, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Dec 17, 2021

@coleenp Pushed as commit 3607a5c.

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

@coleenp coleenp deleted the misc branch Dec 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot integrated
3 participants