RFR (S): 8153540: C2 intrinsic for Unsafe.allocateInstance doesn't properly filter out array classes
vladimir.x.ivanov at oracle.com
Mon Apr 11 11:07:26 UTC 2016
Thanks for the feedback, Vladimir.
> > Unsafe.allocateInstance intrinsic can instantiate arrays, but the
> allocation logic is broken.
> But it should not allocate arrays. Right? This is what your java changes
> do now.
Yes, instance allocation logic doesn't work for arrays. It allocates
broken array instances. That's why I decided to filter out arrays.
> Should it be allocateInstance0 ?:
> + // public native Object Unsafe.allocateInstance(Class<?> cls);
- public native Object allocateInstance(Class<?> cls)
- throws InstantiationException;
+ private native Object allocateInstance0(Class<?> cls) throws
> You removed next stop check. Is it because java code will cat the NULL?:
> Node* cls = null_check(argument(1));
> if (stopped()) return true;
Yes, cls.isPrimitive() does null checks on both cls and klass.
> The test misses bug number @bug
Ok, will add.
> Vladimir K
> On 4/8/16 9:47 AM, Vladimir Ivanov wrote:
>> Unsafe.allocateInstance intrinsic can instantiate arrays, but the
>> allocation logic is broken.
>> The proposed fix is to perform necessary checks in Java code before
>> calling the intrinsic.
>> I did some performance measurements  and reflection (non-constant
>> class) case (non-constant class) regressed ~5-10%
>> due to new guards added.
>> I also experimented with a hotspot-only fix , but it looks uglier.
>> So, if you consider the regression in reflective
>> case non-critical, I'd prefer to go with JDK checks.
>> Testing: regression test, JPRT, RBT (pit-hs-comp; in progress),
>> Best regards,
>> Vladimir Ivanov
>>  http://cr.openjdk.java.net/~vlivanov/8153540/AllocInstance.java
>> AllocInstance.testConstant avgt 25 3.736 ± 0.054 ns/op
>> AllocInstance.testReflective avgt 25 5.880 ± 0.080 ns/op
>> JDK fix:
>> AllocInstance.testConstant avgt 25 3.959 ± 0.205 ns/op
>> AllocInstance.testReflective avgt 25 6.274 ± 0.180 ns/op
>>  http://cr.openjdk.java.net/~vlivanov/8153540/webrev.slow_path
>> AllocInstance.testConstant avgt 25 3.957 ± 0.159 ns/op
>> AllocInstance.testReflective avgt 25 5.901 ± 0.057 ns/op
More information about the hotspot-compiler-dev