Loading core/java/com/android/internal/os/ZygoteInit.java +4 −54 Original line number Diff line number Diff line Loading @@ -19,10 +19,8 @@ package com.android.internal.os; import static libcore.io.OsConstants.S_IRWXG; import static libcore.io.OsConstants.S_IRWXO; import android.content.pm.ActivityInfo; import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.net.LocalServerSocket; import android.os.Debug; import android.os.Process; Loading Loading @@ -87,12 +85,6 @@ public class ZygoteInit { */ static final int GC_LOOP_COUNT = 10; /** * If true, zygote forks for each peer. If false, a select loop is used * inside a single process. The latter is preferred. */ private static final boolean ZYGOTE_FORK_MODE = false; /** * The name of a resource file that contains classes to preload. */ Loading Loading @@ -549,11 +541,7 @@ public class ZygoteInit { Log.i(TAG, "Accepting command socket connections"); if (ZYGOTE_FORK_MODE) { runForkMode(); } else { runSelectLoopMode(); } runSelectLoop(); closeServerSocket(); } catch (MethodAndArgsCaller caller) { Loading @@ -565,44 +553,6 @@ public class ZygoteInit { } } /** * Runs the zygote in accept-and-fork mode. In this mode, each peer * gets its own zygote spawner process. This code is retained for * reference only. * * @throws MethodAndArgsCaller in a child process when a main() should * be executed. */ private static void runForkMode() throws MethodAndArgsCaller { while (true) { ZygoteConnection peer = acceptCommandPeer(); int pid; pid = Zygote.fork(); if (pid == 0) { // The child process should handle the peer requests // The child does not accept any more connections try { sServerSocket.close(); } catch (IOException ex) { Log.e(TAG, "Zygote Child: error closing sockets", ex); } finally { sServerSocket = null; } peer.run(); break; } else if (pid > 0) { peer.closeSocket(); } else { throw new RuntimeException("Error invoking fork()"); } } } /** * Runs the zygote process's select loop. Accepts new connections as * they happen, and reads commands from connections one spawn-request's Loading @@ -611,9 +561,9 @@ public class ZygoteInit { * @throws MethodAndArgsCaller in a child process when a main() should * be executed. */ private static void runSelectLoopMode() throws MethodAndArgsCaller { ArrayList<FileDescriptor> fds = new ArrayList(); ArrayList<ZygoteConnection> peers = new ArrayList(); private static void runSelectLoop() throws MethodAndArgsCaller { ArrayList<FileDescriptor> fds = new ArrayList<FileDescriptor>(); ArrayList<ZygoteConnection> peers = new ArrayList<ZygoteConnection>(); FileDescriptor[] fdArray = new FileDescriptor[4]; fds.add(sServerSocket.getFileDescriptor()); Loading Loading
core/java/com/android/internal/os/ZygoteInit.java +4 −54 Original line number Diff line number Diff line Loading @@ -19,10 +19,8 @@ package com.android.internal.os; import static libcore.io.OsConstants.S_IRWXG; import static libcore.io.OsConstants.S_IRWXO; import android.content.pm.ActivityInfo; import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.net.LocalServerSocket; import android.os.Debug; import android.os.Process; Loading Loading @@ -87,12 +85,6 @@ public class ZygoteInit { */ static final int GC_LOOP_COUNT = 10; /** * If true, zygote forks for each peer. If false, a select loop is used * inside a single process. The latter is preferred. */ private static final boolean ZYGOTE_FORK_MODE = false; /** * The name of a resource file that contains classes to preload. */ Loading Loading @@ -549,11 +541,7 @@ public class ZygoteInit { Log.i(TAG, "Accepting command socket connections"); if (ZYGOTE_FORK_MODE) { runForkMode(); } else { runSelectLoopMode(); } runSelectLoop(); closeServerSocket(); } catch (MethodAndArgsCaller caller) { Loading @@ -565,44 +553,6 @@ public class ZygoteInit { } } /** * Runs the zygote in accept-and-fork mode. In this mode, each peer * gets its own zygote spawner process. This code is retained for * reference only. * * @throws MethodAndArgsCaller in a child process when a main() should * be executed. */ private static void runForkMode() throws MethodAndArgsCaller { while (true) { ZygoteConnection peer = acceptCommandPeer(); int pid; pid = Zygote.fork(); if (pid == 0) { // The child process should handle the peer requests // The child does not accept any more connections try { sServerSocket.close(); } catch (IOException ex) { Log.e(TAG, "Zygote Child: error closing sockets", ex); } finally { sServerSocket = null; } peer.run(); break; } else if (pid > 0) { peer.closeSocket(); } else { throw new RuntimeException("Error invoking fork()"); } } } /** * Runs the zygote process's select loop. Accepts new connections as * they happen, and reads commands from connections one spawn-request's Loading @@ -611,9 +561,9 @@ public class ZygoteInit { * @throws MethodAndArgsCaller in a child process when a main() should * be executed. */ private static void runSelectLoopMode() throws MethodAndArgsCaller { ArrayList<FileDescriptor> fds = new ArrayList(); ArrayList<ZygoteConnection> peers = new ArrayList(); private static void runSelectLoop() throws MethodAndArgsCaller { ArrayList<FileDescriptor> fds = new ArrayList<FileDescriptor>(); ArrayList<ZygoteConnection> peers = new ArrayList<ZygoteConnection>(); FileDescriptor[] fdArray = new FileDescriptor[4]; fds.add(sServerSocket.getFileDescriptor()); Loading