Implementations of the disclosure relate to software management in a computing system that hosts a virtual machine.
A virtual machine (VM) is a software emulating implementation of a machine (e.g., a computer) for executing high level programs. A VM provides a platform-independent programming environment that abstracts away details of the underlying hardware or operating system (OS), and allows a high level program to execute in the same way on any platform. One type of VM, sometimes called a Managed Runtime Environment (MRE), runs on top of a host OS to provide an emulation environment for a single process. For VM emulating, high level program (e.g., JAVA) is compiled into a specific bytecode format. To execute on a real hardware machine (e.g., ARM processors, x86 processors, etc.), the bytecode is either compiled or interpreted by a VM to executable machine code.
Android is a commonly-used mobile framework based on the Linux kernel. Android Runtime (ART) is the VM used by some applications and system services in Android. ART as the runtime executes its bytecode in the Dalvik Executable (DEX) format to generate machine code for the target device. A DEX file (.dex) holds a set of class definitions and their associated data.
The predecessor of ART, Dalvik, had evolved over the years from a runtime interpreter into a Just-in-Time (JIT) compiler. During the application runtime, the JIT compiler generates and caches a subset of the executable machine code that was executed most frequently. A more recent version of Dalvik performs runtime verification and optimization by converting a DEX file into an optimized DEX file (.odex). By contrast, ART introduces the use of ahead-of-time (AOT) compilation by statistically pre-compiling an application into native machine code upon its first installation, first booting or first launching. Compared to Dalvik, ART improves the overall execution efficiency and reduces power consumption, which results in improved battery autonomy on mobile devices. At the same time, ART brings faster execution of applications, improved memory allocation and garbage collection (GC) mechanisms, new applications debugging features, and more accurate high-level profiling of applications.
ART pre-compiles an application into native machine code by using an on-device utility called dex2oat. This utility accepts an application package with DEX files as input and generates a compiled machine code file executable by the target device. The machine code file is native binary code for a specific hardware processor, and is formatted as Executable and Linkable Format (ELF). For ART, its filename has .oat as the postfix.
However, the computing time for dex2oat is non-negligible, especially when the system boots for the first time or when an application is installed for the first time. Furthermore, the resulting machine code (ELF file) takes a significantly larger amount of storage space (e.g., 2-3 times more per application) than a DEX bytecode file. Thus, providing ART on low-cost devices with small storage, such as typical mobile devices, remains a challenge to hardware and software developers.
In one implementation, a method is provided for policy-based compression of a machine code file. The method comprises the steps of: generating the machine code file from bytecode by a virtual machine hosted in a computing system; determining whether to compress the machine code file according to a set of conditions specified by a policy; and in response to a determination that the set of conditions is satisfied, compressing the machine code file to a compressed machine code file in the computing system.
In one implementation, a computing system is provided for policy-based compression of a machine code file. The system comprises one or more processors; a (volatile) memory; a (non-volatile) storage; and an interconnect coupled to the memory and the one or more processors. The one or more processors are adapted to: generate the machine code file from bytecode by a virtual machine hosted in the computing system; determine whether to compress the machine code file according to a set of conditions specified by a policy; and in response to a determination that the set of conditions is satisfied, compress the machine code file to a compressed machine code file in the computing system.
In some implementations, for system booting and package installation, the machine code file can be deleted to save storage. When launching an application, the compressed machine code file is decompressed for execution. When the application process terminates, the decompressed machine code file can be deleted. The machine code file compression and deletion can be performed on a mobile device to save its storage space, or on a host to reduce a system image size for decreasing the download time. Parallel file compression and decompression algorithms can be used for compressing and decompressing the machine code file in a multi-core computing system to speed up the time of system booting, the application installation, and the application launching. Alternatively, compression and decompression algorithms can be performed by an additional compression circuitry.
The present disclosure is illustrated by way of example, and not by way of limitation, in the figures of the accompanying drawings in which like references indicate similar elements. It should be noted that different references to “an” or “one” implementation in this disclosure are not necessarily to the same implementation, and such references mean at least one. Further, when a particular feature, structure, or characteristic is described in connection with an implementation, it is submitted that it is within the knowledge of one skilled in the art to effect such feature, structure, or characteristic in connection with other implementations whether or not explicitly described.
In the following description, numerous specific details are set forth. However, it is understood that implementations of the disclosure may be practiced without these specific details. In other instances, well-known circuits, structures and techniques have not been shown in detail in order not to obscure the understanding of this description. It will be appreciated, however, by one skilled in the art, that the disclosure may be practiced without such specific details. Those of ordinary skill in the art, with the included descriptions, will be able to implement appropriate functionality without undue experimentation.
Implementations of the disclosure provide a method and system for policy-based compression of machine code generated by a VM. In one implementation, the method is performed by a mobile device system to save its storage space and to speed up system performance when booting the system, installing a package, launching an application, or other system events. The method can also be performed by a host computing system, e.g., when building a system image, to reduce the system image size for faster download time, such as download by flash tools or over-the-air (OTA) download. The system determines whether to compress a compiled machine code file based on a policy that specifies a set of one or more conditions. The machine code file is compressed if the set of conditions is satisfied. In some implementations, after the machine code file is compressed and saved in the storage, the original machine code file (that was compiled from the bytecode before compression) can be deleted for saving storage. When launching an application, if a compressed machine code file exists, the compressed machine code file is decompressed into a machine code file for execution. When the application process terminates (e.g., stopped by a user or killed by the system), the decompressed machine code file can be deleted from the system to save its storage space.
In some implementations, the compression and decompression may be executed according to a parallel compression algorithm by multiple cores of a multi-core processor, or by special-purpose compression/decompression hardware, to reduce the time required for system booting, package installation, application launching, system image building and other system events.
In the following description, the policy-based compression is described in the context of Android software. It should be understood, however, the policy-based compression may be implemented in any software environment that provides virtual machines for bytecode to machine code translation or compilation. Furthermore, although specific bytecode and machine code file formats, programming languages and utilities are mentioned in the following description, it is understood that the policy-based compression may apply to any bytecode and machine code file formats, programming languages and utilities. In some parts of the following description, Java application programming language and its related software framework are used as examples; however, it is understood that the policy-based compression may be applied to machine code generated by virtual machines that are based on another programming language different from Java.
With respect to the Applications 150, typically the Applications 150 are distributed and installed as Android application packages with a package file format .apk. A package includes Java programs and necessary files with compression, e.g., in a zip format. In general, a package (.apk file) includes classes.dex, which is Dalvik bytecode containing compiled .class files; AndroidManifest.xml, which is a binary file containing package information; resources.arsc, which contains a compiled resource file; a directory Res\, which contains uncompiled resource files; and a directory META-INF\, which is used to certify an application for .apk completeness and security.
In one implementation, for the policy-based compression of machine code, the Android software architecture 100 includes the enhanced dex2oat tool 650 with policy-based compression in Android Runtime 130 and compression module 180 in Libraries 120. Compression module 180 can be used to compress and decompress machine code files. Although the compression module 180 is shown in
In one implementation, the same policy with the same set of conditions may be used for different system events such as system booting, package installation, application launching, application process termination and system image building. In alternative implementations, policies with different sets of conditions may be used for these different events. In yet alternative implementations, some of the events may use the same policy with the same set of conditions, while some others of the events may use policies with different sets of conditions.
In one implementation, the compression module 180 may be called by an enhanced bytecode compilation tool, which is used in ART Runtime 130 to perform not only bytecode to machine code translation but also the policy-based compression of machine code file. An example of the enhanced translation tool in Android is the enhanced dex2oat tool 650, which will be described in further detail below.
In one implementation, each of the computing systems 200 and 300 could be part of a mobile computing and/or communication device (e.g., a smartphone, a tablet, laptop, etc.). In one implementation, each of the computing systems 200 and 300 could be a host computer, or a part of a cloud server system.
In one implementation, the compression module 180 of
After the compression of the machine code file, the original (i.e., uncompressed) machine code file may be deleted if the method 400 is invoked for certain events, such as system booting or package installation. Thus, the original machine code file can be deleted to save storage space, and the compressed machine code file is stored for future use. It is noted that, the original machine code file may be kept in storage without being deleted for the special case that it is known or predicted that the machine code execution is immediate (e.g., within a predetermined time period) or frequent (i.e., above a predetermined frequency threshold), such as when an application is just installed for launching. It is understood that other events not mentioned herein may also cause the original machine code file to be deleted, or to be kept in storage.
More specifically, if a compressed ELF file for the application is not available, the computing system retrieves bytecode from an application package at step 801. At step 802, the computing system compiles (i.e., translates) the bytecode to machine code. In one implementation, the bytecode compilation is performed by a VM hosted in the computing system. At step 803, the computing system writes the machine code into an ELF file in storage. At step 804, the computing system determines whether a set of one or more conditions specified in a policy is satisfied. If satisfied, the ELF file of the machine code is compressed into a compressed file at step 805 and the method 800 ends. If the set of one or more conditions specified in the policy is not satisfied, the method 800 ends without the compression.
PMS 141 further checks whether it is necessary to optimize the bytecode file (e.g., IsDexOptNeeded( )) at step 942. If it is not necessary, then no optimization is performed. If it is necessary to perform the optimization, PMS 141 calls dexopt( ) 943 to Installer 630. Next, Installer 630 performs do_dexopt( ) 951 to Installd 640. Then, Installd 640 invokes dex2oat 961 to enhanced dex2oat 650 if the runtime environment is ART. Finally, the enhanced dex2oat 650 performs the method 400 described in
In one implementation, the method 1000 starts when the application process terminates (e.g., when the application is stopped by a user or killed by the system) at step 1001. At step 1002, the process resources (e.g., memory, I/O, etc.) are released. At step 1003, the computing system determines whether a set of one or more conditions of a predetermined policy is satisfied. If satisfied, the decompressed machine code file is deleted at step 1004 and the method 1000 ends. If the set of one or more conditions is not satisfied, the method 1000 ends without deleting the decompressed machine code file. In one implementation, the policy used in method 1000 may contain a combination of any of the aforementioned conditions, and may additionally include a prediction of whether the decompressed machine code will be immediately used again (i.e., within a predetermined time period).
The methods and processes of
The process 1100 starts when Package_internal.mk 1110 is invoked to perform dexpreopt-one-file 1111. For ART, this causes dex_preopt.mk 1120 to perform dex2oat-one-file 1121. Next, this invokes dex_preopt_libART.mk 1130 to call dex2oat( ) 1131. Finally, the enhanced dex2oat 650 performs the method 400 described in
It is to be understood that the above description is intended to be illustrative, and not restrictive. Many other implementations will be apparent to those of skill in the art upon reading and understanding the above description. Although the present disclosure has been described with reference to specific exemplary implementations, it will be recognized that the disclosure is not limited to the implementations described, but can be practiced with modification and alteration within the spirit and scope of the appended claims. Accordingly, the specification and drawings are to be regarded in an illustrative sense rather than a restrictive sense. The scope of the disclosure should, therefore, be determined with reference to the appended claims, along with the full scope of equivalents to which such claims are entitled.
This application claims the benefit of U.S. Provisional Application No. 62/186,144 filed on Jun. 29, 2015.
Number | Date | Country | |
---|---|---|---|
62186144 | Jun 2015 | US |