Linked by Thom Holwerda on Tue 10th Jul 2012 17:08 UTC
PDAs, Cellphones, Wireless I've been flashing CyanogenMod 9 nightlies for months now, and the process to do so has become pretty much muscle memory at this point (if cwm ever changes its menu order I'm screwed). One step of this process has always fascinated me simply because I have no idea what exactly it does and why I have to do it: clearing Dalvik cache.
Order by: Score:
Comment by anevilyak
by anevilyak on Tue 10th Jul 2012 17:15 UTC
anevilyak
Member since:
2005-09-14

My understanding of it is that in the process of installing an Android app onto a particular device, various optimizations are made to its Java class files in order to perform more efficiently on the particular hardware contained in that device. These optimized variants are stored in the cache so they don't need to be recomputed each time (along with any JIT optimizations that are made as a result of runtime analysis of the program after you've run it a few times). Since the bytecode format can change between Android versions, that cache would potentially need to be cleared to force all that to be regenerated in the newer format.

Reply Score: 14

RE: Comment by anevilyak
by fatjoe on Tue 10th Jul 2012 18:19 UTC in reply to "Comment by anevilyak"
fatjoe Member since:
2010-01-12

The word you are searching for is AOT compilation cache.

(the android cache partition also contains some data)

Reply Score: 4

RE[2]: Comment by anevilyak
by anevilyak on Tue 10th Jul 2012 20:24 UTC in reply to "RE: Comment by anevilyak"
anevilyak Member since:
2005-09-14

Will try to remember that, thanks!

Reply Score: 2

RE[2]: Comment by anevilyak
by JAlexoid on Wed 11th Jul 2012 13:20 UTC in reply to "RE: Comment by anevilyak"
JAlexoid Member since:
2009-05-19

Not necessarily. Dalvik doesn't do AOT compilation. It does do resource optimization and layout formats.

Reply Score: 3

RE[3]: Comment by anevilyak
by pgeorgi on Wed 11th Jul 2012 16:30 UTC in reply to "RE[2]: Comment by anevilyak"
pgeorgi Member since:
2010-02-18

Dalvik doesn't do AOT compilation.

Though it definitely would be nice to add that.. There's no need to re-JIT the on-screen keyboard task every time it's loaded...

Having the code mmapped also reduces strain on the memory management (since filebacked mappings can be dumped to storage easily).

Would also create opportunities for expensive optimizations which could be scheduled for when the device is "asleep" and externally powered.

Essentially FX!32 for Dalvik.

Reply Score: 2

RE: Comment by anevilyak
by Thom_Holwerda on Tue 10th Jul 2012 19:54 UTC in reply to "Comment by anevilyak"
Thom_Holwerda Member since:
2005-06-29

Thanks for the clear answer, Rene!

Reply Score: 2

RE[2]: Comment by anevilyak
by galvanash on Tue 10th Jul 2012 23:43 UTC in reply to "RE: Comment by anevilyak"
galvanash Member since:
2006-01-25

Thanks for the clear answer, Rene!


If you want a more nitty gritty detailed explanation, read this:

http://www.netmite.com/android/mydroid/dalvik/docs/dexopt.html

Also, just fyi - this is the stuff a large chunk of the Oracle patent lawsuit was about... Namely whether dexopt was violating Oracle's patent on dynamic optimizations. The end result of what they were arguing about is what ends up in the dalvik cache.

Reply Score: 4

Not usinig GooManager?
by rklrkl on Tue 10th Jul 2012 18:26 UTC
rklrkl
Member since:
2005-07-06

I've been using GooManager for a while (yes, it's on Google Play) to flash the nightly CM9 ROMs on my HP TouchPad - it might knock a step or two off your procedure, Thom! A bonus with GooManager is that it lists non-CM9 ROMs too, plus knows about the various Google Apps versions and will let you add those as well.

Edited 2012-07-10 18:26 UTC

Reply Score: 2

RE: Not usinig GooManager?
by Bill Shooter of Bul on Tue 10th Jul 2012 22:22 UTC in reply to "Not usinig GooManager?"
Bill Shooter of Bul Member since:
2006-07-14

RomManager anyone?

It used to work great for CM9 nightlies. For some reason it doesn't list them, only the CM7's now.

In any case, a nightly in late june screwed up wifi bandwidth or latency. Then I screwed up and accidentally installed a CM 7.2 over CM9 with not fun results. Had to do a full wipe of data to get the phone working again. But it works great now!

Reply Score: 2

RE: Not usinig GooManager?
by Thom_Holwerda on Tue 10th Jul 2012 23:27 UTC in reply to "Not usinig GooManager?"
Thom_Holwerda Member since:
2005-06-29

I prefer doing stuff like this in a sparse and Spartan environment - it better fits the task. On top of that, I prefer the old-fashioned non-touch cwm, since using touch instead of the physical volume/power buttons just seems like a very stupid idea for dangerous and possibly destructive tasks like this.

Reply Score: 2

Comment by LB06
by LB06 on Tue 10th Jul 2012 18:47 UTC
LB06
Member since:
2005-07-06

Actually, you don't have to wipe the Dalvik cache. Or the regular cache for that matter. They will be automatically refreshed as required.

Reply Score: 1

RE: Comment by LB06
by kwanbis on Tue 10th Jul 2012 21:25 UTC in reply to "Comment by LB06"
kwanbis Member since:
2005-07-06

Yeah, right.

Reply Score: 3

