soylatte and java.net.preferIPv4Stack=true

Leif Nelson lnelson at llnl.gov
Thu Dec 6 08:56:58 PST 2007


Hi all-

I've been using soylatte for the last few days to work with the Oracle 
application server oc4j.  I was puzzled by it's extremely slow startup 
time using soylatte.  So, I did some investigation, and found that 
setting the system property java.net.preferIPv4Stack=true causes calling 
InetAddress.getLocalHost() to take at least 8 seconds to execute on my 
Mac Pro.  It seems that the oc4j server sets this property in it's 
main() method on startup, and it is not configurable!   Also, each 
subsequent invocation of InetAddress.getLocalHost() takes another 8 
seconds, and apparently this method is called several times!  I did some 
tests on several macs running both Tiger & Leopard with java5 and java6 
to demonstrate the issue. 

After some tracing with -Djava.net.preferIPv4Stack=true, I found that 
the time is all taken up inside of the native method: 
java.net.Inet4AddressImpl.getLocalHostName().

If I trace with -Djava.net.preferIPv4Stack=false (the default), I found 
that the native method java.net.Inet6AddressImpl.getLocalHostName() gets 
called instead returns very quickly.

I hope this narrows it down enough to find out what's wrong. :-)

Thanks,
--Leif

Here's my test class:

package test;

import java.net.InetAddress;

public class TestHostName {
    public static void main(String[] args) {
        try {
            long start = System.currentTimeMillis();
            InetAddress addr = InetAddress.getLocalHost();
            long stop = System.currentTimeMillis();
            System.out.println("Found: " + addr.getHostAddress() + " in: 
" + (stop - start) + " ms.");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Here's some results from running the tests.  The results are very 
similar on both Tiger (32 bit) & Leopard (32 & 64 bit)

~/testhost $ uname -a
Darwin bridger.local 8.11.1 Darwin Kernel Version 8.11.1: Wed Oct 10 
18:23:28 PDT 2007; root:xnu-792.25.20~1/RELEASE_I386 i386 i386

~/testhost $ /opt/soylatte16-i386-r3/bin/javac test/TestHostName.java
~/testhost $ /opt/soylatte16-i386-r3/bin/java 
-Djava.net.preferIPv4Stack=true test.TestHostName
Found: 10.10.11.13 in: 8581 ms.
~/testhost $ /opt/soylatte16-i386-r3/bin/java test.TestHostName
Found: 10.10.11.13 in: 208 ms.

~/testhost $ 
/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home/bin/javac 
test/TestHostName.java
~/testhost $ 
/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home/bin/java 
-Djava.net.preferIPv4Stack=true test.TestHostName
Found: 10.10.11.13 in: 41 ms.
~/testhost $ 
/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home/bin/java 
test.TestHostName
Found: 10.10.11.13 in: 3 ms.

~/testhost $ 
/System/Library/Frameworks/JavaVM.framework/Versions/1.4/Home/bin/javac 
test/TestHostName.java
~/testhost $ 
/System/Library/Frameworks/JavaVM.framework/Versions/1.4/Home/bin/java 
-Djava.net.preferIPv4Stack=true test.TestHostName
Found: 10.10.11.13 in: 8 ms.
~/testhost $ 
/System/Library/Frameworks/JavaVM.framework/Versions/1.4/Home/bin/java 
test.TestHostName
Found: 10.10.11.13 in: 7 ms.




More information about the porters-dev mailing list