1

I'm early in the stages of working on a JavaFX app and I thought, "why not update my JDK to the latest version?". However, after updating, the program takes forever to load! Specifically, before my main method it appears to hang, on loading the class java.net.Inet4AddressImpl.

Output of java -verbose -jar /path/to/jarfile.jar:

[Loaded java.net.Inet6AddressImpl from /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded sun.net.spi.nameservice.NameService from /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded java.net.InetAddress$2 from /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded java.net.Inet4Address from /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded java.net.Inet6Address from /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded java.net.Inet6Address$Inet6AddressHolder from /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/rt.jar]

Here it lags for a full five seconds... then continues.

[Loaded java.net.Inet4AddressImpl from /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded sun.net.InetAddressCachePolicy from /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded sun.net.InetAddressCachePolicy$1 from /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/rt.jar]
[Loaded sun.net.InetAddressCachePolicy$2 from /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/rt.jar]

And so on until the application launches.

This started when switching from JDK 1.8.0_25 to 1.8.0_131

It does not seem that java.net.Inet4AddressImpl lags other random jars I tried to launch.

I'm a bit lost on how to troubleshoot this at this point.

Edit: @Holger suggested a thread dump on the freeze and that it's probably the instantiation of the class beforehand. Well, here is what the JavaFX Application Thread is up to! Seems like it is stuck on a native method Inet6AddressImpl.lookupAllHostAddr(String). Certainly seems like some native DNS handling gone wrong.

Thread [JavaFX Application Thread] (Suspended)  
    owns: Object  (id=27)   
    owns: LogbackLock  (id=28)  
    Inet6AddressImpl.lookupAllHostAddr(String) line: not available [native method]  
    InetAddress$2.lookupAllHostAddr(String) line: 928   
    InetAddress.getAddressesFromNameService(String, InetAddress) line: 1323 
    InetAddress.getLocalHost() line: 1500   
    ContextUtil.getLocalHostName() line: 38 
    ContextUtil.addHostNameAsProperty() line: 74    
    ConfigurationAction.begin(InterpretationContext, String, Attributes) line: 57   
    Interpreter.callBeginAction(List<Action>, String, Attributes) line: 275 
    Interpreter.startElement(String, String, String, Attributes) line: 147  
    Interpreter.startElement(StartEvent) line: 129  
    EventPlayer.play(List<SaxEvent>) line: 50   
    JoranConfigurator(GenericConfigurator).doConfigure(List<SaxEvent>) line: 149    
    JoranConfigurator(GenericConfigurator).doConfigure(InputSource) line: 135   
    JoranConfigurator(GenericConfigurator).doConfigure(InputStream) line: 99    
    JoranConfigurator(GenericConfigurator).doConfigure(URL) line: 49    
    ContextInitializer.configureByResource(URL) line: 75    
    ContextInitializer.autoConfig() line: 148   
    StaticLoggerBinder.init() line: 85  
    StaticLoggerBinder.<clinit>() line: 55  
    LoggerFactory.bind() line: 128  
    LoggerFactory.performInitialization() line: 107 
    LoggerFactory.getILoggerFactory() line: 295 
    LoggerFactory.getLogger(String) line: 269   
    LoggerFactory.getLogger(Class) line: 281    
    App.<clinit>() line: 11 
    Class<T>.forName0(String, boolean, ClassLoader, Class<?>) line: not available [native method]   
    Class<T>.forName(String, boolean, ClassLoader) line: 348    
    LauncherImpl.lambda$launchApplicationWithArgs$156(String, ClassLoader, AtomicReference, String, AtomicReference) line: 352  
    546718765.run() line: not available 
    PlatformImpl.lambda$runAndWait$175(Runnable, CountDownLatch) line: 326  
    592179046.run() line: not available 
    PlatformImpl.lambda$null$173(Runnable) line: 295    
    1018934961.run() line: not available    
    AccessController.doPrivileged(PrivilegedAction<T>, AccessControlContext) line: not available [native method]    
    PlatformImpl.lambda$runLater$174(Runnable, AccessControlContext) line: 294  
    1937348256.run() line: not available    
    InvokeLaterDispatcher$Future.run() line: 95 
Mark Lalor
  • 7,820
  • 18
  • 67
  • 106
  • If you still have the old JDK, you could pull the source from both JDKs and compare. – Jorn Vernee May 29 '17 at 21:05
  • @JornVernee just checked, the source of `java.net.Inet4AddressImpl` remains exactly the same. – Mark Lalor May 29 '17 at 21:09
  • 2
    This might be related to slow DNS lookups. Check your network infrastructure. – Thorbjørn Ravn Andersen May 29 '17 at 21:27
  • Definitely sounds like DNS. – chrylis -cautiouslyoptimistic- May 29 '17 at 21:36
  • What exactly is happening when the class is loaded, though? I assumed it was really just loading the compiled byte code into memory for fast access, not actually doing anything. I tried resetting my /etc/hosts anyways because I don't think I've changed much else network-wise. I turned off WiFi as well. Running this on a macOS laptop. – Mark Lalor May 29 '17 at 22:08
  • This is a known problem of macOS. Try adding a line `127.0.0.1 localhost.local` to `/etc/hosts`. The name should contain a *domain*, i.e. something after a dot. – apangin May 30 '17 at 07:07
  • The observed behavior doesn’t allow to conclude that “JVM suddenly hangs on loading single class”. All you know, is, that there is a delay between printing two `Loaded …` messages, whatever the JVM will do there. Apparently, it is the *initializer* of a class which performs the slow action, which implies that the particular class must have been loaded *before* the delay. – Holger May 30 '17 at 11:11
  • @apangin ok, I tried adding that to /etc/hosts. However the behavior seems to continue, even after restart. My /etc/hosts is now 127.0.0.1 localhost.local 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost – Mark Lalor May 30 '17 at 11:46
  • @Holger this makes sense, I wasn't sure how to get any more useful verbosity than this. In that case, do you think I should be investigating java.net.Inet6Address$Inet6AddressHolder? – Mark Lalor May 30 '17 at 11:49
  • That would be worth a shoot. Besides that, five seconds seems to be long enough to do a thread dump… – Holger May 30 '17 at 11:51
  • @Holger I've edited the post with some more details. Definitely seems like you were right. – Mark Lalor May 30 '17 at 12:22
  • 2
    See http://justthesam.com/2016/10/fixing-java-net-inet6addressimpl-lookupallhostaddr-slowdown/ – apangin May 30 '17 at 14:29
  • @apangin that article had the details for the fix! If you want you can make it into an answer. If not I will write it up as an answer later for future Googlers. – Mark Lalor May 30 '17 at 23:37

0 Answers0