Question:
Does Dex Optimization happens each time we reboot the device ? Or the dex files are stored into the system itself, and used for second time ?
Directory : system/framework
Files : core.jar, core-junit.jar , framework.jar , etc...
Source Code Analysis:
It looks like, the system check if there is already dex file in the cache, if exist, it just ignores, if not it creates a dex file.
http://androidxref.com/4.1.2/xref/dalvik/vm/RawDexFile.cpp :
optFd = dvmOpenCachedDexFile(fileName, cachedName, modTime,
adler32, isBootstrap, &newFile, /*createIfMissing=*/true);
This 'newFile' flag tells if dex file exists in the cache,
Below is the code which actually invokes dex optimization over the file.
if (newFile) {
......
result = dvmOptimizeDexFile(optFd, dexOffset, fileSize,
fileName, modTime, adler32, isBootstrap);
Logcat Output:
03-29 12:16:59.617 D/dalvikvm( 1071): DexOpt: --- END 'core.jar' (success) ---
03-29 12:16:59.617 D/dalvikvm( 1071): DEX prep '/system/framework/core.jar': unzip in 239ms, rewrite 3943ms
03-29 12:16:59.617 D/dalvikvm( 1071): DexOpt: --- BEGIN 'core-junit.jar' (bootstrap=1) ---
03-29 12:16:59.664 D/dalvikvm( 1372): DexOpt: load 4ms, verify+opt 10ms, 137044 bytes
03-29 12:17:00.250 D/dalvikvm( 1071): DexOpt: --- END 'core-junit.jar' (success) ---
03-29 12:17:00.250 D/dalvikvm( 1071): DEX prep '/system/framework/core-junit.jar': unzip in
0ms, rewrite 627ms
03-29 12:17:00.304 D/dalvikvm( 1071): DexOpt: --- BEGIN 'bouncycastle.jar' (bootstrap=1) ---
03-29 12:17:00.882 D/dalvikvm( 1373): DexOpt: load 25ms, verify+opt 463ms, 598508 bytes
03-29 12:17:01.507 D/dalvikvm( 1071): DexOpt: --- END 'bouncycastle.jar' (success) ---
03-29 12:17:01.507 D/dalvikvm( 1071): DEX prep '/system/framework/bouncycastle.jar': unzip
in 49ms, rewrite 1204ms
03-29 12:17:01.632 D/dalvikvm( 1071): DexOpt: --- BEGIN 'ext.jar' (bootstrap=1) ---
Does Dex Optimization happens each time we reboot the device ? Or the dex files are stored into the system itself, and used for second time ?
Directory : system/framework
Files : core.jar, core-junit.jar , framework.jar , etc...
Source Code Analysis:
It looks like, the system check if there is already dex file in the cache, if exist, it just ignores, if not it creates a dex file.
http://androidxref.com/4.1.2/xref/dalvik/vm/RawDexFile.cpp :
optFd = dvmOpenCachedDexFile(fileName, cachedName, modTime,
adler32, isBootstrap, &newFile, /*createIfMissing=*/true);
This 'newFile' flag tells if dex file exists in the cache,
Below is the code which actually invokes dex optimization over the file.
if (newFile) {
......
result = dvmOptimizeDexFile(optFd, dexOffset, fileSize,
fileName, modTime, adler32, isBootstrap);
Logcat Output:
03-29 12:16:59.617 D/dalvikvm( 1071): DexOpt: --- END 'core.jar' (success) ---
03-29 12:16:59.617 D/dalvikvm( 1071): DEX prep '/system/framework/core.jar': unzip in 239ms, rewrite 3943ms
03-29 12:16:59.617 D/dalvikvm( 1071): DexOpt: --- BEGIN 'core-junit.jar' (bootstrap=1) ---
03-29 12:16:59.664 D/dalvikvm( 1372): DexOpt: load 4ms, verify+opt 10ms, 137044 bytes
03-29 12:17:00.250 D/dalvikvm( 1071): DexOpt: --- END 'core-junit.jar' (success) ---
03-29 12:17:00.250 D/dalvikvm( 1071): DEX prep '/system/framework/core-junit.jar': unzip in
0ms, rewrite 627ms
03-29 12:17:00.304 D/dalvikvm( 1071): DexOpt: --- BEGIN 'bouncycastle.jar' (bootstrap=1) ---
03-29 12:17:00.882 D/dalvikvm( 1373): DexOpt: load 25ms, verify+opt 463ms, 598508 bytes
03-29 12:17:01.507 D/dalvikvm( 1071): DexOpt: --- END 'bouncycastle.jar' (success) ---
03-29 12:17:01.507 D/dalvikvm( 1071): DEX prep '/system/framework/bouncycastle.jar': unzip
in 49ms, rewrite 1204ms
03-29 12:17:01.632 D/dalvikvm( 1071): DexOpt: --- BEGIN 'ext.jar' (bootstrap=1) ---