[lworld] RFR: JDK-8247663: [lworld] LambdaMetaFactory should allow an inline value projection type to convert to its reference projection type
Roger Riggs
rriggs at openjdk.java.net
Wed Jul 8 18:27:03 UTC 2020
On Wed, 1 Jul 2020 17:19:17 GMT, Mandy Chung <mchung at openjdk.org> wrote:
> This patch fixes `LambdaMetaFactory` to allow inline value projection type to convert to its reference projection type.
>
> `Class::isAssignableFrom` and `Class::asSubclass` are the APIs to determine if a given type can be safely cast to this
> Class.
> - Class::isAssignableFrom tests if a given type can be converted to this Class via a widening reference conversion.
> - Class::asSubclass tests if a given type can be converted to this Class via a narrowing conversion.
>
> The current thought is to keep `Class::isAssignableFrom` and `Class::asSubclass` to respect the class file hierarchy
> and a cast is needed when converting from `V.val` to `V.ref`. `LambdaMetaFactory` and other frameworks will need to
> extend the type adaptability check to support inline types. I considered adding `Class::isConvertibleFrom` method but
> we should wait for more use cases proving the need of such convenience method. This check can be done by calling
> `Class::referenceType` and `Class::valueType`.
Marked as reviewed by rriggs (Committer).
test/jdk/valhalla/valuetypes/InlineTypeConversionTest.java line 87:
> 86: Object v1 = mh.invoke((Object)null);
> 87: assertTrue(false);
> 88: } catch (NullPointerException e) {
Isn't this just Assert.fail("message");
src/java.base/share/classes/java/lang/invoke/AbstractValidatingLambdaMetafactory.java line 398:
> 397: */
> 398: private boolean canConvert(Class<?> fromType, Class<?> toType) {
> 399: if (toType.isAssignableFrom(fromType)) {
Can this be a static method?
src/java.base/share/classes/java/lang/invoke/AbstractValidatingLambdaMetafactory.java line 402:
> 401: }
> 402:
> 403: if (!fromType.isInlineClass() && !toType.isInlineClass()) {
Since fromType.valueType is an Optional<Class<?>> the code could be rearranged to use is Present() and not double check
for inline so many times. If it is a performance issue it should be refactored to do the complete check of one case
before the other.
-------------
PR: https://git.openjdk.java.net/valhalla/pull/102
More information about the valhalla-dev
mailing list