[9] RFR [XS] 8054492: Casting can result in redundant null checks in generated code

David Chase david.r.chase at oracle.com
Wed Oct 15 18:11:05 UTC 2014


The changes look good to me;
did you find anything more out about Paul Sandoz’s problem?

David


On 2014-10-14, at 4:15 PM, Vladimir Kozlov <vladimir.kozlov at oracle.com> wrote:

> Thank you, Paul
> 
> I will look on that.
> 
> Vladimir
> 
> On 10/14/14 9:58 AM, Paul Sandoz wrote:
>> Here is a simpler test case that just uses a MH to Class.cast that exhibits the same behaviour.
>> 
>> The commented out use of the BiFunction created from a lambda expressions works fine.
>> 
>> This suggests there might be something about the MH invocation that is stopping the optimization from kicking in.
>> 
>> Paul.
>> 
>> import java.lang.invoke.MethodHandle;
>> import java.lang.invoke.MethodHandles;
>> import java.lang.invoke.MethodType;
>> import java.util.function.BiFunction;
>> 
>> public class NullCheckDroppingsMHCastTest {
>> 
>>     static final MethodHandle MH_CAST;
>> 
>>     static {
>>         try {
>>             MH_CAST = MethodHandles.lookup().findVirtual(Class.class,
>>                                                          "cast",
>>                                                          MethodType.methodType(Object.class, Object.class));
>>         }
>>         catch (Exception e) {
>>             throw new Error(e);
>>         }
>>     }
>> 
>>     static final BiFunction<Class, Object, Object> fCast = (c, o) -> c.cast(o);
>> 
>> 
>>     volatile String svalue = "A";
>>     volatile String snull = null;
>>     String ssink;
>> 
>>     public static void main(String[] args) {
>>         NullCheckDroppingsMHCastTest t = new NullCheckDroppingsMHCastTest();
>>         t.testLoop();
>>     }
>> 
>>     void testLoop() {
>>         // Ensure testLoopOne is compiled and does not
>>         // see a null value
>>         for (int i = 0; i < 1000000; i++) {
>>             testLoopOne(svalue);
>>             // Uncomment the following and the call outside
>>             // the loop should not result in any deoptimization
>>             // testLoopOne(snull);
>>         }
>> 
>>         // Sleep just to create delay in the compilation log
>>         try {
>>             Thread.currentThread().sleep(1000);
>>         }
>>         catch (Exception e) {
>>         }
>> 
>>         // This should cause a de-optimisation
>>         // if testLoopOne is compiled with a null-check
>>         testLoopOne(snull);
>>     }
>> 
>>     void testLoopOne(String s) {
>>         try {
>>             ssink = (String) (Object) MH_CAST.invokeExact(String.class, (Object) s);
>> //            ssink = (String) fCast.apply(String.class, s);
>>         }
>>         catch (Throwable t) {
>>             throw new Error(t);
>>         }
>>     }
>> }
>> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20141015/c31f451c/signature.asc>


More information about the hotspot-compiler-dev mailing list