The Android system tool for Optimizing and Verifying applications
The Android system comes with an Optimizer and Verifier for applications. This tool is called dexopt. Its primary task is to verify the dalvik bytecode of applications and optimize the bytecode for efficient execution. Dexopt is a native program which uses libdex / dvm [1] in order to parse the dex file and interpret the dalvik bytecode. It will be called for every application when it gets installed on an Android device. If the verification fails the application gets rejected and will not be installed on the device. After the applications has been verified dexopt generates an optimized version of it. This will be stored for later execution in the dalvik-cache directory. These two steps will also be executed when the devices boots up for all applications which haven't been optimized before.
The verification is not a security feature in the first place! It is easy to circumvent most parts of it where it is not recommended for application developers to do so. Dexopt checks the dex file structure and does a detailed bytecode analysis. By this the installation process can reject broken applications early before they can be executed. The verification of the bytecode has another very important advantage. The optimizing engine can assume much stricter preconditions on the bytecode, which results in better optimization.
At the moment we are more interested in the dalvik bytecode analysis/optimization. Dexopt analyzes all methods for all classes within the dex file. This will be done by a linear sweep algorithm which iterates over the bytecode. For each instruction different checks/optimization steps will be executed.