Zygote Preloaded Classes

3,329 views
Skip to first unread message

bnovc

unread,
Sep 23, 2009, 2:03:16 PM9/23/09
to android-platform
I'm looking into adding to frameworks/base/preloaded-classes. There
are a few basic classes that we've added that a lot of the
applications and services are using.

I was using `procrank` to attempt to measure the memory difference. I
expected that Uss should go down, as the amount of shared resources
goes up, but the opposite seems to happen. I'm not sure if the
differences I'm seeing are just noise in the system.

I then saw frameworks/base/tools/preload, which seems promising to
help determine if my changes should be added. I can't find any
documentation about it, but it seems like you're supposed to do
something like:
adb logcat > logcat.txt
(as root) java -cp preload.jar Compile logcat.txt logcat.compiled
then, either
(as root) java -cp preload.jar PrintCsv logcat.compiled
or
(as root) java -cp preload.jar PrintPsTree logcat.compiled

Then I'm guessing you can open the csv or ps to see statistics about
the preloaded classes (from skimming through the source). When I
attempt to run Compile, it fails, though:

# java -cp out/host/linux-x86/framework/preload.jar Compile logcat.txt
logcat.compiled
Got bad response for null: Dalvik VM init failed (check log file)
Got memory usage for null.
Writing object model...
Done!

# adb shell dalvikvm -Xbootclasspath:/system/framework/core.jar:/
system/framework/ext.jar:/system/framework/framework.jar:/system/
framework/framework-tests.jar:/system/framework/services.jar:/system/
framework/loadclass.jar
Dalvik VM init failed (check log file)

I don't have a /system/framework/loadclass.jar, nor are there any
references to it online. If I remove it, the same error occurs. I
don't know where the log file is at. The logs in /dev/log are some
binaries that I don't know the reader for.

So,
1) Does anyone know how I'm supposed to use preload?
2) Is there a different way I should be measuring the changes?

Thanks

PS It would also be helpful to have a README with this code.

Dianne Hackborn

unread,
Sep 23, 2009, 5:25:15 PM9/23/09
to android-...@googlegroups.com
All preloaded-classes is, is a list of fully qualified class names for zygote to load during system boot.  You just edit the file to add or remove classes as desired.

The actual contents of that file is a serious black art, that we continue to try to tune and tweak.  There have been various tools written that try to automate the creation of this list (by looking at application sizes, load times, and other metrics), but as of 1.6 it is still something that ultimately needs to be tuned by hand.

That said, if you have a new class in the core framework that gets used in every application, it is probably worth adding to the list.  Though watch out what things it is dependent on that it would also caused to be pulled in.
--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

Dan Bornstein

unread,
Sep 23, 2009, 5:51:11 PM9/23/09
to android-...@googlegroups.com
On Wed, Sep 23, 2009 at 2:25 PM, Dianne Hackborn <hac...@android.com> wrote:
> That said, if you have a new class in the core framework that gets used in
> every application, it is probably worth adding to the list.  Though watch
> out what things it is dependent on that it would also caused to be pulled
> in.

In particular, preloaded classes cannot (directly or indirectly) cause
threads to be started, even transiently. The zygote process is limited
to being single-threaded. I don't think anything verifies
single-threadedness at runtime, but Strange Things may happen if the
zygote spawns a thread.

-dan

Anthony

unread,
Sep 24, 2009, 8:41:12 AM9/24/09
to android-platform
Thanks Dianne and Dan.

I think I had realized that much from reading the source, but I wasn't
sure of a good way to determine whether it was worthwhile to add the
classes we've created, since my normal measurements were fluctuating.

That's why I was curious about the preload.jar or other methods people
may be using.

On Sep 23, 4:51 pm, Dan Bornstein <danf...@android.com> wrote:

GeunSik Lim (invain)

unread,
Sep 24, 2009, 8:34:38 PM9/24/09
to android-platform


On Sep 24, 6:51 am, Dan Bornstein <danf...@android.com> wrote:
> On Wed, Sep 23, 2009 at 2:25 PM, Dianne Hackborn <hack...@android.com> wrote:
> In particular, preloaded classes cannot (directly or indirectly) cause
> threads to be started, even transiently. The zygote process is limited
> to being single-threaded. I don't think anything verifies
I am confusing because of single-threaded expression a bit.
As we all know, Zygote is just process that pre-forked for speed-up.
Dan, Did you explain using single-thread word about Zygote
because Zygote have 2827 task in "/process/2827/task/*" folder as
single-threaded.?
For example ( 2827 is Zygote Process),
target#> ls /proc/2827/task/
2827
target#> cat /proc/2827/status | grep Threads
Threads: 1

> single-threadedness at runtime, but Strange Things may happen if the zygote spawns a thread.
Yes, I guess so.
Preforked Zygote make application process
when New tasks like Home,Contacts created by User.
So, I think that the zygote have to fork a new process without a new
thread.

In a summary,
When we run browseron android platform ,
broswer applicaiton process is made by Zygote Process.
And the, browser process consists of below threads.

Thread-No Thread-Name
-----------------------------------------
861 app_process (com.android.browser )
862 HeapWorker
863 Signal Catcher
864 JDWP (Java Debug Wire Protocol)
865 Binder Thread #
866 Binder Thread #
867 Binder Thread #
870 CookieSyncManager
872 AsyncTask #1 (computation that runs on a background thread)
873 WebViewCoreThread
876 WebViewCoreThread
877 WebViewCoreThread
879 http0
880 http1
881 http2
882 http3


> -dan

Jean-Baptiste Queru

unread,
Sep 25, 2009, 9:00:08 AM9/25/09
to android-...@googlegroups.com
I think Dan meant "you can't use threads in zygote before it forks".

JBQ
--
Jean-Baptiste M. "JBQ" Queru
Software Engineer, Android Open-Source Project, Google.

Questions sent directly to me that have no reason for being private
will likely get ignored or forwarded to a public forum with no further
warning.

Dianne Hackborn

unread,
Sep 25, 2009, 12:57:27 PM9/25/09
to android-...@googlegroups.com
Yep.  Though technically you can't use threads IN zygote at any time.  You can use them once zygote forks and becomes a non-zygote process.  (One reason for this is that on Linux when you for a process, only a main thread is create for the new process.  Any other threads that were running in the original process don't have a corresponding thread in the new one, leaking whatever state they had, left holding whatever synchronization objects they had, etc.  Bad.)

Nitin

unread,
May 6, 2013, 5:56:52 AM5/6/13
to android-...@googlegroups.com, hac...@android.com
Hello,

I was looking to parallelize class and resource preloading. I was trying to do this to save some boot time and I am trying this in JB.

Though I experimented with it and it worked fine, but still wanted to check what could be the impact of this?

Does this single threaded nature of Zygote still holds true?

regards
-Nitin
Reply all
Reply to author
Forward
0 new messages