<span id="Label3"><p><p> tag:android virtual Machine </p> </p><p><p> <span style="color:rgb (51,51,51); font-family:arial; font-size:14px; line-height:26px"> 1, The most significant difference between Dalvik virtual machines and Java virtual machines is that they have different class file formats and instruction sets, Respectively. </span> <span style="font-family:arial; font-size:14px; line-height:26px"><span style="color: #ff0000">dalvik virtual machines using Dex (Dal Vik Executable) Format Class file, While the Java Virtual machine uses class file </span> </span> <span style="color:rgb (51,51,51) in class format; font-family:arial; font-size:14px; LINE-HEIGHT:26PX " . < span> <span style="font-family:arial; font-size:14px; line-height:26px"><span style="color: #ff0000"> A dex file can contain several classes </span> </span> <span style="color:rgb (51,51,51); font-family:arial; font-size:14px; line-height:26px">, </span> <span style="font-family:arial; font-size:14px; line-height:26px "><span style=" color: #ff0000 "> and a class file includes only one of the classes </span> </span> <span style=" Color:rgb (51,51,51); font-family:arial; font-size:14px; LINE-HEIGHT:26PX " . because a dex file can contain several classes, it save space by saving duplicate strings and other constant numbers in each class, which is suitable for use mobile systems with limited memory processor speed. in general, uncompressed files that the same class are slightly smaller than jar has been compressed. < span></span></span></p></p><p><p><span style="font-family:Arial; font-size:14px; line-height:26px"><span style="color:#333333">2.</span> the <span style="font-family:Arial; font-size:14px; line-height:26px"><span style="color:#ff0000">instructions used by the Dalvik virtual machine are register-based, while the instruction set used by the Java Virtual machine is stack-based</span></span> <span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">. stack-based instructions are compact, for example, the instructions used by a Java Virtual machine account for only one byte and are called Bytecode. register-based instructions require more instruction space, such as two bytes for some instructions of the Dalvik virtual machine, because the source and destination addresses need to be specified. stack-based and register-based instruction sets have pros and cons,</span> and in general, <span style="font-family:Arial; font-size:14px; line-height:26px"><span style="color:#ff0000">performing the same function requires more instruction (mainly load and store instructions), while the latter requires more instruction Space. Requiring more instructions means more CPU time, and requiring more instruction space means that data buffering (d-cache) is more likely to Fail. </span></span></span></p></p><p><p><span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><br></span></span></p></p><p><p> <span style="font-family:arial; font-size:14px; line-height:26px"><span style="font-family:arial; font-size : 14px; line-height:26px "><span style=" color: #333333 "> 3, </span> <span style=" Color:rgb (51,51,51); font-family:arial; font-size:14px; line-height:26px "> in addition, there is a view that the stack-based instruction is more portable because it does not make any assumptions about the register of the target Machine. however, The register-based instruction is more conducive to </span> Aot<span style="color:rgb (51,51,51) because it assumes the register of the target machine; font-family:arial; font-size:14px; line-height:26px "> (ahead-of-time) Optimization. </span> <span style="font-family:arial; font-size:14px; line-height:26px"><span style="color: #ff0000"> The so-called aot, It is to compile the cost of the machine language program before explaining that the language program Runs. The AOT is essentially a static compilation, which is relative to the jit, that is, the former is compiled before the program runs, while the latter is compiled </span> </span> <span style="color:rgb (51,51,51) when the program runs; font-family:arial; font-size:14px; LINE-HEIGHT:26PX " . run-time compilation means that you can use run-time information to get more optimized code compares static compilation, and it also some advanced optimizations are not possible because the optimization process is too time-consuming. on other hand, pre-run optimize regardless of time cost does occupy program run time. the final goal, both aot jit, compile interpreted language into local machine language, local performed based on register, so that, extent, register-based instruction conducive optimization. < span></span></span></span></p></p><p><p><span style="font-family:Arial; font-size:14px; line-height:26px"><span style="font-family:Arial; font-size:14px; line-height:26px"><span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">4.</span></span></span> <span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">no matter what the conclusion is,</span> <span style="font-family:Arial; font-size:14px; line-height:26px"><span style="color:#ff0000">Dalvik virtual machines are trying their best to optimize themselves</span></span> . <span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">, these measures include:</span><span style="font-family:Arial; font-size:14px; line-height:26px"><span style="font-family:Arial; font-size:14px; line-height:26px"><span style="font-family:Arial; font-size:14px; line-height:26px"></span></span></span></p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">(1). Collect multiple class files into the same Dex file to save space;</p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">(2) load the Dex file with a read-only memory map so that the Dex file can be shared by multiple processes, saving program load time;</p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">(3) Adjust the byte order and word alignment (word Alignment) in advance so that they are more suitable for the local machine, in order to improve the speed of instruction execution;</p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">(4) as far as possible in advance byte code verification (bytecode verification), improve the loading speed of the program;</p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">(5) the optimization of bytecode needs to be rewritten in advance.</p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><br></p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">5. Memory Management</p></p><p style="font-family:Arial; font-size:14px; line-height:26px"><p style="font-family:Arial; font-size:14px; line-height:26px"></p></p><p style="font-family:Arial; font-size:14px; line-height:26px"><p style="font-family:Arial; font-size:14px; line-height:26px"><span style="color:rgb(51,51,51)">the memory of the Dalvik virtual machine can be broadly divided into</span> <span style="color:#ff0000">Java Object heap, Bitmap memory, and native heap</span> <span style="color:#333333">three KINDS. </span></p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">The Java object heap is used to allocate Java objects, that is, the object that we have in code new is located on the Java object heap. Dalvik virtual machines at startup, you can specify the minimum and maximum values for the Java Object heap by using THE-XMS and-xmx options. To prevent the performance of the Dalvik virtual machine from adjusting the size of the Java Object heap while it is running, we can set its minimum and maximum values to equal with THE-XMS and-xmx options.</p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><br></p></p><p style="font-family:Arial; font-size:14px; line-height:26px"><p style="font-family:Arial; font-size:14px; line-height:26px">the <span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">maximum value of this Java Object heap is the maximum amount of memory that we normally call the Android application process to Use. It is important to note</span>that the<span style="font-family:Arial; font-size:14px; line-height:26px"><span style="color:#ff0000">maximum memory that the Android application process can use refers to the heap that can be used to allocate Java Object. </span></span><br></p></p><br><p style="font-family:Arial; font-size:14px; line-height:26px"><p style="font-family:Arial; font-size:14px; line-height:26px"><span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">in the honeycomb and later versions,</span> <span style="font-family:Arial; font-size:14px; line-height:26px"><span style="color:#ff0000">Bitmap memory is allocated directly in the Java Object heap so that it can be directly accepted for GC management</span></span> <span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">. </span></p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"></p></p><p style="font-family:Arial; font-size:14px; line-height:26px"><p style="font-family:Arial; font-size:14px; line-height:26px"><span style="color:rgb(51,51,51)">Native heap is used in Native code to allocate memory such as malloc, which is not limited by the size of the Java Object heap, that is, it is free to use, of course, it will be limited by the System. It is important to note, however, that the native heap is not abused because it is free to use</span> <span style="color:#ff0000">because the misuse of the native heap can lead to a drastic reduction in the amount of memory available to the system, causing the system to take radical steps to kill certain processes to replenish available memory. This can affect the system experience. </span></p></p><br><p style="font-family:Arial; font-size:14px; line-height:26px"><p style="font-family:Arial; font-size:14px; line-height:26px">6. Garbage Collection</p></p><p style="font-family:Arial; font-size:14px; line-height:26px"><p style="font-family:Arial; font-size:14px; line-height:26px"><span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">Dalvik virtual machines can automatically reclaim Java objects that are no longer in Use.</span> <span style="font-family:Arial; font-size:14px; line-height:26px"><span style="color:#ff0000">This is the Java Object that is no longer referenced. The automatic garbage collection mechanism frees developers from memory problems,</span></span> <span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">greatly improving development efficiency and improving the maintainability of the Program. </span><br></p></p><p style="font-family:Arial; font-size:14px; line-height:26px"><p style="font-family:Arial; font-size:14px; line-height:26px"><span style="font-family:Arial; font-size:14px; line-height:26px"></span></p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">In gingerbread and later versions, the Dalvik virtual use garbage collection mechanism is improved as follows:</p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">(1) cocurrent, that is, in most cases, the garbage collection thread is executed concurrently with other threads;</p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">(2) Partial collection, that is, may collect only part of the rubbish at a time;</p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">(3) The program abort time caused by one garbage collection is usually less than 5ms.</p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><br></p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><br></p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">7. <span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">process and thread management</span></p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">In general, the process and threads of a virtual machine correspond to the process and thread one by one of the target Machine's local operating system, and the benefit is that the local operating system can be used to dispatch processes and THREADS. Process and thread scheduling is the core module of the operating system, its implementation is very complex, especially considering the multi-core situation, so there is absolutely no need to provide a process and line libraries in the virtual MACHINE.</span><br></span></p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><br></span></span></p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">The Dalvik virtual machine runs on top of the Linux operating System. We know that the Linux operating system does not have a purely threading concept, as long as two processes share the same address space, then they can be thought of as two threads of the same process. The Linux operating system provides two fork and clone two calls, where the former is used to create the process, and the latter is used to create the THREAD.</span><br></span></span></p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><br></span></span></span></p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">There are two great features about the Android app process, and Here's a brief introduction.</span><br></span></p></p><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><br></span></span></p></p><p style="font-family:Arial; font-size:14px; line-height:26px"><p style="font-family:Arial; font-size:14px; line-height:26px"><span style="font-family:Arial; font-size:14px; line-height:26px"><span style="color:#ff0000">The first feature is that every Android application process has a Dalvik virtual machine instance. </span></span> <span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">The advantage of this is that there is no interaction between Android application processes, meaning that an unexpected abort of an Android application process does not affect the normal operation of other Android application Processes. </span><br></p></p><p style="font-family:Arial; font-size:14px; line-height:26px"><p style="font-family:Arial; font-size:14px; line-height:26px"><span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><br></span></p></p><span style="font-family:Arial; font-size:14px; line-height:26px">a <span style="font-family:Arial; font-size:14px; line-height:26px"><span style="color:#ff0000">second feature is that every Android application process is forked out by a process called zygote</span></span> .</span><span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">. The zygote process is initiated by the Init process, which is initiated when the system is Started. When the zygote process starts, it creates a virtual machine instance and loads all of the Java core libraries in this virtual machine instance. Whenever the zygote process needs to create an Android application process, it is implemented by copying itself, that is, by the fork system Call. These forked Android application processes, on the one hand, replicate the virtual machine instances in the zygote process and share the same set of Java core Libraries with the zygote process. This not only makes the process of Android applications fast, but also saves memory space because all Android application processes share the same set of Java core Libraries. </span></span><br><p style="font-family:Arial; font-size:14px; line-height:26px"><p style="font-family:Arial; font-size:14px; line-height:26px"><span style="font-family:Arial; font-size:14px; line-height:26px"><span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"><br></span></span></p></p><p style="font-family:Arial; font-size:14px; line-height:26px"><p style="font-family:Arial; font-size:14px; line-height:26px"><span style="font-family:Arial; font-size:14px; line-height:26px"><span style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px">Pick From: http://blog.csdn.net/luoshengyang/article/details/8852432</span></span></p></p><p><p>Android Virtual Machine Learning Summary Dalvik Virtual machine Introduction</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service