hg: valhalla/valhalla: 8198748: [lworld] Javac should insert null checks at casts to value types.

Srikanth srikanth.adayapalam at oracle.com
Mon Mar 12 06:32:13 UTC 2018



On Monday 12 March 2018 11:51 AM, srikanth.adayapalam at oracle.com wrote:
> Changeset: 7c1c51c340e6
> Author:    sadayapalam
> Date:      2018-03-12 11:46 +0530
> URL:       http://hg.openjdk.java.net/valhalla/valhalla/rev/7c1c51c340e6
>
> 8198748: [lworld] Javac should insert null checks at casts to value types.

Notes:

Where Point is a value type, code generated for casting an object to 
Point as in:

Object o = ...

Point p = (Point) o;

is:

          2: aload_1
          3: dup
          4: invokestatic  #2                  // Method 
java/util/Objects.requireNonNull:(Ljava/lang/Object;)Ljava/lang/Object;
          7: pop
          8: checkcast     #3                  // class Point
         11: astore_2

If the cast occurs in source code compiled at a level where value types 
are not recognized as such, then there is no insertion of null check.

(FWIW, Javac is not in the business of nullness tracking, so these 
checks will be inserted even where a cursory glance of source code 
context could inform a reader that no null check would be needed)

Thanks
Srikanth

>
> ! src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java
> ! src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java
> + test/langtools/tools/javac/valhalla/lworld-values/CastNoNullCheckTest.java
> + test/langtools/tools/javac/valhalla/lworld-values/CastNullCheckTest.java
>



More information about the valhalla-dev mailing list