changing the heap limit on apps

by devi prasad » Sun, 29 Mar 2009 16:57:10 GMT

Sponsored Links
Can someone point me to the code that enforces the 16MB heap limit?
If we want to increase the allowed heap size to say 24MB, what
additional care should we take so we do not violate other guarantees
already enforced in the system?




changing the heap limit on apps

by devi prasad » Sun, 29 Mar 2009 18:26:44 GMT

 well, looking around I found the following in dalvik/vm/init.c:

/* Defaults overridden by -Xms and -Xmx.
 * TODO: base these on a system or application-specific default
gDvm.heapSizeStart = 2 * 1024 * 1024;   // Spec says 16MB; too big for us.
gDvm.heapSizeMax = 16 * 1024 * 1024;    // Spec says 75% physical mem;

I notice that gDvm.heapSizeMax gets passed (directly or indirectly) to
the rest of the vm code.
Also, are the comments mentioned in the code true? Can we avoid the
default limit by passing larger values to the said arguments?




Sponsored Links

changing the heap limit on apps

by fadden » Mon, 30 Mar 2009 19:43:04 GMT


You can, if you can pass the arguments.  The VM is embedded in the
Android runtime, not launched on the command line.

What you're really looking for is in frameworks/base/core/jni/
AndroidRuntime.cpp; search for CUSTOM_RUNTIME_HEAP_MAX to see where
somebody else has already done an override at compile time.  Note the
heap max is passed in through "-Xmx".

The part where this gets tricky is that the VM is only initialized
once; all subsequent instances of the VM are the result of a fork()
with no exec().  Once the VM has been initialized you can't change the
heap max, because some data structures are sized to match.  Giving one
app a larger virtual heap is most easily accomplished by giving
everybody a larger heap and then forcing most of them to make do with
less than the actual maximum.  The less-easy but better approach would
be to resize the various heap structures, which is a bit awkward but
probably doable since there's only thread running at that point where
the zygote forks.

You can also fork+exec the new process, but now you're losing the size
and startup time advantages that the zygote provides.



changing the heap limit on apps

by devi prasad » Tue, 31 Mar 2009 05:06:32 GMT

 Hi fadden: thanks a lot. This is useful. This is interesting too!



Other Threads

1. sharedpreferences widget

I have a few questions on the default home screen's widget support:

1) if there are multiple instances of the same widget how to
differentiate each (so that the content could be different) eg. world
clock: same clock widget for different countries on diffferent

2) is there any sharedpreferences' equivalent possible with widgets



2. ION kernel source


Can anybody help me find the source for the ION kernel (HTC Dream)?
The config in it is quite different from the one on and
kernels built from there (android-msm-2.6.27 branch) do not boot on my

Thanks in advance


3. How to collect unhandled exception message in the app?

4. Recording mic audio during a call

5. Mic audio capture is of poor quality

6. Compress recorded audio

7. UbiFS SquashFS+lzma to Optimize Speed and save space