Merge "Remove unnecessary explicit GC in ZygoteInit."
This commit is contained in:
@@ -86,12 +86,6 @@ public class ZygoteInit {
|
|||||||
*/
|
*/
|
||||||
private static Resources mResources;
|
private static Resources mResources;
|
||||||
|
|
||||||
/**
|
|
||||||
* The number of times that the main Zygote loop
|
|
||||||
* should run before calling gc() again.
|
|
||||||
*/
|
|
||||||
static final int GC_LOOP_COUNT = 10;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of a resource file that contains classes to preload.
|
* The name of a resource file that contains classes to preload.
|
||||||
*/
|
*/
|
||||||
@@ -286,11 +280,6 @@ public class ZygoteInit {
|
|||||||
float defaultUtilization = runtime.getTargetHeapUtilization();
|
float defaultUtilization = runtime.getTargetHeapUtilization();
|
||||||
runtime.setTargetHeapUtilization(0.8f);
|
runtime.setTargetHeapUtilization(0.8f);
|
||||||
|
|
||||||
// Start with a clean slate.
|
|
||||||
System.gc();
|
|
||||||
runtime.runFinalizationSync();
|
|
||||||
Debug.startAllocCounting();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
BufferedReader br
|
BufferedReader br
|
||||||
= new BufferedReader(new InputStreamReader(is), 256);
|
= new BufferedReader(new InputStreamReader(is), 256);
|
||||||
@@ -309,15 +298,6 @@ public class ZygoteInit {
|
|||||||
Log.v(TAG, "Preloading " + line + "...");
|
Log.v(TAG, "Preloading " + line + "...");
|
||||||
}
|
}
|
||||||
Class.forName(line);
|
Class.forName(line);
|
||||||
if (Debug.getGlobalAllocSize() > PRELOAD_GC_THRESHOLD) {
|
|
||||||
if (false) {
|
|
||||||
Log.v(TAG,
|
|
||||||
" GC at " + Debug.getGlobalAllocSize());
|
|
||||||
}
|
|
||||||
System.gc();
|
|
||||||
runtime.runFinalizationSync();
|
|
||||||
Debug.resetGlobalAllocSize();
|
|
||||||
}
|
|
||||||
count++;
|
count++;
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
Log.w(TAG, "Class not found for preloading: " + line);
|
Log.w(TAG, "Class not found for preloading: " + line);
|
||||||
@@ -347,8 +327,6 @@ public class ZygoteInit {
|
|||||||
// Fill in dex caches with classes, fields, and methods brought in by preloading.
|
// Fill in dex caches with classes, fields, and methods brought in by preloading.
|
||||||
runtime.preloadDexCaches();
|
runtime.preloadDexCaches();
|
||||||
|
|
||||||
Debug.stopAllocCounting();
|
|
||||||
|
|
||||||
// Bring back root. We'll need it later.
|
// Bring back root. We'll need it later.
|
||||||
setEffectiveUser(ROOT_UID);
|
setEffectiveUser(ROOT_UID);
|
||||||
setEffectiveGroup(ROOT_GID);
|
setEffectiveGroup(ROOT_GID);
|
||||||
@@ -366,10 +344,7 @@ public class ZygoteInit {
|
|||||||
private static void preloadResources() {
|
private static void preloadResources() {
|
||||||
final VMRuntime runtime = VMRuntime.getRuntime();
|
final VMRuntime runtime = VMRuntime.getRuntime();
|
||||||
|
|
||||||
Debug.startAllocCounting();
|
|
||||||
try {
|
try {
|
||||||
System.gc();
|
|
||||||
runtime.runFinalizationSync();
|
|
||||||
mResources = Resources.getSystem();
|
mResources = Resources.getSystem();
|
||||||
mResources.startPreloading();
|
mResources.startPreloading();
|
||||||
if (PRELOAD_RESOURCES) {
|
if (PRELOAD_RESOURCES) {
|
||||||
@@ -394,22 +369,12 @@ public class ZygoteInit {
|
|||||||
mResources.finishPreloading();
|
mResources.finishPreloading();
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
Log.w(TAG, "Failure preloading resources", e);
|
Log.w(TAG, "Failure preloading resources", e);
|
||||||
} finally {
|
|
||||||
Debug.stopAllocCounting();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int preloadColorStateLists(VMRuntime runtime, TypedArray ar) {
|
private static int preloadColorStateLists(VMRuntime runtime, TypedArray ar) {
|
||||||
int N = ar.length();
|
int N = ar.length();
|
||||||
for (int i=0; i<N; i++) {
|
for (int i=0; i<N; i++) {
|
||||||
if (Debug.getGlobalAllocSize() > PRELOAD_GC_THRESHOLD) {
|
|
||||||
if (false) {
|
|
||||||
Log.v(TAG, " GC at " + Debug.getGlobalAllocSize());
|
|
||||||
}
|
|
||||||
System.gc();
|
|
||||||
runtime.runFinalizationSync();
|
|
||||||
Debug.resetGlobalAllocSize();
|
|
||||||
}
|
|
||||||
int id = ar.getResourceId(i, 0);
|
int id = ar.getResourceId(i, 0);
|
||||||
if (false) {
|
if (false) {
|
||||||
Log.v(TAG, "Preloading resource #" + Integer.toHexString(id));
|
Log.v(TAG, "Preloading resource #" + Integer.toHexString(id));
|
||||||
@@ -430,14 +395,6 @@ public class ZygoteInit {
|
|||||||
private static int preloadDrawables(VMRuntime runtime, TypedArray ar) {
|
private static int preloadDrawables(VMRuntime runtime, TypedArray ar) {
|
||||||
int N = ar.length();
|
int N = ar.length();
|
||||||
for (int i=0; i<N; i++) {
|
for (int i=0; i<N; i++) {
|
||||||
if (Debug.getGlobalAllocSize() > PRELOAD_GC_THRESHOLD) {
|
|
||||||
if (false) {
|
|
||||||
Log.v(TAG, " GC at " + Debug.getGlobalAllocSize());
|
|
||||||
}
|
|
||||||
System.gc();
|
|
||||||
runtime.runFinalizationSync();
|
|
||||||
Debug.resetGlobalAllocSize();
|
|
||||||
}
|
|
||||||
int id = ar.getResourceId(i, 0);
|
int id = ar.getResourceId(i, 0);
|
||||||
if (false) {
|
if (false) {
|
||||||
Log.v(TAG, "Preloading resource #" + Integer.toHexString(id));
|
Log.v(TAG, "Preloading resource #" + Integer.toHexString(id));
|
||||||
@@ -459,7 +416,7 @@ public class ZygoteInit {
|
|||||||
* softly- and final-reachable objects, along with any other garbage.
|
* softly- and final-reachable objects, along with any other garbage.
|
||||||
* This is only useful just before a fork().
|
* This is only useful just before a fork().
|
||||||
*/
|
*/
|
||||||
/*package*/ static void gc() {
|
/*package*/ static void gcAndFinalize() {
|
||||||
final VMRuntime runtime = VMRuntime.getRuntime();
|
final VMRuntime runtime = VMRuntime.getRuntime();
|
||||||
|
|
||||||
/* runFinalizationSync() lets finalizers be called in Zygote,
|
/* runFinalizationSync() lets finalizers be called in Zygote,
|
||||||
@@ -468,9 +425,6 @@ public class ZygoteInit {
|
|||||||
System.gc();
|
System.gc();
|
||||||
runtime.runFinalizationSync();
|
runtime.runFinalizationSync();
|
||||||
System.gc();
|
System.gc();
|
||||||
runtime.runFinalizationSync();
|
|
||||||
System.gc();
|
|
||||||
runtime.runFinalizationSync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -613,7 +567,7 @@ public class ZygoteInit {
|
|||||||
SamplingProfilerIntegration.writeZygoteSnapshot();
|
SamplingProfilerIntegration.writeZygoteSnapshot();
|
||||||
|
|
||||||
// Do an initial gc to clean up after startup
|
// Do an initial gc to clean up after startup
|
||||||
gc();
|
gcAndFinalize();
|
||||||
|
|
||||||
// Disable tracing so that forked processes do not inherit stale tracing tags from
|
// Disable tracing so that forked processes do not inherit stale tracing tags from
|
||||||
// Zygote.
|
// Zygote.
|
||||||
@@ -682,27 +636,9 @@ public class ZygoteInit {
|
|||||||
fds.add(sServerSocket.getFileDescriptor());
|
fds.add(sServerSocket.getFileDescriptor());
|
||||||
peers.add(null);
|
peers.add(null);
|
||||||
|
|
||||||
int loopCount = GC_LOOP_COUNT;
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
/*
|
|
||||||
* Call gc() before we block in select().
|
|
||||||
* It's work that has to be done anyway, and it's better
|
|
||||||
* to avoid making every child do it. It will also
|
|
||||||
* madvise() any free memory as a side-effect.
|
|
||||||
*
|
|
||||||
* Don't call it every time, because walking the entire
|
|
||||||
* heap is a lot of overhead to free a few hundred bytes.
|
|
||||||
*/
|
|
||||||
if (loopCount <= 0) {
|
|
||||||
gc();
|
|
||||||
loopCount = GC_LOOP_COUNT;
|
|
||||||
} else {
|
|
||||||
loopCount--;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fdArray = fds.toArray(fdArray);
|
fdArray = fds.toArray(fdArray);
|
||||||
index = selectReadable(fdArray);
|
index = selectReadable(fdArray);
|
||||||
|
|||||||
Reference in New Issue
Block a user