changeset 22646:5fa3669fd35d

8025306: Inet[4|6]Address class and fieldID initialization in networking native code Reviewed-by: alanb, michaelm
author chegar
date Tue, 04 Feb 2014 23:40:23 +0000
parents 636153f07b26
children 7e45e0a1088d 93c0a5484bb5
files jdk/make/mapfiles/libnet/mapfile-vers jdk/src/share/native/java/net/Inet4Address.c jdk/src/share/native/java/net/Inet6Address.c jdk/src/share/native/java/net/InetAddress.c jdk/src/share/native/java/net/net_util.c jdk/src/share/native/java/net/net_util.h jdk/src/solaris/native/java/net/Inet4AddressImpl.c jdk/src/solaris/native/java/net/Inet6AddressImpl.c jdk/src/solaris/native/java/net/NetworkInterface.c jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c jdk/src/solaris/native/java/net/PlainSocketImpl.c jdk/src/solaris/native/sun/nio/ch/IOUtil.c jdk/src/solaris/native/sun/nio/ch/sctp/SctpNet.c jdk/src/windows/native/java/net/Inet4AddressImpl.c jdk/src/windows/native/java/net/Inet6AddressImpl.c jdk/src/windows/native/java/net/NetworkInterface.c jdk/src/windows/native/java/net/NetworkInterface.h jdk/src/windows/native/java/net/NetworkInterface_winXP.c jdk/src/windows/native/sun/nio/ch/IOUtil.c
diffstat 19 files changed, 141 insertions(+), 332 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/make/mapfiles/libnet/mapfile-vers	Tue Feb 04 18:37:12 2014 +0000
+++ b/jdk/make/mapfiles/libnet/mapfile-vers	Tue Feb 04 23:40:23 2014 +0000
@@ -105,6 +105,7 @@
 		NET_MapSocketOption;
 		NET_Wait;
                 ipv6_available;
+                initInetAddressIDs;
 
 	local:
 		*;
--- a/jdk/src/share/native/java/net/Inet4Address.c	Tue Feb 04 18:37:12 2014 +0000
+++ b/jdk/src/share/native/java/net/Inet4Address.c	Tue Feb 04 23:40:23 2014 +0000
@@ -34,6 +34,8 @@
 jclass ia4_class;
 jmethodID ia4_ctrID;
 
+static int ia4_initialized = 0;
+
 /*
  * Class:     java_net_Inet4Address
  * Method:    init
@@ -41,9 +43,13 @@
  */
 JNIEXPORT void JNICALL
 Java_java_net_Inet4Address_init(JNIEnv *env, jclass cls) {
-    jclass c = (*env)->FindClass(env, "java/net/Inet4Address");
-    CHECK_NULL(c);
-    ia4_class = (*env)->NewGlobalRef(env, c);
-    CHECK_NULL(ia4_class);
-    ia4_ctrID = (*env)->GetMethodID(env, ia4_class, "<init>", "()V");
+    if (!ia4_initialized) {
+        jclass c = (*env)->FindClass(env, "java/net/Inet4Address");
+        CHECK_NULL(c);
+        ia4_class = (*env)->NewGlobalRef(env, c);
+        CHECK_NULL(ia4_class);
+        ia4_ctrID = (*env)->GetMethodID(env, ia4_class, "<init>", "()V");
+        CHECK_NULL(ia4_ctrID);
+        ia4_initialized = 1;
+    }
 }
--- a/jdk/src/share/native/java/net/Inet6Address.c	Tue Feb 04 18:37:12 2014 +0000
+++ b/jdk/src/share/native/java/net/Inet6Address.c	Tue Feb 04 23:40:23 2014 +0000
@@ -42,6 +42,8 @@
 jfieldID ia6_scopeifnameID;
 jmethodID ia6_ctrID;
 
+static int ia6_initialized = 0;
+
 /*
  * Class:     java_net_Inet6Address
  * Method:    init
@@ -49,24 +51,28 @@
  */
 JNIEXPORT void JNICALL
 Java_java_net_Inet6Address_init(JNIEnv *env, jclass cls) {
-    jclass ia6h_class;
-    jclass c = (*env)->FindClass(env, "java/net/Inet6Address");
-    CHECK_NULL(c);
-    ia6_class = (*env)->NewGlobalRef(env, c);
-    CHECK_NULL(ia6_class);
-    ia6h_class = (*env)->FindClass(env, "java/net/Inet6Address$Inet6AddressHolder");
-    CHECK_NULL(ia6h_class);
-    ia6_holder6ID = (*env)->GetFieldID(env, ia6_class, "holder6", "Ljava/net/Inet6Address$Inet6AddressHolder;");
-    CHECK_NULL(ia6_holder6ID);
-    ia6_ipaddressID = (*env)->GetFieldID(env, ia6h_class, "ipaddress", "[B");
-    CHECK_NULL(ia6_ipaddressID);
-    ia6_scopeidID = (*env)->GetFieldID(env, ia6h_class, "scope_id", "I");
-    CHECK_NULL(ia6_scopeidID);
-    ia6_cachedscopeidID = (*env)->GetFieldID(env, ia6_class, "cached_scope_id", "I");
-    CHECK_NULL(ia6_cachedscopeidID);
-    ia6_scopeidsetID = (*env)->GetFieldID(env, ia6h_class, "scope_id_set", "Z");
-    CHECK_NULL(ia6_scopeidsetID);
-    ia6_scopeifnameID = (*env)->GetFieldID(env, ia6h_class, "scope_ifname", "Ljava/net/NetworkInterface;");
-    CHECK_NULL(ia6_scopeifnameID);
-    ia6_ctrID = (*env)->GetMethodID(env, ia6_class, "<init>", "()V");
+    if (!ia6_initialized) {
+        jclass ia6h_class;
+        jclass c = (*env)->FindClass(env, "java/net/Inet6Address");
+        CHECK_NULL(c);
+        ia6_class = (*env)->NewGlobalRef(env, c);
+        CHECK_NULL(ia6_class);
+        ia6h_class = (*env)->FindClass(env, "java/net/Inet6Address$Inet6AddressHolder");
+        CHECK_NULL(ia6h_class);
+        ia6_holder6ID = (*env)->GetFieldID(env, ia6_class, "holder6", "Ljava/net/Inet6Address$Inet6AddressHolder;");
+        CHECK_NULL(ia6_holder6ID);
+        ia6_ipaddressID = (*env)->GetFieldID(env, ia6h_class, "ipaddress", "[B");
+        CHECK_NULL(ia6_ipaddressID);
+        ia6_scopeidID = (*env)->GetFieldID(env, ia6h_class, "scope_id", "I");
+        CHECK_NULL(ia6_scopeidID);
+        ia6_cachedscopeidID = (*env)->GetFieldID(env, ia6_class, "cached_scope_id", "I");
+        CHECK_NULL(ia6_cachedscopeidID);
+        ia6_scopeidsetID = (*env)->GetFieldID(env, ia6h_class, "scope_id_set", "Z");
+        CHECK_NULL(ia6_scopeidsetID);
+        ia6_scopeifnameID = (*env)->GetFieldID(env, ia6h_class, "scope_ifname", "Ljava/net/NetworkInterface;");
+        CHECK_NULL(ia6_scopeifnameID);
+        ia6_ctrID = (*env)->GetMethodID(env, ia6_class, "<init>", "()V");
+        CHECK_NULL(ia6_ctrID);
+        ia6_initialized = 1;
+    }
 }
