-
Notifications
You must be signed in to change notification settings - Fork 5.8k
8199149: Improve the exception message thrown by VarHandle of unsupported operation #14928
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
Conversation
👋 Welcome back mchung! A progress list of the required criteria for merging this PR into |
Webrevs
|
} | ||
|
||
static AccessMode valueFromOrdinal(int mode) { | ||
return modeToAccessMode.get(mode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't this be simplified to AccessMode.values()[mode]
since this is only rarely used in the exception logic?
If we do need a cache, I would recommend a stable array like
private static final @Stable AccessMode[] VALUES = values();
and users call this accessor instead.
The code in getMethodHandleUncached
can benefit from this caching mechanism.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion.
@@ -90,7 +90,9 @@ public VarHandle withInvokeBehavior() { | |||
@Override | |||
@ForceInline | |||
boolean checkAccessModeThenIsDirect(VarHandle.AccessDescriptor ad) { | |||
super.checkAccessModeThenIsDirect(ad); | |||
if (exact && accessModeType(ad.type) != ad.symbolicMethodTypeExact) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a comment that the detailed UOE is thrown via directTarget.getMethodHandleUncached
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually VarHandle::checkAccessModeThenIsDirect
can call isAccessModeSupported
so that this will check properly for IndirectVarHandle
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change VarHandle::checkAccessModeThenIsDirect to check if the access mode is unsupported. This check is only needed for direct var handle.
Note that IndirectVarHandle
calls super.checkAccessModeThenIsDirect
, so it ends up doing the check any way, I think?
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two new imports seem unused.
In the initial patch, it was distinct; it was migrated to call |
Just curious, why does Paul Sandoz recommend removing the VarHandle itself from the UOE message? |
I got feedback from @PaulSandoz. The patch is updated to include only the access mode information.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The enum values caching can be applied to AccessType
as well; can be done in a separate patch, and I've created ticket at https://bugs.openjdk.org/browse/JDK-8312423.
Also just noticed copyright year of VarForm is still 2019; should be updated to 2023 with this patch. |
@@ -1,5 +1,5 @@ | |||
/* | |||
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved. | |||
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you've updated the wrong copyright header?
@mlchung 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:
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 43 new commits pushed to the
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 |
private static final @Stable AccessMode[] VALUES = values(); | ||
static AccessMode valueFromOrdinal(int mode) { | ||
return VALUES[mode]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I'll throw this out there, though I'm not sure how big of an issue it is: this array creation might have an effect on startup. But, since it is only used on a slow path right before we throw an exception (at least, at the moment), calling values()
every time inside the valueFromOrdinal
method, and avoiding the array creation on startup, might be 'better'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a worthy change: see https://github.com/openjdk/jdk/pull/14943/files#diff-556b309ea2df3f5bfe8229de944183ef19750ce4511d0328cd59af2ce2b61ae2R135
that VarHandle.AccessMode.values()
is called every time a polymorphic VH call is linked.
If the startup cost from array allocation is really problematic, we can make it stable and allocate VALUES
on demand (at valueFromOrdinal
calls).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so it looks like we are creating this array already, in adding the valueFromOrdinal
method allows sharing. That sounds good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The overhead is just one time allocation of an array of length 31, which is a very small array which I don't think such small array creation impacts as much.
I should have replaced other uses of AccessMode.values()
. I will include that change in this patch.
@liach I don't know about AccessType.values()
which seems to me not worth the change to add valueFromOrdinal
as only calls that 6 times.
/integrate |
Going to push as commit d7b9416.
Your commit was automatically rebased without conflicts. |
VarForm::getMemberName
currently throws UOE with no information if the requested access mode is unsupported. To provide the var handle information, move the access mode check toVarHandle
so that the exception message can include the var handle information. Changes include:VarHandle::checkAccessModeThenIsDirect
to check if the access mode is unsupported. This check is only needed for direct var handle.VarHandle::getMethodHandleUncached
to callgetMemberNameOrNull
and throw UOE with an informative exception message if the access mode is unsupportedThe error message looks like:
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/14928/head:pull/14928
$ git checkout pull/14928
Update a local copy of the PR:
$ git checkout pull/14928
$ git pull https://git.openjdk.org/jdk.git pull/14928/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 14928
View PR using the GUI difftool:
$ git pr show -t 14928
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/14928.diff
Webrev
Link to Webrev Comment