RFR (S) 8150102: C1 should fold arraylength for constant/trusted arrays

Aleksey Shipilev aleksey.shipilev at oracle.com
Thu Feb 18 13:20:31 UTC 2016

On 02/18/2016 03:56 PM, Vladimir Ivanov wrote:
>>   http://cr.openjdk.java.net/~shade/8150102/webrev.01/
> Why don't you fold as_LoadField into the assert?

Because "lf->field()" is polled from as_LoadField:

  } else if ((lf = x->array()->as_LoadField()) != NULL) {
    // GraphBuilder should emit Constants in static final case,
    //let's assert that.
    ciField* field = lf->field();
    assert (!(field->is_constant() && field->is_static()),
            "Array loads from static final fields should be handled as

Granted, we can construct a convoluted short-circuiting boolean
expression that folds that, but I think explicitly matching the "type"
is cleaner (sucks that our code does not have proper pattern matching).

> Also, field->is_static() is redundant: ciField::initialize_from does all
> necessary checks.

No, it isn't redundant: is_constant() is TRUE for trusted non-static
finals, like String.value. The old code predicated on is_static() to
pull the constant value without having an instance to introspect.
Perhaps, we need to fold (is_constant == TRUE, is_static == FALSE) loads
during parsing too to make a stronger assertion?

> Something like:
> +  } else {
> +    assert(x->array()->as_LoadField() == NULL || !field->is_constant(),
> "constant field loads are folded during parsing");
> +  }

The assert message is good though, stole that!



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20160218/869066af/signature.asc>

More information about the hotspot-compiler-dev mailing list