--- a/jdk/src/share/native/java/net/InetAddress.c	Tue Feb 04 18:37:12 2014 +0000
+++ b/jdk/src/share/native/java/net/InetAddress.c	Tue Feb 04 23:40:23 2014 +0000
@@ -40,6 +40,8 @@
 jfieldID iac_hostNameID;
 jfieldID ia_preferIPv6AddressID;
 
+static int ia_initialized = 0;
+
 /*
  * Class:     java_net_InetAddress
  * Method:    init
@@ -47,21 +49,25 @@
  */
 JNIEXPORT void JNICALL
 Java_java_net_InetAddress_init(JNIEnv *env, jclass cls) {
-    jclass c = (*env)->FindClass(env,"java/net/InetAddress");
-    CHECK_NULL(c);
-    ia_class = (*env)->NewGlobalRef(env, c);
-    CHECK_NULL(ia_class);
-    c = (*env)->FindClass(env,"java/net/InetAddress$InetAddressHolder");
-    CHECK_NULL(c);
-    iac_class = (*env)->NewGlobalRef(env, c);
-    ia_holderID = (*env)->GetFieldID(env, ia_class, "holder", "Ljava/net/InetAddress$InetAddressHolder;");
-    CHECK_NULL(ia_holderID);
-    ia_preferIPv6AddressID = (*env)->GetStaticFieldID(env, ia_class, "preferIPv6Address", "Z");
-    CHECK_NULL(ia_preferIPv6AddressID);
+    if (!ia_initialized) {
+        jclass c = (*env)->FindClass(env,"java/net/InetAddress");
+        CHECK_NULL(c);
+        ia_class = (*env)->NewGlobalRef(env, c);
+        CHECK_NULL(ia_class);
+        c = (*env)->FindClass(env,"java/net/InetAddress$InetAddressHolder");
+        CHECK_NULL(c);
+        iac_class = (*env)->NewGlobalRef(env, c);
+        ia_holderID = (*env)->GetFieldID(env, ia_class, "holder", "Ljava/net/InetAddress$InetAddressHolder;");
+        CHECK_NULL(ia_holderID);
+        ia_preferIPv6AddressID = (*env)->GetStaticFieldID(env, ia_class, "preferIPv6Address", "Z");
+        CHECK_NULL(ia_preferIPv6AddressID);
 
-    iac_addressID = (*env)->GetFieldID(env, iac_class, "address", "I");
-    CHECK_NULL(iac_addressID);
-    iac_familyID = (*env)->GetFieldID(env, iac_class, "family", "I");
-    CHECK_NULL(iac_familyID);
-    iac_hostNameID = (*env)->GetFieldID(env, iac_class, "hostName", "Ljava/lang/String;");
+        iac_addressID = (*env)->GetFieldID(env, iac_class, "address", "I");
+        CHECK_NULL(iac_addressID);
+        iac_familyID = (*env)->GetFieldID(env, iac_class, "family", "I");
+        CHECK_NULL(iac_familyID);
+        iac_hostNameID = (*env)->GetFieldID(env, iac_class, "hostName", "Ljava/lang/String;");
+        CHECK_NULL(iac_hostNameID);
+        ia_initialized = 1;
+    }
 }
--- a/jdk/src/share/native/java/net/net_util.c	Tue Feb 04 18:37:12 2014 +0000
+++ b/jdk/src/share/native/java/net/net_util.c	Tue Feb 04 23:40:23 2014 +0000
@@ -75,11 +75,14 @@
 
 static int initialized = 0;
 
-static void initInetAddrs(JNIEnv *env) {
+JNIEXPORT void JNICALL initInetAddressIDs(JNIEnv *env) {
     if (!initialized) {
         Java_java_net_InetAddress_init(env, 0);
+        JNU_CHECK_EXCEPTION(env);
         Java_java_net_Inet4Address_init(env, 0);
+        JNU_CHECK_EXCEPTION(env);
         Java_java_net_Inet6Address_init(env, 0);
+        JNU_CHECK_EXCEPTION(env);
         initialized = 1;
     }
 }
@@ -100,47 +103,32 @@
  * get_ methods that return objects return NULL on error.
  */
 jobject getInet6Address_scopeifname(JNIEnv *env, jobject iaObj) {
-    jobject holder;
-
-    initInetAddrs(env);
-    holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID);
+    jobject holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID);
     CHECK_NULL_RETURN(holder, NULL);
     return (*env)->GetObjectField(env, holder, ia6_scopeifnameID);
 }
 
 int setInet6Address_scopeifname(JNIEnv *env, jobject iaObj, jobject scopeifname) {
-    jobject holder;
-
-    initInetAddrs(env);
-    holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID);
+    jobject holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID);
     CHECK_NULL_RETURN(holder, JNI_FALSE);
     (*env)->SetObjectField(env, holder, ia6_scopeifnameID, scopeifname);
     return JNI_TRUE;
 }
 
 int getInet6Address_scopeid_set(JNIEnv *env, jobject iaObj) {
-    jobject holder;
-
-    initInetAddrs(env);
-    holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID);
+    jobject holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID);
     CHECK_NULL_RETURN(holder, -1);
     return (*env)->GetBooleanField(env, holder, ia6_scopeidsetID);
 }
 
 int getInet6Address_scopeid(JNIEnv *env, jobject iaObj) {
-    jobject holder;
-
-    initInetAddrs(env);
-    holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID);
+    jobject holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID);
     CHECK_NULL_RETURN(holder, -1);
     return (*env)->GetIntField(env, holder, ia6_scopeidID);
 }
 
 int setInet6Address_scopeid(JNIEnv *env, jobject iaObj, int scopeid) {
-    jobject holder;
-
-    initInetAddrs(env);
-    holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID);
+    jobject holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID);
     CHECK_NULL_RETURN(holder, JNI_FALSE);
     (*env)->SetIntField(env, holder, ia6_scopeidID, scopeid);
     if (scopeid > 0) {
@@ -154,7 +142,6 @@
     jobject holder, addr;
     jbyteArray barr;
 
-    initInetAddrs(env);
     holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID);
     CHECK_NULL_RETURN(holder, JNI_FALSE);
     addr =  (*env)->GetObjectField(env, holder, ia6_ipaddressID);
