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.)
diff --git a/libcore/luni/src/main/java/java/net/DatagramSocket.java b/libcore/luni/src/main/java/java/net/DatagramSocket.java
index ba5e207..0e06788 100644
--- a/libcore/luni/src/main/java/java/net/DatagramSocket.java
+++ b/libcore/luni/src/main/java/java/net/DatagramSocket.java
@@ -51,9 +51,11 @@
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();
diff --git a/libcore/luni/src/main/java/java/net/ServerSocket.java b/libcore/luni/src/main/java/java/net/ServerSocket.java
index f9d5b22..6942577 100644
--- a/libcore/luni/src/main/java/java/net/ServerSocket.java
+++ b/libcore/luni/src/main/java/java/net/ServerSocket.java
@@ -42,9 +42,11 @@
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
diff --git a/libcore/luni/src/main/java/java/net/Socket.java b/libcore/luni/src/main/java/java/net/Socket.java
index 5289566..6ecc548 100644
--- a/libcore/luni/src/main/java/java/net/Socket.java
+++ b/libcore/luni/src/main/java/java/net/Socket.java
@@ -78,9 +78,11 @@
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
diff --git a/libcore/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java b/libcore/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
index 71a272a..a76618f 100644
--- a/libcore/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
+++ b/libcore/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
@@ -260,5 +260,7 @@
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
}
diff --git a/libcore/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java b/libcore/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
index 9901412..831b492 100644
--- a/libcore/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
+++ b/libcore/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
@@ -46,7 +46,7 @@
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 @@
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
diff --git a/libcore/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp b/libcore/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp
index aa4abe5..3f58736 100644
--- a/libcore/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp
+++ b/libcore/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp
@@ -1350,10 +1350,7 @@
}
#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 @@
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 @@
} 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 @@
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 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 @@
};
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));
diff --git a/libcore/nio/src/main/java/java/nio/channels/DatagramChannel.java b/libcore/nio/src/main/java/java/nio/channels/DatagramChannel.java
index 31b0825..3281cf4 100644
--- a/libcore/nio/src/main/java/java/nio/channels/DatagramChannel.java
+++ b/libcore/nio/src/main/java/java/nio/channels/DatagramChannel.java
@@ -44,9 +44,11 @@
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}.
diff --git a/libcore/nio/src/main/java/java/nio/channels/SocketChannel.java b/libcore/nio/src/main/java/java/nio/channels/SocketChannel.java
index 40003ea..ba03a2a 100644
--- a/libcore/nio/src/main/java/java/nio/channels/SocketChannel.java
+++ b/libcore/nio/src/main/java/java/nio/channels/SocketChannel.java
@@ -59,9 +59,11 @@
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}.