RE: Comment by LB06
by jimmystewpot on Tue 10th Jul 2012 23:17 UTC in reply to "Comment by LB06"
jimmystewpot Member since:
2006-01-19

that is definitely not my experience.. the number of problems I've had with my own custom roms that are as a direct result of not clearing the cache..... too many to count..

I wish it worked as the docs say.. maybe i miss something in my config

Reply Score: 2

RE: Comment by LB06
by galvanash on Tue 10th Jul 2012 23:54 UTC in reply to "Comment by LB06"
galvanash Member since:
2006-01-25

Actually, you don't have to wipe the Dalvik cache. Or the regular cache for that matter. They will be automatically refreshed as required.


While that is true for a non-rooted device, the minute you root an android device it goes out the window. Once you have rooted you have put the device in a state where it is entirely possible for things to get seriously out of whack because you will of course start installing things that don't follow all the rules religiously. That and odds are you will start changing boot-loaders and ROMs and other things that were _never_ meant to be changed in isolation, and there are different tools that do this differently - some clear the caches for you automatically when they think it is the right thing to do, but some don't...

In short, it is certainly possible to get away with not clearing the dalvik cache, but the rules are so complex as to what you can and cannot do without requiring a cache clear that it is simply more reliable to _always_ clear the cache when making a low level change. Think of it as good hygiene.

Reply Score: 3

RE: Comment by LB06
by LB06 on Wed 11th Jul 2012 02:21 UTC in reply to "Comment by LB06"
LB06 Member since:
2005-07-06

Well, I guess it depends on what you're running. When you update (to) a CM9 rom you'll notice that at the first boot Android is rebuilding the cache for all applications. THAT's the Dalvik cache rebuilding afaik.

So it seems we are all right. Yes, the Dalvik cache needs to be rebuilt, but you don't have to manually wipe it.

Reply Score: 2

RE[2]: Comment by LB06
by FadeFx on Wed 11th Jul 2012 10:27 UTC in reply to "RE: Comment by LB06"
FadeFx Member since:
2011-08-01

You all are partially right, there is no need to wipe dalvik cache after flashing a nightly build as the installer script does it for you, but, it is not always neccessary at all, only when there have been changes to the dalvik-vm, which indeed happens relatively rarely. However to be on the safe side cm does it on every flash.

So Thom, if u want to ease the process of flashing nightlies, get the rom manager pro (its worth those few bucks) and use it to download and flash the latest one, the pro version can even be used to notify you if a new version is available.

Reply Score: 1

No clue...
by Morgan on Tue 10th Jul 2012 20:39 UTC
Morgan
Member since:
2005-06-29

What is it? I have no idea. Is it truly necessary to clear the cache? Well on my first Android phone, a Motorola Cliq (SB200), if I didn't clear it the phone would crash after installing or updating CM7. On my Nook Color, I once forgot to clear the cache and it still booted fine.

I wish I could offer more but that particular subject is over my head.

Reply Score: 2

janito.vff
Member since:
2012-07-10

I could be wrong, but some of the optimizations could be between different intermediate files (classes for example), and if there is a slight change in one of those interfaces between versions, the optimizations might no longer work. Therefore it could result in failure to boot (if the application was critical to the system), or maybe just some force-closes.

Again, pure speculation...

Reply Score: 1

ODEX
by Lorin on Wed 11th Jul 2012 00:12 UTC
Lorin
Member since:
2010-04-06

That is where the "ODEX" files are stored for each application, that applies to all ROMS that are deodexed.

Reply Score: 1

JVM Bytecode to "native"
by Lennie on Wed 11th Jul 2012 11:50 UTC
Lennie
Member since:
2007-09-22

Java is compiled to processor independant bytecode so you can run it on any device which has a JVM which understands that bytecode. The bytecode is "the program" you download onto your device.

That bytecode than gets "compiled" at runtime optimized for the processor it is running on (x86, ARM, AMD64, etc.). This is what they call Just-In-Time compilation is. Depending on how JIT is done, it can mean that only the part of the code that is used will be JIT compiled.

As some examples: PHP files are also compiles to bytecode before it is run. The bytecode is what is actually 'running' when a PHP-script is doing it's work, it is interpreting the bytecode.

JavaScript doesn't use a bytecode intermediate, I believe. But it does do the JIT compilation to optimise for the processor it is running on.

Anyway, I assume the cache you mentioned is the used for the result of the JIT compilation.

And the reason why it needs to be cleared I guess is because for Android system classes it would always use the JIT and not even check if it the bytecode is newer/different/has been updated.

Edited 2012-07-11 11:53 UTC

Reply Score: 1

RE: JVM Bytecode to "native"
by Lennie on Fri 13th Jul 2012 23:59 UTC in reply to "JVM Bytecode to "native""
Lennie Member since:
2007-09-22

Seems I was wrong, at least the Firefox JavaScript engine (and I assume the other do too) compiles the script source to bytecode as well.

Reply Score: 2

RE[2]: JVM Bytecode to "native"
by zima on Tue 17th Jul 2012 23:33 UTC in reply to "RE: JVM Bytecode to "native""
zima Member since:
2005-07-06

Overall, you mix a bit carelessly interpretation, compilation, and JIT over there.

Reply Score: 2

thank you
by sadaf1230 on Sun 15th Jul 2012 08:54 UTC
sadaf1230
Member since:
2012-07-14

beautiful sharing, really interesting, keep it up
9th calss result 2012
http://www.biseresult.pk/9th-class.html

Reply Score: 1