[foreign-memaccess] RFR 8225172: Add way to create deref VarHandles without using the Layout API
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Thu Jun 13 15:56:47 UTC 2019
On 13/06/2019 16:40, Jorn Vernee wrote:
> Updated webrev:
> https://cr.openjdk.java.net/~jvernee/panama/webrevs/8225172/webrev.04/
>
> The sizeOf(Class) call was also implicitly doing a carrier type check,
> so I'm now doing that explicitly in
> MemoryAccessVarHandles::dereferenceVarHandle and
> LayoutPathImpl::dereferenceVarHandle instead, and added a test case
> for this as well.
Looks nice...
Of these two checks:
if (!carrier.isPrimitive() || carrier == void.class || carrier ==
boolean.class) {
+ throw new IllegalArgumentException("Illegal carrier: " +
carrier.getSimpleName());
+ }
+
+ if (Wrapper.forPrimitiveType(carrier).bitWidth() !=
layout.bitsSize()) {
+ throw new IllegalArgumentException("Invalid carrier: " +
carrier + ", for layout " + layout);
+ }
The former seems redundant. BitWidth of void is zero, and the
ValueLayout API throws IAE if size is 0.
So I would rewrite as this:
Wrapper wrapper = Wrapper.forPrimitiveType(carrier);
if (wrapper == null || //not a primitive
wrapper.bitWidth() != layout.bitSize()) { //incompatible sizes (or
void carrier!)
throw new IllegalArgumentException(...)
}
And, again, if you check the carrier both in MemoryAccessVarHandles, and
in LayoutPath, I don't see the need for checking it in VarHandles.
Maurizio
More information about the panama-dev
mailing list