8396438: AArch64: Remove unnecessary checks for CPU_ASIMD feature #33704
<!-- Welcome message -->
:wave: Welcome back adinn! 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.
❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.
<!-- PullRequestBot merge is ready comment -->
<!-- PullRequestBot placeholder -->
@adinn The following label will be automatically applied to this pull request:
hotspotWhen 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.
<!-- PullRequestBot initial label help comment -->
<!-- PullRequest Bot label commit '07a9c53b951101fb1c176aa01e84cc05c55c6150' -->
The total number of required reviews for this PR has been set to 2 based on the presence of this label: hotspot. This can be overridden with the /reviewers command.
<!-- additional required reviewers id marker (2) (authors) (bot)-->
<!-- two-reviewers applied -->
Please use FLAG_SET_DEFAULT() macro in these changes to match other parts of code.
Drive-by comment but these checks don't make any sense to me. The default value of the flags being checked is already true so setting them to true is just redundant.
Sorry my mistake I was checking a fastdebug build. But in that case what we have still doesn't make sense. We are basically saying we assume we always have CPU_ASIMD so we will always set the flag to true, even though it is listed as a default of false. So we may as well just change the default to true and drop the code to check it.
I'm not sure why this would be any different in a fastdebug build.
This is a generic flag that controls the use of generated intrinsic code.
$ grep -r UseChaCha20Intrinsics src/hotspot/share/
src/hotspot/share/classfile/vmIntrinsics.cpp: if (!UseChaCha20Intrinsics) return true;
. . .
src/hotspot/share/runtime/globals.hpp: product(bool, UseChaCha20Intrinsics, false, DIAGNOSTIC, \
It has to be set to false by default because not all architectures implement the intrinsic. The resetting of the default to true on an architecture which supports the intrinsic has to happen in arch-specific code (specifically in the vm_version implementation file). Hence the need for the above code.
@vnkozlov I updated all the previously modified locations to use FLAG_SET_DEFAULT(). I then found that there were a lot of other places where a FLAG_IS_DEFAULT() test was followed by a bare assignment so I updated them too.
I noticed two places where a direct assignment was done in an else clause i.e. UseSVE = 0 and MaxVectorSize = new_vl.
Neither of these is a direct else clause for a FLAG_IS_DEFAULT() test. That said, I believe they are both ok because they represent an explicit decision to repair an erroneous configuration rather than a simple reset of a default. However, I'll be happy to follow your guidance on that.
What @adinn said. It is a generic flag which should be set separately for each platform which support it.
Looks good. I will submit our testing.
My testing passed.
Sorry I missed the generic nature of the flag.
I'm not sure I see a reason to make this kind of change given that FLAG_SET_DEFAULT does not change the origin value of the flag. Why it doesn't set the origin perplexes me. That aside if we are making a conscious decision to adjust flags based on available capabilities shouldn't we be using FLAG_SET_ERGO here?
I fear our flag handling code is very messy and inconsistent.
@dholmes-ora
shouldn't we be using FLAG_SET_ERGO here?
That sounds probable. I'm very happy to be guided by you and @vnkozlov here.
I think in some of the cases I changed, i.e. where we see the reset of a generic intrinsic flag to a cpu-specific variant, the re-assignment is adjusting a 'presumed default' to the 'correct default' for the platform. In those cases I suggest it is correct to use FLAG_SET_DEFAULT because a subsequent FLAG_IS_DEFAULT test (if there is one) should not see this sort of update as having left the flag in a non-default state.
In other cases -- perhaps indeed the one you mention here -- I'm not sure whether the reset is meant to preserve the 'defaultness' of the flag or meant to mark it as having changed. What does FLAG_SET_ERGO mean in terms of any subsequent FLAG_IS_DEFAULT test. Perhaps you can clarify that?
I fear our flag handling code is very messy and inconsistent.
That is undoubtedly true given the number of bare 'reset' assignments already found in this file. ;-(
On the plus side, having stumbled on the problem we now have a chance to record some of the constraints and fix at least some of the errors (n.b. I'm honestly trying to be positive without resorting to platitudes about all problems being opportunities, clouds having silver linings, etc, etc ;-)
I agree with @adinn here. When we set a generic flag based on current CPU feature we should use FLAG_SET_DEFAULT. Using FLAG_SET_ERGO to set flag setting based on some other properties should be done separately. It should be discussed in detail when and where it should be done. Definitely not in these changes.
I think we are hitting the classic problem with flag management: in the query FLAG_IS_DEFAULT the term DEFAULT does not relate to the value of the flag but to the origin of the flag i.e. where it was set.
in the query FLAG_IS_DEFAULT the term DEFAULT does not relate to the value of the flag but to the origin of the flag i.e. where it was set.
@dholmes-ora I'm not sure I am following you correctly here but I think that observation was priced into my previous comment and that of @vnkozlov.
What I take you to be saying is that FLAG_IS_DEFAULT reports whether the flag has had its value reset after its initial assignment during construction via the wrapper which tracks changes. So, it is not about recording what it was reset to but the fact of its having been updated at all. Is that correct?
Two qualifications:
- As described above this would allow a flag to be 'reset' with the same value as the default and still look like it had been changed. Is that a possibility? I'm assuming not i.e. that we only mark a departure from the default setting when a 'reset' to some other value occurs.
- I'm also assuming that the point of FLAG_SET_DEFAULT is to change a 'default' setting to something else without it looking as if the value has been reset i.e. to update the setting yet still allow a subsequent FLAG_IS_DEFAULT test to return true.
That was the basis for my suggestion that we should use FLAG_SET_DEFAULT when overriding a generic intrinsic default of false with a cpu-specific intrinsic default of true. If I am reading your comment above correctly then I think my suggestion takes what it emphasises into account. If not then could you please clarify where I have misunderstood you and/or whatever difference is at play in the way that the flag tracking code is supposed to operate?
What I take you to be saying is that FLAG_IS_DEFAULT reports whether the flag has had its value reset after its initial assignment during construction via the wrapper which tracks changes. So, it is not about recording what it was reset to but the fact of its having been updated at all. Is that correct?
It returns true if the flags ORIGIN is still DEFAULT, irrespective of what the actual value of the flag currently is.
As described above this would allow a flag to be 'reset' with the same value as the default and still look like it had been changed. Is that a possibility? I'm assuming not i.e. that we only mark a departure from the default setting when a 'reset' to some other value occurs.
That would be the expected usage yes - though nothing enforces that. A typical usage would be to switch the flag from its default value under specific conditions:
if (flag && someCondition()) {
FLAG_SET_ERGO(flag, false);
}
though those conditions may also include "unless the user set it on the command-line" for which FLAG_IS_DEFAULT may be used as a proxy (as long as we process everything in the right order).
I'm also assuming that the point of FLAG_SET_DEFAULT is to change a 'default' setting to something else without it looking as if the value has been reset i.e. to update the setting yet still allow a subsequent FLAG_IS_DEFAULT test to return true.
I don't know what point it serves. Given FLAG_SET_ERGO sets the origin to ERGO one might reasonably expect that FLAG_SET_DEFAULT sets the origin to DEFAULT - but it doesn't. If you want to change the value without changing the origin then that is what direct assignment does: flag = x;.
So to me direct assignment for a cpu-specific default is preferable to using FLAG_SET_DEFAULT. If we want something that keeps the DEFAULT origin and updates the value and is highly visible in the code, then the following would seem a better idiom to me:
#define FLAG_SET_IF_DEFAULT(flag, val) if (FLAG_IS_DEFAULT(flag)) flag = val;
Bottom line is I don't think some of the changes in the PR were necessary and I question the claim they are "better", but as the saying goes I'm not trying, or willing, to die on this hill. Flag management is a mess, and complicated and we can't solve that here.
> I'm also assuming that the point of FLAG_SET_DEFAULT is to change a 'default' setting to something else without it looking as if the value has been reset i.e. to update the setting yet still allow a subsequent FLAG_IS_DEFAULT test to return true.
> I don't know what point it serves. GivenFLAG_SET_ERGOsets the origin toERGOone might reasonably expect thatFLAG_SET_DEFAULTsets the origin toDEFAULT- but it doesn't. If you want to change the value without changing the origin then that is what direct assignment does: flag = x;.
> So to me direct assignment for a cpu-specific default is preferable to using FLAG_SET_DEFAULT.
Well, yes, a direct assignment does not change the status of the value and indeed neither does FLAG_SET_DEFAULT as currently defined:
#define FLAG_SET_DEFAULT(name, value) ((name) = (value))
So, whatever difference we might be discussing here arises only in terms of 'presentational' semantics rather than any program semantic. n.b. by that term I merely mean to clarify the target of the discussion here. I don't want to deprecate having code that signals intent -- quite the opposite.
If we want something that keeps the DEFAULT origin and updates the value and is highly visible in the code, then the following would seem a better idiom to me:
> #define FLAG_SET_IF_DEFAULT(flag, val) if (FLAG_IS_DEFAULT(flag)) flag = val; >
I am not sure this signals the intention more clearly rather than the (program-)semantically equivalent code we currently have e.g, we can certainly replace the current
if (FLAG_IS_DEFAULT(UseSignumIntrinsic)) {
FLAG_SET_DEFAULT(UseSignumIntrinsic, true);
}
with the semantically equivalent
FLAG_SET_IF_DEFAULT(UseSignumIntrinsic, true);
but I think this actually makes it less clear what is going on. The former makes an explicit statement that status of the new value after reassignment is still that of a DEFAULT. The latter leaves it implicit.
@dholmes-ora Are you willing to approve this PR or do I need to make some changes?
Just an observation but shouldn't this then be declared as a "pd" flag so that each platform can directly declare its own default value?
Approved with mild reluctance. :) Thanks
Yes, I think that is probably how it ought to be done. However, I think the fact that it is done the current way reflects a pragmatic compromise (not trying to take a side here, just observing the status quo). The considerations influencing that compromise are as follows:
1. Flags which reflect the availability of intrinsics, such as UseChaCha20Intrinsics, need to be global because they are accessed by generic (compiler) code.
2. Any stub generator code whose action is gated by the flag setting is always arch-specific.
3. Historically may of these intrinsic flags that have only been implemented by a subset of architectures i.e. there is no corresponding generator routine.
So, if a pd_product declaration were employed to declare, say, UseChaCha20Intrinsics then every architecture would need to provide a define_pd_global defaulting that intrinsic flag (situated in the generator code), even when it did not implement the intrinsic, while still retaining the existing logic to ensure that it is not mistakenly enabled on the command line (situated in the vm_version code). The compromise uses a common declaration, avoiding a dangling define_pd_global that applies to non-existent code, and supplements the logic that tests for invalid settings with a reset of the default (all in the vm_version code).
I'm not averse to 'fixing' this the way you suggest at some point but . . . not here ;-)
Thank you for the review!
@vnkozlov Could you re-review this following the merge?
Yes I see that now. All platforms get the shared global flag in a disabled state; platforms that support it then opt-in by flipping the value at runtime. I wonder if we can augment the pd flag handling so that it acts the same way ... something to think on.
vnkozlov
adinn
Trivial fix to remove all tests of CPU_ASIMD during argument processing, replacing them with an assert that the feature is present.
---------
<!-- Anything below this marker will be automatically updated, please do not edit manually! -->
---------
Progress
Issue
JDK-8396438: AArch64: Remove unnecessary checks for CPU_ASIMD feature (Enhancement - P4)
Reviewers
Vladimir Kozlov (@vnkozlov - Reviewer) 🔄 Re-review required (review applies to a807924b)
* David Holmes (@dholmes-ora - Reviewer)
Reviewing
<details><summary>Using <code>git</code></summary>
Checkout this PR locally: \
$ git fetch https://git.openjdk.org/jdk.git pull/33704/head:pull/33704\$ git checkout pull/33704Update a local copy of the PR: \
$ git checkout pull/33704\$ git pull https://git.openjdk.org/jdk.git pull/33704/head</details>
<details><summary>Using Skara CLI tools</summary>
Checkout this PR locally: \
$ git pr checkout 33704View PR using the GUI difftool: \
$ git pr show -t 33704</details>
<details><summary>Using diff file</summary>
Download this PR as a diff file: \
<a href="https://git.openjdk.org/jdk/pull/33704.diff">https://git.openjdk.org/jdk/pull/33704.diff</a>
</details>
<details><summary>Using Webrev</summary>
Link to Webrev Comment
</details>