Sporadic NPEs in compiled code

David M. Lloyd david.lloyd at redhat.com
Mon Nov 14 18:11:00 UTC 2016

We observed a problem where java.net.NetworkInterface appeared to be 
throwing an NPE originating at a line of code corresponding to its 
return instruction:

Caused by: java.lang.NullPointerException
         at java.net.NetworkInterface.<init>(NetworkInterface.java:80)
         at java.net.NetworkInterface.getAll(Native Method)

        0: aload_0
        1: invokespecial #3                  // Method 
        4: aload_0
        5: aconst_null
        6: putfield      #4                  // Field 
        9: aload_0
       10: iconst_0
       11: putfield      #5                  // Field virtual:Z
       14: return
       line 79: 0
       line 50: 4
       line 51: 9
       line 80: 14

I assumed that the problem was possibly JNI-related, because of the 
previous stack frame, however we've begun seeing the problem in other 
bits of code as well, areas like this:

        0: aload_0
        1: invokestatic  #10                 // Method 
        4: return

or this constructor:

       87: aload_0
       88: aload         7
       90: putfield      #17                 // Field 

We've started testing with -XX:TieredStopAtLevel=1 and so far it seems 
the problems have disappeared, however, it's not clear to my 
hotspot-amateur mind at all whether it's C2 that is causing this or 
whether there is a more general timing-related race condition that is 
hidden by limiting the compiler in this way.

The OpenJDK version is:

openjdk version "1.8.0_111"
OpenJDK Runtime Environment (build 1.8.0_111-b16)
OpenJDK 64-Bit Server VM (build 25.111-b16, mixed mode)

It's coming out of a Fedora 24 distribution.

More information about the hotspot-dev mailing list