@@ -167,7 +154,6 @@
     jobject holder;
     jbyteArray addr;
 
-    initInetAddrs(env);
     holder = (*env)->GetObjectField(env, iaObj, ia6_holder6ID);
     CHECK_NULL_RETURN(holder, JNI_FALSE);
     addr =  (jbyteArray)(*env)->GetObjectField(env, holder, ia6_ipaddressID);
@@ -181,52 +167,38 @@
 }
 
 void setInetAddress_addr(JNIEnv *env, jobject iaObj, int address) {
-    jobject holder;
-    initInetAddrs(env);
-    holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
+    jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
     (*env)->SetIntField(env, holder, iac_addressID, address);
 }
 
 void setInetAddress_family(JNIEnv *env, jobject iaObj, int family) {
-    jobject holder;
-    initInetAddrs(env);
-    holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
+    jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
     (*env)->SetIntField(env, holder, iac_familyID, family);
 }
 
 void setInetAddress_hostName(JNIEnv *env, jobject iaObj, jobject host) {
-    jobject holder;
-    initInetAddrs(env);
-    holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
+    jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
     (*env)->SetObjectField(env, holder, iac_hostNameID, host);
 }
 
 int getInetAddress_addr(JNIEnv *env, jobject iaObj) {
-    jobject holder;
-    initInetAddrs(env);
-    holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
+    jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
     return (*env)->GetIntField(env, holder, iac_addressID);
 }
 
 int getInetAddress_family(JNIEnv *env, jobject iaObj) {
-    jobject holder;
-
-    initInetAddrs(env);
-    holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
+    jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
     return (*env)->GetIntField(env, holder, iac_familyID);
 }
 
 jobject getInetAddress_hostName(JNIEnv *env, jobject iaObj) {
-    jobject holder;
-    initInetAddrs(env);
-    holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
+    jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
     return (*env)->GetObjectField(env, holder, iac_hostNameID);
 }
 
 JNIEXPORT jobject JNICALL
 NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) {
     jobject iaObj;
-    initInetAddrs(env);
 #ifdef AF_INET6
     if (him->sa_family == AF_INET6) {
         jbyteArray ipaddress;
@@ -238,31 +210,15 @@
         jbyte *caddr = (jbyte *)&(him6->sin6_addr);
         if (NET_IsIPv4Mapped(caddr)) {
             int address;
-            static jclass inet4Cls = 0;
-            if (inet4Cls == 0) {
-                jclass c = (*env)->FindClass(env, "java/net/Inet4Address");
-                CHECK_NULL_RETURN(c, NULL);
-                inet4Cls = (*env)->NewGlobalRef(env, c);
-                CHECK_NULL_RETURN(inet4Cls, NULL);
-                (*env)->DeleteLocalRef(env, c);
-            }
-            iaObj = (*env)->NewObject(env, inet4Cls, ia4_ctrID);
+            iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
             CHECK_NULL_RETURN(iaObj, NULL);
             address = NET_IPv4MappedToIPv4(caddr);
             setInetAddress_addr(env, iaObj, address);
             setInetAddress_family(env, iaObj, IPv4);
         } else {
-            static jclass inet6Cls = 0;
             jint scope;
             int ret;
-            if (inet6Cls == 0) {
-                jclass c = (*env)->FindClass(env, "java/net/Inet6Address");
-                CHECK_NULL_RETURN(c, NULL);
-                inet6Cls = (*env)->NewGlobalRef(env, c);
-                CHECK_NULL_RETURN(inet6Cls, NULL);
-                (*env)->DeleteLocalRef(env, c);
-            }
-            iaObj = (*env)->NewObject(env, inet6Cls, ia6_ctrID);
+            iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
             CHECK_NULL_RETURN(iaObj, NULL);
             ret = setInet6Address_ipaddress(env, iaObj, (char *)&(him6->sin6_addr));
             CHECK_NULL_RETURN(ret, NULL);
@@ -275,16 +231,7 @@
 #endif /* AF_INET6 */
         {
             struct sockaddr_in *him4 = (struct sockaddr_in *)him;
-            static jclass inet4Cls = 0;
-
-            if (inet4Cls == 0) {
-                jclass c = (*env)->FindClass(env, "java/net/Inet4Address");
-                CHECK_NULL_RETURN(c, NULL);
-                inet4Cls = (*env)->NewGlobalRef(env, c);
-                CHECK_NULL_RETURN(inet4Cls, NULL);
-                (*env)->DeleteLocalRef(env, c);
-            }
-            iaObj = (*env)->NewObject(env, inet4Cls, ia4_ctrID);
+            iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
             CHECK_NULL_RETURN(iaObj, NULL);
             setInetAddress_family(env, iaObj, IPv4);
             setInetAddress_addr(env, iaObj, ntohl(him4->sin_addr.s_addr));
--- a/jdk/src/share/native/java/net/net_util.h	Tue Feb 04 18:37:12 2014 +0000
+++ b/jdk/src/share/native/java/net/net_util.h	Tue Feb 04 23:40:23 2014 +0000
@@ -55,6 +55,8 @@
 extern jfieldID iac_hostNameID;
 extern jfieldID ia_preferIPv6AddressID;
 
+JNIEXPORT void JNICALL initInetAddressIDs(JNIEnv *env);
+
 /** (Inet6Address accessors)
  * set_ methods return JNI_TRUE on success JNI_FALSE on error
  * get_ methods that return int/boolean, return -1 on error
--- a/jdk/src/solaris/native/java/net/Inet4AddressImpl.c	Tue Feb 04 18:37:12 2014 +0000
+++ b/jdk/src/solaris/native/java/net/Inet4AddressImpl.c	Tue Feb 04 23:40:23 2014 +0000
@@ -51,29 +51,6 @@
 #define HAS_GLIBC_GETHOSTBY_R   1
 #endif
 
-static jclass ni_iacls;
-static jclass ni_ia4cls;
-static jmethodID ni_ia4ctrID;
-
-static jboolean initializeInetClasses(JNIEnv *env)
-{
-    static int initialized = 0;
-    if (!initialized) {
-        ni_iacls = (*env)->FindClass(env, "java/net/InetAddress");
-        CHECK_NULL_RETURN(ni_iacls, JNI_FALSE);
-        ni_iacls = (*env)->NewGlobalRef(env, ni_iacls);
-        CHECK_NULL_RETURN(ni_iacls, JNI_FALSE);
-        ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address");
-        CHECK_NULL_RETURN(ni_ia4cls, JNI_FALSE);
-        ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls);
-        CHECK_NULL_RETURN(ni_ia4cls, JNI_FALSE);
-        ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V");
-        CHECK_NULL_RETURN(ni_ia4ctrID, JNI_FALSE);
-        initialized = 1;
-    }
-    return JNI_TRUE;
-}
-
 
 #if defined(_ALLBSD_SOURCE) && !defined(HAS_GLIBC_GETHOSTBY_R)
 extern jobjectArray lookupIfLocalhost(JNIEnv *env, const char *hostname, jboolean includeV6);
@@ -147,8 +124,8 @@
     int error=0;
     struct addrinfo hints, *res, *resNew = NULL;
 
-    if (!initializeInetClasses(env))
-        return NULL;
+    initInetAddressIDs(env);
+    JNU_CHECK_EXCEPTION_RETURN(env, NULL);
 
     if (IS_NULL(host)) {
         JNU_ThrowNullPointerException(env, "host is null");
@@ -241,7 +218,7 @@
           goto cleanupAndReturn;
         }
 
-        ret = (*env)->NewObjectArray(env, retLen, ni_iacls, NULL);
+        ret = (*env)->NewObjectArray(env, retLen, ia_class, NULL);
         if (IS_NULL(ret)) {
             /* we may have memory to free at the end of this */
             goto cleanupAndReturn;
@@ -251,7 +228,7 @@
             /* We need 4 bytes to store ipv4 address; */
             int len = 4;
 
-            jobject iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
+            jobject iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
             if (IS_NULL(iaObj)) {
                 /* we may have memory to free at the end of this */
                 ret = NULL;
@@ -407,8 +384,8 @@
     int error = 0;
     struct addrinfo hints, *res, *resNew = NULL;
 
-    if (!initializeInetClasses(env))
-        return NULL;
+    initInetAddressIDs(env);
+    JNU_CHECK_EXCEPTION_RETURN(env, NULL);
 
     if (IS_NULL(host)) {
         JNU_ThrowNullPointerException(env, "host is null");
@@ -486,7 +463,7 @@
         retLen = i;
         iterator = resNew;
 
-        ret = (*env)->NewObjectArray(env, retLen, ni_iacls, NULL);
+        ret = (*env)->NewObjectArray(env, retLen, ia_class, NULL);
 
         if (IS_NULL(ret)) {
             /* we may have memory to free at the end of this */
@@ -495,7 +472,7 @@
 
         i = 0;
         while (iterator != NULL) {
-            jobject iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
+            jobject iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
             if (IS_NULL(iaObj)) {
                 ret = NULL;
                 goto cleanupAndReturn;
--- a/jdk/src/solaris/native/java/net/Inet6AddressImpl.c	Tue Feb 04 18:37:12 2014 +0000
+++ b/jdk/src/solaris/native/java/net/Inet6AddressImpl.c	Tue Feb 04 23:40:23 2014 +0000
@@ -117,44 +117,6 @@
     return (*env)->NewStringUTF(env, hostname);
 }
 
-static jclass ni_iacls;
-static jclass ni_ia4cls;
-static jclass ni_ia6cls;
-static jmethodID ni_ia4ctrID;
-static jmethodID ni_ia6ctrID;
-static jboolean preferIPv6Address;
-
-static jboolean initializeInetClasses(JNIEnv *env)
-{
-    jfieldID ni_preferIPv6AddressID;
-    static int initialized = 0;
-    if (!initialized) {
-        ni_iacls = (*env)->FindClass(env, "java/net/InetAddress");
-        CHECK_NULL_RETURN(ni_iacls, JNI_FALSE);
-        ni_iacls = (*env)->NewGlobalRef(env, ni_iacls);
-        CHECK_NULL_RETURN(ni_iacls, JNI_FALSE);
-        ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address");
-        CHECK_NULL_RETURN(ni_ia4cls, JNI_FALSE);
-        ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls);
-        CHECK_NULL_RETURN(ni_ia4cls, JNI_FALSE);
-        ni_ia6cls = (*env)->FindClass(env, "java/net/Inet6Address");
-        CHECK_NULL_RETURN(ni_ia6cls, JNI_FALSE);
-        ni_ia6cls = (*env)->NewGlobalRef(env, ni_ia6cls);
-        CHECK_NULL_RETURN(ni_ia6cls, JNI_FALSE);
-        ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V");
-        CHECK_NULL_RETURN(ni_ia4ctrID, JNI_FALSE);
-        ni_ia6ctrID = (*env)->GetMethodID(env, ni_ia6cls, "<init>", "()V");
-        CHECK_NULL_RETURN(ni_ia6ctrID, JNI_FALSE);
-        ni_preferIPv6AddressID =
-            (*env)->GetStaticFieldID(env, ni_iacls, "preferIPv6Address", "Z");
-        CHECK_NULL_RETURN(ni_preferIPv6AddressID, JNI_FALSE);
-        preferIPv6Address =
-            (*env)->GetStaticBooleanField(env, ia_class, ia_preferIPv6AddressID);
-        initialized = 1;
-    }
-    return JNI_TRUE;
-}
-
 #ifdef MACOSX
 /* also called from Inet4AddressImpl.c */
 __private_extern__ jobjectArray
@@ -169,9 +131,8 @@
     jboolean includeLoopback = JNI_FALSE;
     jobject name;
 
-    // Make sure static variables we need are set.
-    if (!initializeInetClasses(env))
-        return NULL;
+    initInetAddressIDs(env);
+    JNU_CHECK_EXCEPTION_RETURN(env, NULL);
 
     /* If the requested name matches this host's hostname, return IP addresses
      * from all attached interfaces. (#2844683 et al) This prevents undesired
@@ -196,7 +157,7 @@
     }
 
     name = (*env)->NewStringUTF(env, hostname);
-    CHECK_NULL(name);
+    CHECK_NULL_RETURN(name, NULL);
 
     /* Iterate over the interfaces, and total up the number of IPv4 and IPv6
      * addresses we have. Also keep a count of loopback addresses. We need to
@@ -231,10 +192,10 @@
     /* Create and fill the Java array. */
     int arraySize = addrs4 + addrs6 -
         (includeLoopback ? 0 : (numV4Loopbacks + numV6Loopbacks));
-    result = (*env)->NewObjectArray(env, arraySize, ni_iacls, NULL);
+    result = (*env)->NewObjectArray(env, arraySize, ia_class, NULL);
     if (!result) goto done;
 
-    if (preferIPv6Address) {
+    if ((*env)->GetStaticBooleanField(env, ia_class, ia_preferIPv6AddressID)) {
         i = includeLoopback ? addrs6 : (addrs6 - numV6Loopbacks);
         j = 0;
     } else {
@@ -298,8 +259,8 @@
     struct addrinfo hints, *res, *resNew = NULL;
 #endif /* AF_INET6 */
 
-    if (!initializeInetClasses(env))
-        return NULL;
+    initInetAddressIDs(env);
+    JNU_CHECK_EXCEPTION_RETURN(env, NULL);
 
     if (IS_NULL(host)) {
         JNU_ThrowNullPointerException(env, "host is null");
@@ -423,14 +384,14 @@
         retLen = i;
         iterator = resNew;
 
-        ret = (*env)->NewObjectArray(env, retLen, ni_iacls, NULL);
+        ret = (*env)->NewObjectArray(env, retLen, ia_class, NULL);
 
         if (IS_NULL(ret)) {
             /* we may have memory to free at the end of this */
             goto cleanupAndReturn;
         }
 
-        if (preferIPv6Address) {
+        if ((*env)->GetStaticBooleanField(env, ia_class, ia_preferIPv6AddressID)) {
             /* AF_INET addresses will be offset by inet6Count */
             inetIndex = inet6Count;
             inet6Index = 0;
@@ -443,7 +404,7 @@
         while (iterator != NULL) {
             int ret1;
             if (iterator->ai_family == AF_INET) {
-                jobject iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
+                jobject iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
                 if (IS_NULL(iaObj)) {
                     ret = NULL;
                     goto cleanupAndReturn;
@@ -455,7 +416,7 @@
             } else if (iterator->ai_family == AF_INET6) {
                 jint scope = 0;
 
-                jobject iaObj = (*env)->NewObject(env, ni_ia6cls, ni_ia6ctrID);
+                jobject iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
                 if (IS_NULL(iaObj)) {
                     ret = NULL;
                     goto cleanupAndReturn;
@@ -549,7 +510,7 @@
 
     if (!error) {
         ret = (*env)->NewStringUTF(env, host);
-        CHECK_NULL(ret);
+        CHECK_NULL_RETURN(ret, NULL);
     }
 #endif /* AF_INET6 */
 
--- a/jdk/src/solaris/native/java/net/NetworkInterface.c	Tue Feb 04 18:37:12 2014 +0000
+++ b/jdk/src/solaris/native/java/net/NetworkInterface.c	Tue Feb 04 23:40:23 2014 +0000
@@ -118,12 +118,7 @@
 jfieldID ni_defaultIndexID;
 jmethodID ni_ctrID;
 
-static jclass ni_iacls;
-static jclass ni_ia4cls;
-static jclass ni_ia6cls;
 static jclass ni_ibcls;
-static jmethodID ni_ia4ctrID;
-static jmethodID ni_ia6ctrID;
 static jmethodID ni_ibctrID;
 static jfieldID ni_ibaddressID;
 static jfieldID ni_ib4broadcastID;
@@ -198,27 +193,10 @@
     CHECK_NULL(ni_parentID);
     ni_ctrID = (*env)->GetMethodID(env, ni_class, "<init>", "()V");
     CHECK_NULL(ni_ctrID);
-
-    ni_iacls = (*env)->FindClass(env, "java/net/InetAddress");
-    CHECK_NULL(ni_iacls);
-    ni_iacls = (*env)->NewGlobalRef(env, ni_iacls);
-    CHECK_NULL(ni_iacls);
-    ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address");
-    CHECK_NULL(ni_ia4cls);
-    ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls);
-    CHECK_NULL(ni_ia4cls);
-    ni_ia6cls = (*env)->FindClass(env, "java/net/Inet6Address");
-    CHECK_NULL(ni_ia6cls);
-    ni_ia6cls = (*env)->NewGlobalRef(env, ni_ia6cls);
-    CHECK_NULL(ni_ia6cls);
     ni_ibcls = (*env)->FindClass(env, "java/net/InterfaceAddress");
     CHECK_NULL(ni_ibcls);
     ni_ibcls = (*env)->NewGlobalRef(env, ni_ibcls);
     CHECK_NULL(ni_ibcls);
-    ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V");
-    CHECK_NULL(ni_ia4ctrID);
-    ni_ia6ctrID = (*env)->GetMethodID(env, ni_ia6cls, "<init>", "()V");
-    CHECK_NULL(ni_ia6ctrID);
     ni_ibctrID = (*env)->GetMethodID(env, ni_ibcls, "<init>", "()V");
     CHECK_NULL(ni_ibctrID);
     ni_ibaddressID = (*env)->GetFieldID(env, ni_ibcls, "address", "Ljava/net/InetAddress;");
@@ -228,6 +206,9 @@
     ni_ib4maskID = (*env)->GetFieldID(env, ni_ibcls, "maskLength", "S");
     CHECK_NULL(ni_ib4maskID);
     ni_defaultIndexID = (*env)->GetStaticFieldID(env, ni_class, "defaultIndex", "I");
+    CHECK_NULL(ni_defaultIndexID);
+
+    initInetAddressIDs(env);
 }
 
 
@@ -654,7 +635,7 @@
     /*
      * Create the array of InetAddresses
      */
-    addrArr = (*env)->NewObjectArray(env, addr_count,  ni_iacls, NULL);
+    addrArr = (*env)->NewObjectArray(env, addr_count,  ia_class, NULL);
     if (addrArr == NULL) {
         return NULL;
     }
@@ -671,7 +652,7 @@
         jobject ibObj = NULL;
 
         if (addrP->family == AF_INET) {
-            iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
+            iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
             if (iaObj) {
                  setInetAddress_addr(env, iaObj, htonl(((struct sockaddr_in*)addrP->addr)->sin_addr.s_addr));
             }
@@ -680,7 +661,7 @@
                  (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
                  if (addrP->brdcast) {
                     jobject ia2Obj = NULL;
-                    ia2Obj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
+                    ia2Obj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
                     if (ia2Obj) {
                        setInetAddress_addr(env, ia2Obj, htonl(((struct sockaddr_in*)addrP->brdcast)->sin_addr.s_addr));
                        (*env)->SetObjectField(env, ibObj, ni_ib4broadcastID, ia2Obj);
@@ -694,7 +675,7 @@
 #ifdef AF_INET6
         if (addrP->family == AF_INET6) {
             int scope=0;
-            iaObj = (*env)->NewObject(env, ni_ia6cls, ni_ia6ctrID);
+            iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
             if (iaObj) {
                 int ret = setInet6Address_ipaddress(env, iaObj, (char *)&(((struct sockaddr_in6*)addrP->addr)->sin6_addr));
                 if (ret == JNI_FALSE) {
--- a/jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c	Tue Feb 04 18:37:12 2014 +0000
+++ b/jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c	Tue Feb 04 23:40:23 2014 +0000
@@ -166,9 +166,8 @@
     IO_fd_fdID = NET_GetFileDescriptorID(env);
     CHECK_NULL(IO_fd_fdID);
 
-    Java_java_net_InetAddress_init(env, 0);
-    Java_java_net_Inet4Address_init(env, 0);
-    Java_java_net_Inet6Address_init(env, 0);
+    initInetAddressIDs(env);
+    JNU_CHECK_EXCEPTION(env);
     Java_java_net_NetworkInterface_init(env, 0);
 
 }
--- a/jdk/src/solaris/native/java/net/PlainSocketImpl.c	Tue Feb 04 18:37:12 2014 +0000
+++ b/jdk/src/solaris/native/java/net/PlainSocketImpl.c	Tue Feb 04 23:40:23 2014 +0000
@@ -162,6 +162,9 @@
     IO_fd_fdID = NET_GetFileDescriptorID(env);
     CHECK_NULL(IO_fd_fdID);
 
+    initInetAddressIDs(env);
+    JNU_CHECK_EXCEPTION(env);
+
     /* Create the marker fd used for dup2 */
     marker_fd = getMarkerFD();
 }
--- a/jdk/src/solaris/native/sun/nio/ch/IOUtil.c	Tue Feb 04 18:37:12 2014 +0000
+++ b/jdk/src/solaris/native/sun/nio/ch/IOUtil.c	Tue Feb 04 23:40:23 2014 +0000
@@ -35,6 +35,7 @@
 #include "java_lang_Integer.h"
 #include "nio.h"
 #include "nio_util.h"
+#include "net_util.h"
 
 static jfieldID fd_fdID;        /* for jint 'fd' in java.io.FileDescriptor */
 
@@ -44,6 +45,7 @@
 {
     CHECK_NULL(clazz = (*env)->FindClass(env, "java/io/FileDescriptor"));
     CHECK_NULL(fd_fdID = (*env)->GetFieldID(env, clazz, "fd", "I"));
+    initInetAddressIDs(env);
 }
 
 JNIEXPORT jboolean JNICALL
--- a/jdk/src/solaris/native/sun/nio/ch/sctp/SctpNet.c	Tue Feb 04 18:37:12 2014 +0000
+++ b/jdk/src/solaris/native/sun/nio/ch/sctp/SctpNet.c	Tue Feb 04 23:40:23 2014 +0000
@@ -157,6 +157,7 @@
     }
     preCloseFD = sp[0];
     close(sp[1]);
+    initInetAddressIDs(env);
 }
 
 /*
--- a/jdk/src/windows/native/java/net/Inet4AddressImpl.c	Tue Feb 04 18:37:12 2014 +0000
+++ b/jdk/src/windows/native/java/net/Inet4AddressImpl.c	Tue Feb 04 23:40:23 2014 +0000
@@ -111,11 +111,6 @@
     return JNU_NewStringPlatform(env, hostname);
 }
 
-static jclass ni_iacls;
-static jclass ni_ia4cls;
-static jmethodID ni_ia4ctrID;
-static int initialized = 0;
-
 /*
  * Find an internet address for a given hostname.  Not this this
  * code only works for addresses of type INET. The translation
@@ -140,19 +135,8 @@
 
     jobjectArray ret = NULL;
 
-    if (!initialized) {
-      ni_iacls = (*env)->FindClass(env, "java/net/InetAddress");
-      CHECK_NULL_RETURN(ni_iacls, NULL);
-      ni_iacls = (*env)->NewGlobalRef(env, ni_iacls);
-      CHECK_NULL_RETURN(ni_iacls, NULL);
-      ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address");
-      CHECK_NULL_RETURN(ni_ia4cls, NULL);
-      ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls);
-      CHECK_NULL_RETURN(ni_ia4cls, NULL);
-      ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V");
-      CHECK_NULL_RETURN(ni_ia4ctrID, NULL);
-      initialized = 1;
-    }
+    initInetAddressIDs(env);
+    JNU_CHECK_EXCEPTION_RETURN(env, NULL);
 
     if (IS_NULL(host)) {
         JNU_ThrowNullPointerException(env, "host argument");
@@ -196,13 +180,13 @@
         address |= (addr[1]<<8) & 0xff00;
         address |= addr[0];
 
-        ret = (*env)->NewObjectArray(env, 1, ni_iacls, NULL);
+        ret = (*env)->NewObjectArray(env, 1, ia_class, NULL);
 
         if (IS_NULL(ret)) {
             goto cleanupAndReturn;
         }
 
-        iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
+        iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
         if (IS_NULL(iaObj)) {
           ret = NULL;
           goto cleanupAndReturn;
@@ -226,7 +210,7 @@
             addrp++;
         }
 
-        ret = (*env)->NewObjectArray(env, i, ni_iacls, NULL);
+        ret = (*env)->NewObjectArray(env, i, ia_class, NULL);
 
         if (IS_NULL(ret)) {
             goto cleanupAndReturn;
@@ -235,7 +219,7 @@
         addrp = (struct in_addr **) hp->h_addr_list;
         i = 0;
         while (*addrp != (struct in_addr *) 0) {
-          jobject iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
+          jobject iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
           if (IS_NULL(iaObj)) {
             ret = NULL;
             goto cleanupAndReturn;
--- a/jdk/src/windows/native/java/net/Inet6AddressImpl.c	Tue Feb 04 18:37:12 2014 +0000
+++ b/jdk/src/windows/native/java/net/Inet6AddressImpl.c	Tue Feb 04 23:40:23 2014 +0000
@@ -72,13 +72,6 @@
     return JNU_NewStringPlatform (env, hostname);
 }
 
-static jclass ni_iacls;
-static jclass ni_ia4cls;
-static jclass ni_ia6cls;
-static jmethodID ni_ia4ctrID;
-static jmethodID ni_ia6ctrID;
-static int initialized = 0;
-
 JNIEXPORT jobjectArray JNICALL
 Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
                                                 jstring host) {
@@ -86,30 +79,13 @@
     jobjectArray ret = 0;
     int retLen = 0;
     jboolean preferIPv6Address;
-    static jfieldID ia_preferIPv6AddressID;
 
     int error=0;
     struct addrinfo hints, *res, *resNew = NULL;
 
-    if (!initialized) {
-      ni_iacls = (*env)->FindClass(env, "java/net/InetAddress");
-      CHECK_NULL_RETURN(ni_iacls, NULL);
-      ni_iacls = (*env)->NewGlobalRef(env, ni_iacls);
-      CHECK_NULL_RETURN(ni_iacls, NULL);
-      ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address");
-      CHECK_NULL_RETURN(ni_ia4cls, NULL);
-      ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls);
-      CHECK_NULL_RETURN(ni_ia4cls, NULL);
-      ni_ia6cls = (*env)->FindClass(env, "java/net/Inet6Address");
-      CHECK_NULL_RETURN(ni_ia6cls, NULL);
-      ni_ia6cls = (*env)->NewGlobalRef(env, ni_ia6cls);
-      CHECK_NULL_RETURN(ni_ia6cls, NULL);
-      ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V");
-      CHECK_NULL_RETURN(ni_ia4ctrID, NULL);
-      ni_ia6ctrID = (*env)->GetMethodID(env, ni_ia6cls, "<init>", "()V");
-      CHECK_NULL_RETURN(ni_ia6ctrID, NULL);
-      initialized = 1;
-    }
+    initInetAddressIDs(env);
+    JNU_CHECK_EXCEPTION_RETURN(env, NULL);
+
     if (IS_NULL(host)) {
         JNU_ThrowNullPointerException(env, "host is null");
         return 0;
@@ -117,17 +93,6 @@
     hostname = JNU_GetStringPlatformChars(env, host, JNI_FALSE);
     CHECK_NULL_RETURN(hostname, NULL);
 
-    if (ia_preferIPv6AddressID == NULL) {
-        jclass c = (*env)->FindClass(env,"java/net/InetAddress");
-        if (c)  {
-            ia_preferIPv6AddressID =
-                (*env)->GetStaticFieldID(env, c, "preferIPv6Address", "Z");
-        }
-        if (ia_preferIPv6AddressID == NULL) {
-            JNU_ReleaseStringPlatformChars(env, host, hostname);
-            return NULL;
-        }
-    }
     /* get the address preference */
     preferIPv6Address
         = (*env)->GetStaticBooleanField(env, ia_class, ia_preferIPv6AddressID);
@@ -229,7 +194,7 @@
         retLen = i;
         iterator = resNew;
         i = 0;
-        ret = (*env)->NewObjectArray(env, retLen, ni_iacls, NULL);
+        ret = (*env)->NewObjectArray(env, retLen, ia_class, NULL);
 
         if (IS_NULL(ret)) {
             /* we may have memory to free at the end of this */
@@ -246,7 +211,7 @@
 
         while (iterator != NULL) {
             if (iterator->ai_family == AF_INET) {
-              jobject iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
+              jobject iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
               if (IS_NULL(iaObj)) {
                 ret = NULL;
                 goto cleanupAndReturn;
@@ -257,7 +222,7 @@
                 inetIndex ++;
             } else if (iterator->ai_family == AF_INET6) {
               jint scope = 0, ret1;
-              jobject iaObj = (*env)->NewObject(env, ni_ia6cls, ni_ia6ctrID);
+              jobject iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
               if (IS_NULL(iaObj)) {
                 ret = NULL;
                 goto cleanupAndReturn;
@@ -347,7 +312,7 @@
 
     if (!error) {
         ret = (*env)->NewStringUTF(env, host);
-        CHECK_NULL(ret);
+        CHECK_NULL_RETURN(ret, NULL);
     }
 
     if (ret == NULL) {
--- a/jdk/src/windows/native/java/net/NetworkInterface.c	Tue Feb 04 18:37:12 2014 +0000
+++ b/jdk/src/windows/native/java/net/NetworkInterface.c	Tue Feb 04 23:40:23 2014 +0000
@@ -65,13 +65,6 @@
 jfieldID ni_nameID;         /* NetworkInterface.name */
 jfieldID ni_displayNameID;  /* NetworkInterface.displayName */
 jfieldID ni_childsID;       /* NetworkInterface.childs */
-jclass ni_iacls;            /* InetAddress */
-
-jclass ni_ia4cls;           /* Inet4Address */
-jmethodID ni_ia4Ctor;       /* Inet4Address() */
-
-jclass ni_ia6cls;           /* Inet6Address */
-jmethodID ni_ia6ctrID;      /* Inet6Address() */
 
 jclass ni_ibcls;            /* InterfaceAddress */
 jmethodID ni_ibctrID;       /* InterfaceAddress() */
@@ -515,26 +508,6 @@
     CHECK_NULL(ni_childsID);
     ni_ctor = (*env)->GetMethodID(env, ni_class, "<init>", "()V");
     CHECK_NULL(ni_ctor);
-
-    ni_iacls = (*env)->FindClass(env, "java/net/InetAddress");
-    CHECK_NULL(ni_iacls);
-    ni_iacls = (*env)->NewGlobalRef(env, ni_iacls);
-    CHECK_NULL(ni_iacls);
-
-    ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address");
-    CHECK_NULL(ni_ia4cls);
-    ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls);
-    CHECK_NULL(ni_ia4cls);
-    ni_ia4Ctor = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V");
-    CHECK_NULL(ni_ia4Ctor);
-
-    ni_ia6cls = (*env)->FindClass(env, "java/net/Inet6Address");
-    CHECK_NULL(ni_ia6cls);
-    ni_ia6cls = (*env)->NewGlobalRef(env, ni_ia6cls);
-    CHECK_NULL(ni_ia6cls);
-    ni_ia6ctrID = (*env)->GetMethodID(env, ni_ia6cls, "<init>", "()V");
-    CHECK_NULL(ni_ia6ctrID);
-
     ni_ibcls = (*env)->FindClass(env, "java/net/InterfaceAddress");
     CHECK_NULL(ni_ibcls);
     ni_ibcls = (*env)->NewGlobalRef(env, ni_ibcls);
@@ -546,6 +519,9 @@
     ni_ibbroadcastID = (*env)->GetFieldID(env, ni_ibcls, "broadcast", "Ljava/net/Inet4Address;");
     CHECK_NULL(ni_ibbroadcastID);
     ni_ibmaskID = (*env)->GetFieldID(env, ni_ibcls, "maskLength", "S");
+    CHECK_NULL(ni_ibmaskID);
+
+    initInetAddressIDs(env);
 }
 
 /*
@@ -591,7 +567,7 @@
             return NULL;
         }
     }
-    addrArr = (*env)->NewObjectArray(env, netaddrCount, ni_iacls, NULL);
+    addrArr = (*env)->NewObjectArray(env, netaddrCount, ia_class, NULL);
     if (addrArr == NULL) {
         free_netaddr(netaddrP);
         return NULL;
@@ -609,7 +585,7 @@
         jobject iaObj, ia2Obj;
         jobject ibObj = NULL;
         if (addrs->addr.him.sa_family == AF_INET) {
-            iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4Ctor);
+            iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
             if (iaObj == NULL) {
                 free_netaddr(netaddrP);
                 return NULL;
@@ -624,7 +600,7 @@
                 return NULL;
               }
               (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
-              ia2Obj = (*env)->NewObject(env, ni_ia4cls, ni_ia4Ctor);
+              ia2Obj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
               if (ia2Obj == NULL) {
                 free_netaddr(netaddrP);
                 return NULL;
@@ -636,7 +612,7 @@
             }
         } else /* AF_INET6 */ {
             int scope;
-            iaObj = (*env)->NewObject(env, ni_ia6cls, ni_ia6ctrID);
+            iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
             if (iaObj) {
                 int ret = setInet6Address_ipaddress(env, iaObj,  (jbyte *)&(addrs->addr.him6.sin6_addr.s6_addr));
                 if (ret == JNI_FALSE) {
--- a/jdk/src/windows/native/java/net/NetworkInterface.h	Tue Feb 04 18:37:12 2014 +0000
+++ b/jdk/src/windows/native/java/net/NetworkInterface.h	Tue Feb 04 23:40:23 2014 +0000
@@ -70,16 +70,6 @@
 extern jfieldID ni_displayNameID;   /* NetworkInterface.displayName */
 extern jfieldID ni_childsID;        /* NetworkInterface.childs */
 
-extern jclass ni_iacls;             /* InetAddress */
-
-extern jclass ni_ia4cls;            /* Inet4Address */
-extern jmethodID ni_ia4Ctor;        /* Inet4Address() */
-
-extern jclass ni_ia6cls;            /* Inet6Address */
-extern jmethodID ni_ia6ctrID;       /* Inet6Address() */
-extern jfieldID ni_ia6ipaddressID;
-extern jfieldID ni_ia6ipaddressID;
-
 extern jclass ni_ibcls;             /* InterfaceAddress */
 extern jmethodID ni_ibctrID;        /* InterfaceAddress() */
 extern jfieldID ni_ibaddressID;     /* InterfaceAddress.address */
--- a/jdk/src/windows/native/java/net/NetworkInterface_winXP.c	Tue Feb 04 18:37:12 2014 +0000
+++ b/jdk/src/windows/native/java/net/NetworkInterface_winXP.c	Tue Feb 04 23:40:23 2014 +0000
@@ -504,7 +504,7 @@
         }
     }
 
-    addrArr = (*env)->NewObjectArray(env, netaddrCount, ni_iacls, NULL);
+    addrArr = (*env)->NewObjectArray(env, netaddrCount, ia_class, NULL);
     if (addrArr == NULL) {
         return NULL;
     }
@@ -522,7 +522,7 @@
         jobject iaObj, ia2Obj;
         jobject ibObj = NULL;
         if (addrs->addr.him.sa_family == AF_INET) {
-            iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4Ctor);
+            iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
             if (iaObj == NULL) {
                 return NULL;
             }
@@ -536,7 +536,7 @@
               return NULL;
             }
             (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
-            ia2Obj = (*env)->NewObject(env, ni_ia4cls, ni_ia4Ctor);
+            ia2Obj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
             if (ia2Obj == NULL) {
               free_netaddr(netaddrP);
               return NULL;
@@ -547,7 +547,7 @@
             (*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj);
         } else /* AF_INET6 */ {
             int scope;
-            iaObj = (*env)->NewObject(env, ni_ia6cls, ni_ia6ctrID);
+            iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
             if (iaObj) {
                 int ret = setInet6Address_ipaddress(env, iaObj, (jbyte *)&(addrs->addr.him6.sin6_addr.s6_addr));
                 if (ret == JNI_FALSE) {
--- a/jdk/src/windows/native/sun/nio/ch/IOUtil.c	Tue Feb 04 18:37:12 2014 +0000
+++ b/jdk/src/windows/native/sun/nio/ch/IOUtil.c	Tue Feb 04 23:40:23 2014 +0000
@@ -33,6 +33,7 @@
 
 #include "nio.h"
 #include "nio_util.h"
+#include "net_util.h"
 #include "sun_nio_ch_IOUtil.h"
 
 /* field id for jlong 'handle' in java.io.FileDescriptor used for file fds */
@@ -55,6 +56,7 @@
     CHECK_NULL(clazz = (*env)->FindClass(env, "java/io/FileDescriptor"));
     CHECK_NULL(fd_fdID = (*env)->GetFieldID(env, clazz, "fd", "I"));
     CHECK_NULL(handle_fdID = (*env)->GetFieldID(env, clazz, "handle", "J"));
+    initInetAddressIDs(env);
 }
 
 /**************************************************************