- About Scala
- In the Enterprise
- Scala Community
- Language Research
- In the Press
- The Scala Team
- Scala's Prehistory
- Contact Us
- Learning Scala
- Tour of Scala
- Scala API
- Setup & Getting Started
- Programming Guides
- Other Guides
- Code Examples
- Scala Developers
Scala 2.9.x's problems with the DalvikVM
while I had a somewhat workable solution to create some simple Android
apps with Scala, I've now come to the point (as well) where Dalvik
fails either while dexopt'ing a proguarded Scala program or later at
runtime when it tries to load a class (basically reported in ). I'm
starting this thread to gather some more information to find out how
this problem can be solved by Scala, Android, or at all.
The basic problem lies in in dalvik's custom memory allocator,
LinearAlloc. Without going into details, it seems like that allocator
is used similar to the PermGen in HotSpot to allocate class data, like
vtables etc. The problem here is that this allocation region is
statically fixed to 5 MB  per classloader.
For a program that fails consider the single line from SI-4620:
class ObservableTest extends ArrayBuffer[Int]
Even if proguarded, ArrayBuffer alone has such a trail of dependencies
that those 5MB are not enough.
I patched dexopt to log for what purpose and what class it is
allocating memory, here's the output .
(The line 'D/dalvikvm(14166): CLASS: linking 'Ljava/lang/Class;'...'
always comes in between the corresponding entries for the class)
As you can see at the end there are classes which need big amounts of
memory, I think that's because the huge number of methods in those
classes coming from several interfaces.
As a starter, here are some suggestions how to go further from here:
* Find out which classes exactly cause the problem, and how big the
memory would have to be to support Scala
* Try to use multiple class loaders to have multiple allocation regions of 5 MB
* Work with the Android team to find a better general allocator scheme
* Try to reduce the footprint (of the most common parts) of the Scala library
* Find out why proguard can't shrink Scala's library further into
better consumable bits
* Create a more lightweight Scala library for Android development
More to come...