Dalvik virtual machines are still commonly used. So I studied the Dalvik Virtual Machine and shared it with you here. I hope it will be useful to you. After a long period of study on the Dalvik virtual machine, so I would like to share with you that you will certainly have a lot of gains after reading this article. I hope this article will teach you more things.
A lot of implementation code comes from the Apache Harmony project. The main purpose is to ensure the maximum compatibility between the virtual machine class library and the Java SE class library, this reduces the difficulty for application developers to move from the Java SE camp to the Android development camp and increases their availability.
Dalvik virtual machines are mainly used to manage object lifecycles, stack management, thread management, security and exception management, and garbage collection. The main features of Dalvik virtual machines are very suitable for use on mobile terminals. Compared with virtual machines running on desktop and server systems, it does not require high CPU speed and a large amount of memory space.
According to Google's calculations, 64 m RAM has been able to make the system operate normally. Among them, 24 m is used for initialization and startup of the underlying system, and 20 m is used for high-level startup of high-level services. Of course, with the increase of system services and the expansion of application functions, the memory consumption will inevitably increase. In summary, the Dalvik virtual machine has the following main features:
Java virtual machine runs Java bytecode, while Dalvik virtual machine runs its proprietary file format DEXDalvik Executable ).
The Java class in the Java SE program will be compiled into one or more bytecode files. class) and then packaged into the JAR file. Then, the Java Virtual Machine obtains the corresponding bytecode from the corresponding CLASS file and JAR file;
Although Android applications are programming in Java, after compiling and translating a CLASS file, a tool dx is used to convert all the CLASS files in the application into a DEX file, then the Dalvik virtual opportunity reads commands and data from it. Dalvik and Android are the next generation of Linux-based open-source mobile phone operating systems. Their system architecture can be divided into the following parts: the application framework application of the Android Runtime Library of the Linux kernel local library.
.
DEX optimization the DEX file structure is compact. However, if we want to further improve the runtime performance, we still need to further optimize the DEX file. The optimization mainly targets the following aspects:
◆ Adjust the byte order of all fields LITTLE_ENDIAN) and none of the fields in the alignment structure
◆ Verify all classes in the DEX File
◆ Optimize some specific classes and the operation codes in the methods
◆ The optimized file size will increase, which should be 1-4 times that of the original DEX file.
◆ There are two optimization scenarios: for pre-built applications, you can generate an optimization file after the system compilation, ending with ODEX. In this way, in addition to the APK file does not include DEX), there is a corresponding ODEX file. For non-preset applications, the DEX file contained in the APK file will be optimized during runtime, the optimized files will be saved in the cache.
Compared with stack-based virtual machines, register-based virtual machines are less universal in hardware, but they are more efficient in code execution. Generally speaking, the explain execution time of commands in virtual machines is mainly spent in the following three aspects:
◆ Delivery instructions
◆ Number of access operations
◆ Perform operations