Fix the boot time regression caused by DexUseManagerLocal init.

See details in the bug.

Before:
D SystemServerTiming: DexUseManagerLocal
I system_server: Waiting for a blocking GC ClassLinker
I system_server: Background concurrent copying GC freed 207020(9016KB) AllocSpace objects, 21(896KB) LOS objects, 49% free, 12MB/25MB, paused 56us,21us total 209.779ms
I system_server: WaitForGcToComplete blocked ClassLinker on Background for 177.623ms
V SystemServerTiming: DexUseManagerLocal took to complete: 182ms

After:
D SystemServerTiming: ArtModuleServiceInitializer
V SystemServerTiming: ArtModuleServiceInitializer took to complete: 3ms
...
D SystemServerTiming: DexUseManagerLocal
V SystemServerTiming: DexUseManagerLocal took to complete: 20ms

Bug: 263373204
Test: manual - See above.
Change-Id: I81e517fd3c18ccd3490947b16e36e7d43b2fc07c
This commit is contained in:
Jiakai Zhang
2022-12-21 22:52:08 +00:00
parent e5773c3ffd
commit 1b7dda73e0

View File

@@ -1049,6 +1049,17 @@ public final class SystemServer implements Dumpable {
private void startBootstrapServices(@NonNull TimingsTraceAndSlog t) {
t.traceBegin("startBootstrapServices");
t.traceBegin("ArtModuleServiceInitializer");
// This needs to happen before DexUseManagerLocal init. We do it here to avoid colliding
// with a GC. ArtModuleServiceInitializer is a class from a separate dex file
// "service-art.jar", so referencing it involves the class linker. The class linker and the
// GC are mutually exclusive (b/263486535). Therefore, we do this here to force trigger the
// class linker earlier. If we did this later, especially after PackageManagerService init,
// the class linker would be consistently blocked by a GC because PackageManagerService
// allocates a lot of memory and almost certainly triggers a GC.
ArtModuleServiceInitializer.setArtModuleServiceManager(new ArtModuleServiceManager());
t.traceEnd();
// Start the watchdog as early as possible so we can crash the system server
// if we deadlock during early boot
t.traceBegin("StartWatchdog");
@@ -1235,8 +1246,6 @@ public final class SystemServer implements Dumpable {
t.traceBegin("DexUseManagerLocal");
// DexUseManagerLocal needs to be loaded after PackageManagerLocal has been registered, but
// before PackageManagerService starts processing binder calls to notifyDexLoad.
// DexUseManagerLocal may also call artd, so ensure ArtModuleServiceManager is instantiated.
ArtModuleServiceInitializer.setArtModuleServiceManager(new ArtModuleServiceManager());
LocalManagerRegistry.addManager(
DexUseManagerLocal.class, DexUseManagerLocal.createInstance());
t.traceEnd();