Commit 7861ea9a authored by Elliott Hughes's avatar Elliott Hughes
Browse files

Remove OSNetworkSystem.oneTimeInitialization.

Do this work at JNI registration time, as we do for almost everything else.
(I did this to rule out a warning from the dalvikvm deadlock prediction
code, which doesn't like the unusual lock ordering at initialization time,
and although it didn't make any difference to that, I prefer to have a
defined static order of initialization.)
parent 546ebfa5
......@@ -51,9 +51,11 @@ public class DatagramSocket {
private static class Lock {
}
static {
Platform.getNetworkSystem().oneTimeInitialization(true);
}
// BEGIN android-removed: we do this statically, when we start the VM.
// static {
// Platform.getNetworkSystem().oneTimeInitialization(true);
// }
// END android-removed
private Object lock = new Lock();
......
......@@ -42,9 +42,11 @@ public class ServerSocket {
private boolean isClosed;
static {
Platform.getNetworkSystem().oneTimeInitialization(true);
}
// BEGIN android-removed: we do this statically, when we start the VM.
// static {
// Platform.getNetworkSystem().oneTimeInitialization(true);
// }
// END android-removed
/**
* Constructs a new {@code ServerSocket} instance which is not bound to any
......
......@@ -78,9 +78,11 @@ public class Socket {
return logger;
}
static {
Platform.getNetworkSystem().oneTimeInitialization(true);
}
// BEGIN android-removed: we do this statically, when we start the VM.
// static {
// Platform.getNetworkSystem().oneTimeInitialization(true);
// }
// END android-removed
/**
* Creates a new unconnected socket. When a SocketImplFactory is defined it
......
......@@ -260,5 +260,7 @@ public interface INetworkSystem {
public Channel inheritedChannel();
public void oneTimeInitialization(boolean jcl_supports_ipv6);
// BEGIN android-removed: we do this statically, when we start the VM.
// public void oneTimeInitialization(boolean jcl_supports_ipv6);
// END android-removed
}
......@@ -46,7 +46,7 @@ final class OSNetworkSystem implements INetworkSystem {
private static final int INETADDR_REACHABLE = 0;
private static boolean isNetworkInited = false;
// private static boolean isNetworkInited = false; android-removed
private static OSNetworkSystem singleton = new OSNetworkSystem();
......@@ -310,14 +310,10 @@ final class OSNetworkSystem implements INetworkSystem {
static native void listenStreamSocketImpl(FileDescriptor aFD, int backlog)
throws SocketException;
public void oneTimeInitialization(boolean jcl_supports_ipv6) {
if (!isNetworkInited) {
oneTimeInitializationImpl(jcl_supports_ipv6);
isNetworkInited = true;
}
}
native void oneTimeInitializationImpl (boolean jcl_supports_ipv6);
// BEGIN android-removed: we do this statically, when we start the VM.
// public void oneTimeInitialization(boolean jcl_supports_ipv6);
// native void oneTimeInitializationImpl(boolean jcl_supports_ipv6);
// END android-removed
/**
* Peek on the socket, update <code>sender</code> address and answer the
......
......@@ -1350,10 +1350,7 @@ static void mcastAddDropMembership(JNIEnv *env, int handle, jobject optVal,
}
#endif // def ENABLE_MULTICAST
static void osNetworkSystem_oneTimeInitializationImpl(JNIEnv* env, jobject obj,
jboolean jcl_supports_ipv6) {
// LOGD("ENTER oneTimeInitializationImpl of OSNetworkSystem");
static bool initCachedFields(JNIEnv* env) {
memset(&gCachedFields, 0, sizeof(gCachedFields));
struct CachedFields *c = &gCachedFields;
......@@ -1373,7 +1370,7 @@ static void osNetworkSystem_oneTimeInitializationImpl(JNIEnv* env, jobject obj,
for (unsigned i = 0; i < sizeof(classes) / sizeof(classes[0]); i++) {
classInfo c = classes[i];
jclass tempClass = env->FindClass(c.name);
if (tempClass == NULL) return;
if (tempClass == NULL) return false;
*c.clazz = (jclass) env->NewGlobalRef(tempClass);
}
......@@ -1398,7 +1395,7 @@ static void osNetworkSystem_oneTimeInitializationImpl(JNIEnv* env, jobject obj,
} else {
*m.method = env->GetMethodID(m.clazz, m.name, m.signature);
}
if (*m.method == NULL) return;
if (*m.method == NULL) return false;
}
struct fieldInfo {
......@@ -1422,8 +1419,9 @@ static void osNetworkSystem_oneTimeInitializationImpl(JNIEnv* env, jobject obj,
for (unsigned i = 0; i < sizeof(fields) / sizeof(fields[0]); i++) {
fieldInfo f = fields[i];
*f.field = env->GetFieldID(f.clazz, f.name, f.type);
if (*f.field == NULL) return;
if (*f.field == NULL) return false;
}
return true;
}
/**
......@@ -2923,7 +2921,6 @@ static jobject osNetworkSystem_inheritedChannel(JNIEnv* env, jobject obj) {
*/
static JNINativeMethod gMethods[] = {
/* name, signature, funcPtr */
{ "oneTimeInitializationImpl", "(Z)V", (void*) osNetworkSystem_oneTimeInitializationImpl },
{ "createStreamSocketImpl", "(Ljava/io/FileDescriptor;Z)V", (void*) osNetworkSystem_createStreamSocketImpl },
{ "createDatagramSocketImpl", "(Ljava/io/FileDescriptor;Z)V", (void*) osNetworkSystem_createDatagramSocketImpl },
{ "readSocketImpl", "(Ljava/io/FileDescriptor;[BIII)I", (void*) osNetworkSystem_readSocketImpl },
......@@ -2968,7 +2965,7 @@ static JNINativeMethod gMethods[] = {
};
int register_org_apache_harmony_luni_platform_OSNetworkSystem(JNIEnv* env) {
return jniRegisterNativeMethods(env,
return initCachedFields(env) && jniRegisterNativeMethods(env,
"org/apache/harmony/luni/platform/OSNetworkSystem",
gMethods,
NELEM(gMethods));
......
......@@ -44,9 +44,11 @@ import org.apache.harmony.luni.platform.Platform;
public abstract class DatagramChannel extends AbstractSelectableChannel
implements ByteChannel, ScatteringByteChannel, GatheringByteChannel {
static {
Platform.getNetworkSystem().oneTimeInitialization(true);
}
// BEGIN android-removed: we do this statically, when we start the VM.
// static {
// Platform.getNetworkSystem().oneTimeInitialization(true);
// }
// END android-removed
/**
* Constructs a new {@code DatagramChannel}.
......
......@@ -59,9 +59,11 @@ import org.apache.harmony.luni.platform.Platform;
public abstract class SocketChannel extends AbstractSelectableChannel implements
ByteChannel, ScatteringByteChannel, GatheringByteChannel {
static {
Platform.getNetworkSystem().oneTimeInitialization(true);
}
// BEGIN android-removed: we do this statically, when we start the VM.
// static {
// Platform.getNetworkSystem().oneTimeInitialization(true);
// }
// END android-removed
/**
* Constructs a new {@code SocketChannel}.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment