Removed reflection use in sun.nio.ch.ServerSocketChannelImpl native code.
Change on 2018/05/22 by antoniocortes
@@ -45,38 +45,22 @@ typedef size_t socklen_t; /* New in SunOS 5.7, so need this for 5.6 */
#include "nio.h"
#include "nio_util.h"
+// Objective C defs.
+#include "java/io/FileDescriptor.h"
+#include "java/net/InetSocketAddress.h"
+
#define NATIVE_METHOD(className, functionName, signature) \
{ #functionName, signature, (void*)(className ## _ ## functionName) }
-
-static jfieldID fd_fdID; /* java.io.FileDescriptor.fd */
-static jclass isa_class; /* java.net.InetSocketAddress */
-static jmethodID isa_ctorID; /* .InetSocketAddress(InetAddress, int) */
-
-
JNIEXPORT void JNICALL
-Java_sun_nio_ch_ServerSocketChannelImpl_initIDs(JNIEnv *env, jclass c)
-{
- jclass cls;
-
- cls = (*env)->FindClass(env, "java/io/FileDescriptor");
- fd_fdID = (*env)->GetFieldID(env, cls, "descriptor", "I");
- [(id)fd_fdID retain];
-
- cls = (*env)->FindClass(env, "java/net/InetSocketAddress");
- isa_class = (*env)->NewGlobalRef(env, cls);
- [(id)isa_class retain];
- isa_ctorID = (*env)->GetMethodID(env, cls, "<init>",
- "(Ljava/net/InetAddress;I)V");
- [(id)isa_ctorID retain];
-}
+Java_sun_nio_ch_ServerSocketChannelImpl_initIDs(JNIEnv *env, jclass c) {}
JNIEXPORT jint JNICALL
Java_sun_nio_ch_ServerSocketChannelImpl_accept0(JNIEnv *env, jobject this,
jobject ssfdo, jobject newfdo,
jobjectArray isaa)
{
- jint ssfd = (*env)->GetIntField(env, ssfdo, fd_fdID);
+ jint ssfd = ((JavaIoFileDescriptor *) ssfdo)->descriptor_;
jint newfd;
struct sockaddr *sa;
int alloc_len;
@@ -113,11 +97,11 @@ Java_sun_nio_ch_ServerSocketChannelImpl_accept0(JNIEnv *env, jobject this,
return IOS_THROWN;
}
- (*env)->SetIntField(env, newfdo, fd_fdID, newfd);
+ ((JavaIoFileDescriptor *) newfdo)->descriptor_ = newfd;
remote_ia = NET_SockaddrToInetAddress(env, sa, (int *)&remote_port);
free((void *)sa);
- isa = (*env)->NewObject(env, isa_class, isa_ctorID,
- remote_ia, remote_port);
+ isa = create_JavaNetInetSocketAddress_initWithJavaNetInetAddress_withInt_(
+ (JavaNetInetAddress *)remote_ia, remote_port);
(*env)->SetObjectArrayElement(env, isaa, 0, isa);
return 1;
}
