On Thu, 29 Oct 2020 18:14:05 GMT, Jorn Vernee <jver...@openjdk.org> wrote:

>> Hi,
>> 
>> This patch adds an asExact() combinator to VarHandle, that will return a new 
>> VarHandle that performs exact type checks, similar to 
>> MethodHandle::invokeExact, to help developers catch inexact VarHandle usage, 
>> which can lead to performance degradation.
>> 
>> This is implemented using a boolean flag in VarForm. If the flag is set, the 
>> exact type of the invocation is checked against the exact type in the 
>> VarForm. If there is a mismatch, a WrongMethodTypeException is thrown.
>> 
>> Other than that, there is also an asGeneric() combinator added that does the 
>> inverse operation (thanks to Rémi for the suggestion). I've also added The 
>> `@Hidden` annotation to the VarHandleGuards methods, as well as a 
>> type-checking helper method called from the generic invocation lambda form, 
>> so that the stack trace we get points at the location where the VarHandle is 
>> being used.
>> 
>> Thanks,
>> Jorn
>> 
>> CSR link: https://bugs.openjdk.java.net/browse/JDK-8255375
>
> Jorn Vernee has updated the pull request with a new target base due to a 
> merge or a rebase. The incremental webrev excludes the unrelated changes 
> brought in by the merge/rebase. The pull request contains 12 additional 
> commits since the last revision:
> 
>  - Update Javadoc, and rename asExact and asGeneric to 
> withInvokeExactBehaviour and withInvokeBehaviour
>  - Merge branch 'master' into Exact_VarHandle
>  - Use AccessType ordinal in guard checks instead of the AccessMode ordinal
>  - Update accessModeType to use the AccessType ordinal directly.
>  - Add benchmarks
>  - - Update javadoc
>    - Make isExact() public
>  - Fixes failing tests, and enable verifier on Exact test
>  - Fix whitespace
>  - Comment out VarHandleGuards generator code
>  - Makes exactness a property of a VarHandle, not a VarForm, since the latter 
> are shared. Use handle.accessModeType to get the exact type of the VarHandle.
>  - ... and 2 more: 
> https://git.openjdk.java.net/jdk/compare/08226775...3c707bc7

Looks good. There is just one difference between the spec and implementation. 
The spec states: 
> If this VarHandle already has invoke{-exact} behaviour this VarHandle is 
> returned.

I prefer this behaviour, but feel free to update the spec if you like e.g. If 
... already has XXX then a new VH with exactly the same behaviour as this VH is 
returned.

I just realized i used "behaviour", the english spelling. We should use the US 
spelling, "behavior", which is more commonly used throughout the JDK 
documentation.

-------------

Marked as reviewed by psandoz (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/843

Reply via email to