diff --git a/make/mapfiles/libnet/mapfile-vers b/make/mapfiles/libnet/mapfile-vers index 0e432d3ef69744c774e56ec09bfb4e915884f9dc..a37668a8418f5177699eef20c3ff4a58f13d27ad 100644 --- a/make/mapfiles/libnet/mapfile-vers +++ b/make/mapfiles/libnet/mapfile-vers @@ -112,6 +112,7 @@ SUNWprivate_1.1 { NET_EnableFastTcpLoopback; NET_ThrowNew; ipv6_available; + initInetAddressIDs; local: *; diff --git a/src/share/native/java/net/Inet4Address.c b/src/share/native/java/net/Inet4Address.c index 62ad3d6a8e26fba1c6351464a0dbc899ca8a558b..cc432414eeaeca6eb3b97ae27e57d873f9a22061 100644 --- a/src/share/native/java/net/Inet4Address.c +++ b/src/share/native/java/net/Inet4Address.c @@ -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 @@ jmethodID ia4_ctrID; */ 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, "", "()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, "", "()V"); + CHECK_NULL(ia4_ctrID); + ia4_initialized = 1; + } } diff --git a/src/share/native/java/net/Inet6Address.c b/src/share/native/java/net/Inet6Address.c index 9b828af55e64eb7d8ef005216fd35f0771862d06..3d0151aafbfe3f7fcd06375717ea2b0f08bda5ed 100644 --- a/src/share/native/java/net/Inet6Address.c +++ b/src/share/native/java/net/Inet6Address.c @@ -42,6 +42,8 @@ jfieldID ia6_scopeidsetID; jfieldID ia6_scopeifnameID; jmethodID ia6_ctrID; +static int ia6_initialized = 0; + /* * Class: java_net_Inet6Address * Method: init @@ -49,24 +51,28 @@ jmethodID ia6_ctrID; */ 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, "", "()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, "", "()V"); + CHECK_NULL(ia6_ctrID); + ia6_initialized = 1; + } } diff --git a/src/share/native/java/net/InetAddress.c b/src/share/native/java/net/InetAddress.c index 607ed356bd4ae0de0c58ea05d5bc8b80f212f69c..3809dd3dca35356745fafc534d2fd7edfa5914cf 100644 --- a/src/share/native/java/net/InetAddress.c +++ b/src/share/native/java/net/InetAddress.c @@ -41,6 +41,8 @@ jfieldID iac_hostNameID; jfieldID iac_origHostNameID; jfieldID ia_preferIPv6AddressID; +static int ia_initialized = 0; + /* * Class: java_net_InetAddress * Method: init @@ -48,23 +50,27 @@ jfieldID ia_preferIPv6AddressID; */ 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;"); - CHECK_NULL(iac_hostNameID); - iac_origHostNameID = (*env)->GetFieldID(env, iac_class, "originalHostName", "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); + iac_origHostNameID = (*env)->GetFieldID(env, iac_class, "originalHostName", "Ljava/lang/String;"); + CHECK_NULL(iac_origHostNameID); + ia_initialized = 1; + } } diff --git a/src/share/native/java/net/net_util.c b/src/share/native/java/net/net_util.c index 56edb6340ca4ebc27b10e1cfecb675f5eb34a40f..2194e2e6ef4a0a955825f52285a441882ddfd04d 100644 --- a/src/share/native/java/net/net_util.c +++ b/src/share/native/java/net/net_util.c @@ -75,11 +75,14 @@ JNI_OnLoad(JavaVM *vm, void *reserved) 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 @@ extern jfieldID iac_familyID; * 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 @@ int getInet6Address_ipaddress(JNIEnv *env, jobject iaObj, char *dest) { 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 @@ int setInet6Address_ipaddress(JNIEnv *env, jobject iaObj, char *address) { 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,53 +167,39 @@ int setInet6Address_ipaddress(JNIEnv *env, jobject iaObj, char *address) { } 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); (*env)->SetObjectField(env, holder, iac_origHostNameID, 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; @@ -239,31 +211,15 @@ NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) { 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); @@ -276,16 +232,7 @@ NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port) { #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)); diff --git a/src/share/native/java/net/net_util.h b/src/share/native/java/net/net_util.h index 9063c3e8d9574f901e3f63a6a1a705a90ca1fcaa..c8a5e68c49f2a302883d4e10921dd9ffe30a25d6 100644 --- a/src/share/native/java/net/net_util.h +++ b/src/share/native/java/net/net_util.h @@ -56,6 +56,8 @@ extern jfieldID iac_hostNameID; extern jfieldID iac_origHostNameID; 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 diff --git a/src/solaris/native/java/net/Inet4AddressImpl.c b/src/solaris/native/java/net/Inet4AddressImpl.c index c8fb987375f7e793517f1bf056b800cd28145abd..ec4f97dfae11ccc5eeff6da0f1bc4e2f30c64b21 100644 --- a/src/solaris/native/java/net/Inet4AddressImpl.c +++ b/src/solaris/native/java/net/Inet4AddressImpl.c @@ -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, "", "()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 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, int getaddrinfo_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"); @@ -242,7 +219,7 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, 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; @@ -252,7 +229,7 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, /* 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; @@ -408,8 +385,8 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, 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"); @@ -487,7 +464,7 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, 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 */ @@ -496,7 +473,7 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, 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; diff --git a/src/solaris/native/java/net/Inet6AddressImpl.c b/src/solaris/native/java/net/Inet6AddressImpl.c index da510a28c9f37344182eb5acd42c164439e4d8b9..e67e25ac4e9894bdb133dba1dcfd22839eee265f 100644 --- a/src/solaris/native/java/net/Inet6AddressImpl.c +++ b/src/solaris/native/java/net/Inet6AddressImpl.c @@ -117,44 +117,6 @@ Java_java_net_Inet6AddressImpl_getLocalHostName(JNIEnv *env, jobject this) { 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, "", "()V"); - CHECK_NULL_RETURN(ni_ia4ctrID, JNI_FALSE); - ni_ia6ctrID = (*env)->GetMethodID(env, ni_ia6cls, "", "()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 @@ lookupIfLocalhost(JNIEnv *env, const char *hostname, jboolean includeV6) 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 @@ -234,10 +195,10 @@ lookupIfLocalhost(JNIEnv *env, const char *hostname, jboolean includeV6) /* 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 { @@ -301,8 +262,8 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, 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"); @@ -429,14 +390,14 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, 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; @@ -449,7 +410,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, 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; @@ -461,7 +422,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, } 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; @@ -555,7 +516,7 @@ Java_java_net_Inet6AddressImpl_getHostByAddr(JNIEnv *env, jobject this, if (!error) { ret = (*env)->NewStringUTF(env, host); - CHECK_NULL(ret); + CHECK_NULL_RETURN(ret, NULL); } #endif /* AF_INET6 */ diff --git a/src/solaris/native/java/net/NetworkInterface.c b/src/solaris/native/java/net/NetworkInterface.c index bb6773fe909a35e9cabcb60f2a60a064b360f488..89a4e4f9bd8e9293aaa7f30afbe8b47e69ad2e15 100644 --- a/src/solaris/native/java/net/NetworkInterface.c +++ b/src/solaris/native/java/net/NetworkInterface.c @@ -133,12 +133,7 @@ jfieldID ni_parentID; 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; @@ -215,26 +210,10 @@ JNIEXPORT void JNICALL Java_java_net_NetworkInterface_init CHECK_NULL(ni_parentID); ni_ctrID = (*env)->GetMethodID(env, ni_class, "", "()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, "", "()V"); - CHECK_NULL(ni_ia4ctrID); - ni_ia6ctrID = (*env)->GetMethodID(env, ni_ia6cls, "", "()V"); - CHECK_NULL(ni_ia6ctrID); ni_ibctrID = (*env)->GetMethodID(env, ni_ibcls, "", "()V"); CHECK_NULL(ni_ibctrID); ni_ibaddressID = (*env)->GetFieldID(env, ni_ibcls, "address", @@ -247,6 +226,9 @@ JNIEXPORT void JNICALL Java_java_net_NetworkInterface_init CHECK_NULL(ni_ib4maskID); ni_defaultIndexID = (*env)->GetStaticFieldID(env, ni_class, "defaultIndex", "I"); + CHECK_NULL(ni_defaultIndexID); + + initInetAddressIDs(env); } /* @@ -700,7 +682,7 @@ static jobject createNetworkInterface(JNIEnv *env, netif *ifs) { } // 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; } @@ -717,7 +699,7 @@ static jobject createNetworkInterface(JNIEnv *env, netif *ifs) { 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)); @@ -729,7 +711,7 @@ static jobject createNetworkInterface(JNIEnv *env, netif *ifs) { (*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)); @@ -747,7 +729,7 @@ static jobject createNetworkInterface(JNIEnv *env, netif *ifs) { #if defined(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) { jboolean ret = setInet6Address_ipaddress(env, iaObj, (char *)&(((struct sockaddr_in6*)addrP->addr)->sin6_addr)); diff --git a/src/solaris/native/java/net/PlainDatagramSocketImpl.c b/src/solaris/native/java/net/PlainDatagramSocketImpl.c index 406654d2086f0803f193a1430f15fee4bf1438a3..c48d1153ce42061c55881355276c8e8f209a18b3 100644 --- a/src/solaris/native/java/net/PlainDatagramSocketImpl.c +++ b/src/solaris/native/java/net/PlainDatagramSocketImpl.c @@ -174,9 +174,8 @@ Java_java_net_PlainDatagramSocketImpl_init(JNIEnv *env, jclass cls) { 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); } diff --git a/src/solaris/native/java/net/PlainSocketImpl.c b/src/solaris/native/java/net/PlainSocketImpl.c index 724c1cfd89e669c4b867dc6d9cfd26e26e069936..71cbdf8ce67d5f00201e62449757aa557198478b 100644 --- a/src/solaris/native/java/net/PlainSocketImpl.c +++ b/src/solaris/native/java/net/PlainSocketImpl.c @@ -162,6 +162,9 @@ Java_java_net_PlainSocketImpl_initProto(JNIEnv *env, jclass cls) { 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(); } diff --git a/src/solaris/native/sun/nio/ch/IOUtil.c b/src/solaris/native/sun/nio/ch/IOUtil.c index 438bf41ddea33be56abcc9b0feaa6cd44c5f8732..d8bbe8492525a370306488c75f8367a1e3b29041 100644 --- a/src/solaris/native/sun/nio/ch/IOUtil.c +++ b/src/solaris/native/sun/nio/ch/IOUtil.c @@ -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 @@ Java_sun_nio_ch_IOUtil_initIDs(JNIEnv *env, jclass clazz) { CHECK_NULL(clazz = (*env)->FindClass(env, "java/io/FileDescriptor")); CHECK_NULL(fd_fdID = (*env)->GetFieldID(env, clazz, "fd", "I")); + initInetAddressIDs(env); } JNIEXPORT jboolean JNICALL diff --git a/src/solaris/native/sun/nio/ch/sctp/SctpNet.c b/src/solaris/native/sun/nio/ch/sctp/SctpNet.c index 1b700bb57caa172c9656f32988f9ae0869a7a1f8..6a5e2cbbb8c3e1bc2b07e353d30a7941f8f8cf97 100644 --- a/src/solaris/native/sun/nio/ch/sctp/SctpNet.c +++ b/src/solaris/native/sun/nio/ch/sctp/SctpNet.c @@ -157,6 +157,7 @@ Java_sun_nio_ch_sctp_SctpNet_init } preCloseFD = sp[0]; close(sp[1]); + initInetAddressIDs(env); } /* diff --git a/src/windows/native/java/net/Inet4AddressImpl.c b/src/windows/native/java/net/Inet4AddressImpl.c index 1f91f95a3bc8e960e21c91b7e1201b00fd4d043c..9e7097ec91020d8e9f210f7b90f6165f069ee167 100644 --- a/src/windows/native/java/net/Inet4AddressImpl.c +++ b/src/windows/native/java/net/Inet4AddressImpl.c @@ -114,11 +114,6 @@ Java_java_net_Inet4AddressImpl_getLocalHostName (JNIEnv *env, jobject this) { 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 @@ -143,19 +138,8 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, 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, "", "()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"); @@ -199,13 +183,13 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, 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; @@ -229,7 +213,7 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, addrp++; } - ret = (*env)->NewObjectArray(env, i, ni_iacls, NULL); + ret = (*env)->NewObjectArray(env, i, ia_class, NULL); if (IS_NULL(ret)) { goto cleanupAndReturn; @@ -238,7 +222,7 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, 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; diff --git a/src/windows/native/java/net/Inet6AddressImpl.c b/src/windows/native/java/net/Inet6AddressImpl.c index c9e48bec48c6bd7d0f1a17c578f8c3b5585155b0..0ebd0613b6a133c2d1576745e4a6a2783e8d605c 100644 --- a/src/windows/native/java/net/Inet6AddressImpl.c +++ b/src/windows/native/java/net/Inet6AddressImpl.c @@ -74,13 +74,6 @@ Java_java_net_Inet6AddressImpl_getLocalHostName (JNIEnv *env, jobject this) { 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) { @@ -88,30 +81,13 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, 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, "", "()V"); - CHECK_NULL_RETURN(ni_ia4ctrID, NULL); - ni_ia6ctrID = (*env)->GetMethodID(env, ni_ia6cls, "", "()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; @@ -119,17 +95,6 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, 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); @@ -231,7 +196,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, 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 */ @@ -248,7 +213,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, 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; @@ -259,7 +224,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, 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; @@ -349,7 +314,7 @@ Java_java_net_Inet6AddressImpl_getHostByAddr(JNIEnv *env, jobject this, if (!error) { ret = (*env)->NewStringUTF(env, host); - CHECK_NULL(ret); + CHECK_NULL_RETURN(ret, NULL); } if (ret == NULL) { diff --git a/src/windows/native/java/net/NetworkInterface.c b/src/windows/native/java/net/NetworkInterface.c index 6483f12619e41e14e45e92234abebc850cd783f3..4dc22a08c0f44b625754e2072949e6286324dd96 100644 --- a/src/windows/native/java/net/NetworkInterface.c +++ b/src/windows/native/java/net/NetworkInterface.c @@ -65,13 +65,6 @@ jfieldID ni_bindsID; /* NetworkInterface.bindings */ 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 @@ Java_java_net_NetworkInterface_init(JNIEnv *env, jclass cls) CHECK_NULL(ni_childsID); ni_ctor = (*env)->GetMethodID(env, ni_class, "", "()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, "", "()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, "", "()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 @@ Java_java_net_NetworkInterface_init(JNIEnv *env, jclass cls) 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 @@ jobject createNetworkInterface 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 createNetworkInterface 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 @@ jobject createNetworkInterface 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 @@ jobject createNetworkInterface } } 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) { diff --git a/src/windows/native/java/net/NetworkInterface.h b/src/windows/native/java/net/NetworkInterface.h index fc40906859690e876fd1604259ba74cbccf499c1..3bf4ed06aecbc466c77b1ddd7d2fae0cb6adb451 100644 --- a/src/windows/native/java/net/NetworkInterface.h +++ b/src/windows/native/java/net/NetworkInterface.h @@ -70,16 +70,6 @@ extern jfieldID ni_nameID; /* NetworkInterface.name */ 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 */ diff --git a/src/windows/native/java/net/NetworkInterface_winXP.c b/src/windows/native/java/net/NetworkInterface_winXP.c index 4042d16d4eff741b3d5976ffad6a672fa1964fbe..8248d3a3dfa6e79fd8135f978a86323ad9c3a201 100644 --- a/src/windows/native/java/net/NetworkInterface_winXP.c +++ b/src/windows/native/java/net/NetworkInterface_winXP.c @@ -513,7 +513,7 @@ static jobject createNetworkInterfaceXP(JNIEnv *env, netif *ifs) } } - addrArr = (*env)->NewObjectArray(env, netaddrCount, ni_iacls, NULL); + addrArr = (*env)->NewObjectArray(env, netaddrCount, ia_class, NULL); if (addrArr == NULL) { return NULL; } @@ -531,7 +531,7 @@ static jobject createNetworkInterfaceXP(JNIEnv *env, netif *ifs) 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; } @@ -545,7 +545,7 @@ static jobject createNetworkInterfaceXP(JNIEnv *env, netif *ifs) 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; @@ -556,7 +556,7 @@ static jobject createNetworkInterfaceXP(JNIEnv *env, netif *ifs) (*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) { diff --git a/src/windows/native/sun/nio/ch/IOUtil.c b/src/windows/native/sun/nio/ch/IOUtil.c index 370dcf5e23f0a2a7e161bca9261ff1b8aad412ae..49de1eb89d7d546eb663b181b78c16adb88f1a11 100644 --- a/src/windows/native/sun/nio/ch/IOUtil.c +++ b/src/windows/native/sun/nio/ch/IOUtil.c @@ -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 @@ Java_sun_nio_ch_IOUtil_initIDs(JNIEnv *env, jclass clazz) 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); } /**************************************************************