An application operation method and electronic device
By removing the translated code fragments of executable files from the terminal device and storing them in non-volatile storage, the memory consumption and I/O overhead issues caused by cross-platform application compatibility are resolved, improving device performance and operating efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HUAWEI TECH CO LTD
- Filing Date
- 2024-12-31
- Publication Date
- 2026-06-30
AI Technical Summary
In existing technologies, when terminal devices are compatible with cross-platform applications, the dynamic translation of executable files leads to increased memory usage and I/O overhead, affecting device performance.
By removing translated original code snippets from the executable file, the amount of code loaded into memory is reduced, and non-volatile storage space is used to store the translated code snippets, ensuring that the application runs correctly on different processor architectures.
It reduces memory usage and I/O loading overhead, improving the performance of terminal devices and the efficiency of application operation.
Smart Images

Figure CN122308950A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of terminal technology, and in particular to an application operation method and an electronic device. Background Technology
[0002] Different operating systems or processor architectures of terminal devices can cause applications that support one operating system or processor architecture to be incompatible with other operating systems or processor architectures, thus preventing them from performing their functions. Therefore, it is necessary to translate the application's executable file into a file that can be executed by other operating systems or processor architectures, thereby achieving cross-platform compatible operation of the application.
[0003] Currently, executable file translation includes pre-translation and dynamic translation. Pre-translation requires translating the executable file corresponding to the application before it runs. However, some code segments in the executable file cannot be pre-translated and need to be dynamically translated at runtime. During dynamic translation, the executable file needs to be loaded into memory, and the code segments that need to be dynamically translated are read from memory. However, this method can easily increase the input / output (I / O) overhead of the terminal device and affect the performance of the terminal device. Summary of the Invention
[0004] This application provides an application running method and an electronic device that can reduce memory usage and lower I / O loading overhead.
[0005] To achieve the above objectives, the embodiments of this application adopt the following technical solutions:
[0006] In a first aspect, an application running method is provided. The method is applied to an electronic device on which the application is installed. First, the electronic device loads a first executable file and a first code fragment of the application into the memory of the electronic device. Then, the electronic device runs the application based on the first code fragment and / or the first executable file.
[0007] The first executable file includes the original code segment of the application after the first original code segment has been removed; the first original code segment can be translated into the first code segment.
[0008] In the above application running method, by removing the first original code segment in the executable file, the number of original code segments of the executable file loaded into memory is reduced, thereby reducing memory usage, lowering I / O loading overhead, and improving the performance of electronic devices.
[0009] In one possible implementation of the first aspect, before the electronic device loads the first executable file and the first code fragment of the application into the electronic device's memory, the electronic device obtains the executable file of the application. Then, the electronic device obtains the first code fragment based on the first original code fragment in the executable file, and then writes the first code fragment into the non-volatile storage space of the electronic device. It is evident that the mobile phone permanently stores the translated first code fragment, which facilitates improving the speed of subsequent application execution by the electronic device.
[0010] In one possible implementation of the first aspect, the electronic device acquires first information, then obtains a first executable file based on the first information, and then writes the first executable file into the non-volatile storage space of the electronic device. The first information includes first tag information and / or second tag information; the first tag information indicates a first original code segment in the executable file, and the second tag information indicates other original code segments in the executable file besides the first original code segment; the first executable file is the executable file after removing the first original code segment. Therefore, the electronic device can remove the translated first original code segment from the executable file using the first information, reconstruct the executable file, and reduce the amount of data subsequently loaded into memory.
[0011] In one possible implementation of the first aspect, the electronic device, in response to a mismatch between the format of the executable file and the format of the electronic device's operating system, translates a first source code segment in the executable file to obtain a first code segment; or, the electronic device, in response to an operation on a selection control on the user interface, translates the first source code segment in the executable file to obtain a first code segment; or, the electronic device, in response to a mismatch between the processor architecture on which the executable file runs and the processor architecture of the electronic device, translates the first source code segment in the executable file to obtain a first code segment. It is evident that the electronic device provides multiple methods for translating executable files, ensuring that executable files subsequently loaded into memory can be correctly executed by the electronic device.
[0012] In one possible implementation of the first aspect, the original code fragment in the first executable file includes multiple program instructions, which are stored contiguously within the first executable file. It is evident that contiguous storage can improve the efficiency of loading the original code fragment into memory.
[0013] In one possible implementation of the first aspect, if a first program instruction exists among multiple program instructions, and the storage location of the first program instruction in the first executable file differs from its storage location within the executable file, the electronic device updates the pointer address of the first program instruction. This pointer address indicates the storage location of the first program instruction. Therefore, updating the pointer address of the first program instruction ensures that the correct first program instruction is subsequently read from memory.
[0014] In one possible implementation of the first aspect, the electronic device reads program instructions to be executed from memory. If the program instructions to be executed are program instructions included in the first code segment, the electronic device executes the program instructions to run the application. It is evident that the electronic device can directly execute the translated program instructions during program execution, thereby improving execution efficiency.
[0015] In one possible implementation of the first aspect, when the program instructions to be executed are program instructions included in the original code segment, the electronic device translates the program instructions to be executed to obtain translated program instructions, and the electronic device runs the translated program instructions to run the application. It is evident that by translating the program instructions in the original code segment in real time during program execution, the electronic device can improve the accuracy of execution and ensure the normal operation of the application.
[0016] In one possible implementation of the first aspect, when the electronic device obtains the executable file of an application, it first obtains the application's installation package, and then decompresses the installation package to obtain the application's executable file. Therefore, the executable file of the electronic device can be obtained by decompressing the installation package, ensuring the accuracy of the executable file.
[0017] In one possible implementation of the first aspect, the electronic device obtains fourth information; the fourth information is used to indicate that the installation package has been decompressed; the electronic device writes the executable file after the installation package has been decompressed into the non-volatile storage space of the electronic device according to the fourth information, so that the electronic device can subsequently obtain the first executable file based on the stored executable file.
[0018] In a second aspect, an electronic device is provided, the electronic device including a memory and one or more processors; the memory is coupled to the processors; wherein the memory stores computer program code, the computer program code including computer instructions, and when the computer instructions are executed by the processor, the electronic device performs an application running method as described in the first aspect and any of its implementations.
[0019] Thirdly, a computer-readable storage medium is provided, including computer instructions that, when executed on an electronic device, cause the electronic device to perform an application execution method as described in the first aspect and any of its implementations.
[0020] Fourthly, a computer program product is provided that, when the computer program product is run on an electronic device, causes the electronic device to execute the application running method as described in the first aspect and any of its implementations.
[0021] The beneficial effects that the electronic device provided in the second aspect, the computer-readable storage medium provided in the third aspect, and the computer program product provided in the fourth aspect can achieve are similar to the beneficial effects that can be achieved in the first aspect and any of its implementations, and will not be repeated here. Attached Figure Description
[0022] Figure 1 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of this application is shown;
[0023] Figure 2 A schematic diagram of the software structure of an electronic device provided in an embodiment of this application is shown;
[0024] Figure 3 A flowchart illustrating the operation of an application according to an embodiment of this application is shown;
[0025] Figure 4 This illustration shows one of the schematic diagrams of an executable file provided in an embodiment of this application;
[0026] Figure 5 This illustration shows a second schematic diagram of an executable file provided in an embodiment of this application;
[0027] Figure 6 This illustration shows a schematic diagram of a first executable file provided in an embodiment of this application;
[0028] Figure 7 A schematic diagram of the hardware structure of another electronic device provided in an embodiment of this application is shown. Detailed Implementation
[0029] The technical solutions of the embodiments of this application will be described below with reference to the accompanying drawings. In the description of this application, unless otherwise stated, " / " indicates that the objects before and after are in an "or" relationship. For example, A / B can represent A or B. "And / or" in this application is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, and B alone, where A and B can be singular or plural. Furthermore, in the description of this application, unless otherwise stated, "multiple" refers to two or more. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one of a, b, or c can represent: a, b, c, ab, ac, bc, or abc, where a, b, and c can be single or multiple. Furthermore, to facilitate a clear description of the technical solutions in the embodiments of this application, the terms "first" and "second" are used in the embodiments of this application to distinguish identical or similar items with substantially the same function and effect. Those skilled in the art will understand that the terms "first" and "second" do not limit the quantity or execution order, and that "first" and "second" are not necessarily different. Meanwhile, in the embodiments of this application, the terms "exemplary" or "for example" are used to indicate that something is being used as an example, illustration, or description. Any embodiment or design scheme described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design schemes. Specifically, the use of terms such as "exemplary" or "for example" is intended to present related concepts in a concrete manner for ease of understanding.
[0030] Furthermore, the business scenarios described in the embodiments of this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the emergence of new business scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.
[0031] The executable file will be introduced first:
[0032] Executable files are typically stored in Executable and Linkable Format (ELF) or similar formats. These formats define the internal structure of the executable file, including a code segment. Within the executable file, the code segment is allocated a specific region with a fixed starting position and size to store the application's program instructions (i.e., opcodes and operands that the processor can execute). These instructions are stored directly in the code segment of the executable file in binary code form. During program execution, these instructions are read and executed line by line by the processor to implement the program's logic and functionality. The binary code in an executable file can be divided into multiple logically independent code segments. The logical address of a code segment within the file is an offset relative to the start position of the executable file, used to locate the code segment within the executable file. Each code segment typically includes one or more consecutive program instructions. The position of any program instruction within each code segment of the executable file refers to its logical address or offset within the executable file, used to locate that program instruction during program execution. The offset of a program instruction in the code segment is calculated by the difference between the logical address of the instruction in the code segment and the starting address of the code segment.
[0033] Currently, profile-guided optimization (PGO) can be used to generate executable files. First, the electronic device collects runtime information: during program execution, PGO collects performance data, including function call counts, loop execution counts, and branch prediction accuracy. Then, based on this runtime information, the electronic device generates an optimization information file: the collected runtime information is used to generate an optimization information file. This file contains the program's performance data and information that the compiler can use to guide optimization. Second, the electronic device optimizes the source code based on the optimization information file, generating an intermediate executable file: during program compilation, PGO uses the optimization information file as an additional input file, compiling it along with the source code. The compiler uses the information in the optimization information file to guide the source code optimization process, performing functions such as hot and cold reordering (improving source code layout by grouping frequently executed code together to increase cache hit rate) and inlining (determining whether to inline specific functions based on their call frequency to reduce function call overhead), generating an intermediate executable file containing optimized but not yet linked code. Finally, the electronic device performs link optimization on the intermediate executable files to generate the final executable file: During the linking stage, PGO merges all optimization information files to generate a single final optimization information file. This file contains optimization information for all programs and can be used to guide the optimization of the intermediate executable files, thus producing the final executable file.
[0034] Executable files contain all the instructions and data required for a program to run. They can be directly loaded into memory by the operating system for execution and are the foundation for applications (APPs) to perform various functions and operations. Users can directly download and run these files to use the application.
[0035] With the continuous development of computer technology, processor architectures are diverse. These architectures differ in instruction sets, register configurations, memory management, etc., which means that an executable file compiled on one processor may not be able to run directly on another processor. Alternatively, in the process of APP development, it is often necessary to port existing APPs to new hardware platforms. Due to the limitations of hardware resources and differences in operating systems, the APP's executable files are incompatible with different hardware platforms.
[0036] Currently, binary translation technology can be used to solve the above-mentioned executable file incompatibility problem. Binary translation is a technology that directly translates executable binary programs. It can translate the binary program of an executable file on one processor to be executed on another processor, enabling the program to run on different processor architectures and allowing the APP to run on more hardware platforms, improving hardware and software compatibility and expanding the applicability of the software.
[0037] To reduce application startup time, current binary translation technologies often employ static binary translators to pre-translate most of the original code segments in the executable file. The untranslated original code segments in the executable file (including those that failed to be translated) are then dynamically translated using a dynamic binary translator at runtime. However, during program execution, most of these original code segments still need to be loaded into memory, for example, in 4KB units. Within one 4KB page of the executable file, there might be two original code segments that cannot be pre-translated. But when dynamically translating these two original code segments, the entire 4KB page of the executable file needs to be loaded to read them. This not only consumes memory and flash memory but also increases I / O loading overhead, resulting in performance loss for the terminal device.
[0038] In view of this, embodiments of this application provide an application running method that saves storage space and reduces the overhead of I / O loading during dynamic translation by removing translated original code fragments from the executable file.
[0039] In some embodiments, the method provided in this application can be applied to an electronic device with an application installed. The electronic device loads the first executable file and the first code fragment of the application into the memory of the electronic device, and then the electronic device runs the application based on the first code fragment and / or the first executable file.
[0040] The first executable file includes the original code segment of the application after the first original code segment has been removed; the first original code segment can be translated into the first code segment.
[0041] In the above method, by loading the executable file with the translated original code fragments removed into memory, the number of original code fragments loaded into memory is reduced, which can reduce memory usage, reduce I / O overhead, and improve the performance of electronic devices.
[0042] In some embodiments, such as Figure 1 As shown, the electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc.
[0043] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements.
[0044] Processor 110 may include one or more processing units ( Figure 1(Not shown in the image), for example, processor 110 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0045] The controller can be the nerve center and command center of the electronic device 100. The controller can generate operation control signals according to the instruction opcode and timing signals to complete the control of fetching and executing instructions.
[0046] In some possible implementations, the processor 110 may specifically control the electronic device 100 to load the first executable file and the first code fragment of the application into the memory of the electronic device, and run the application based on the first code fragment and / or the first executable file.
[0047] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store instructions or data that the processor 110 has just used or that are used repeatedly. If the processor 110 needs to use the instruction or data again, it can retrieve it directly from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0048] In some embodiments, processor 110 may include one or more interfaces ( Figure 1 (Not shown in the image). For example, USB interface 130 is an interface conforming to the USB standard specification, specifically a Mini USB interface, Micro USB interface, USB Type-C interface, etc. USB interface 130 can be used to connect a charger to charge electronic device 100, and can also be used for data transfer between electronic device 100 and peripheral devices. It can also be used to connect headphones for audio playback. This interface can also be used to connect other electronic devices, such as AR devices.
[0049] The charging management module 140 is used to receive charging input from the charger. The charger can be a wireless charger or a wired charger.
[0050] The power management module 141 is used to connect the battery 142, the charging management module 140, and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140 to power the processor 110, internal memory 121, external memory, display 194, camera 193, and wireless communication module 160, etc.
[0051] The wireless communication function of electronic device 100 can be realized through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor and baseband processor, etc.
[0052] Electronic device 100 implements display functions through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, connected to the display screen 194 and the application processor. The GPU performs mathematical and geometric calculations for graphics rendering. Processor 110 may include one or more GPUs, which execute program instructions to generate or modify display information. Display screen 194 is used to display images, videos, etc. Display screen 194 includes a display panel.
[0053] In some possible implementations, the electronic device 100 may display information about the first executable file, such as the file name, size, and storage location of the first executable file, on the display screen 194.
[0054] Electronic device 100 can perform shooting functions through ISP, camera 193, video codec, GPU, display 194 and application processor.
[0055] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to perform data storage functions.
[0056] In some possible implementations, the electronic device 100 may store the first executable file and the first code fragment via an external memory card.
[0057] Internal memory 121 can be used to store computer executable program code, which includes instructions. Processor 110 executes various functional applications and data processing of electronic device 100 by running the instructions stored in internal memory 121. Internal memory 121 may include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as sound playback, image playback, etc.), etc. The data storage area may store data created during the use of electronic device 100 (such as audio data, phonebook, etc.). Furthermore, internal memory 121 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, universal flash storage (UFS), etc.
[0058] In some possible implementations, the electronic device 100 may also store the first executable file and the first code segment in its internal memory 121.
[0059] Electronic device 100 can implement audio functions through audio module 170 and application processor, such as music playback and recording. Audio module 170 is used to convert digital audio information into analog audio signals for output, and also to convert analog audio input into digital audio signals. Audio module 170 can also be used for encoding and decoding audio signals.
[0060] Buttons 190 include a power button, volume buttons, etc. Buttons 190 can be mechanical buttons or touch-sensitive buttons. Motor 191 can generate vibration alerts. Motor 191 can be used for incoming call vibration alerts or for touch vibration feedback. Indicator 192 can be an indicator light, used to indicate charging status, battery level changes, or to indicate messages, missed calls, notifications, etc. SIM card interface 195 is used to connect a SIM card.
[0061] based on Figure 1 The electronic device shown implements the application running method in the embodiments of this application, which can reduce memory usage and improve IO performance.
[0062] The electronic device provided in this application embodiment can run an operating system (OS). This operating system can be various operating systems used in the industry, such as an operating system based on OpenHarmony, like HarmonyOS; or other operating systems such as Android. TMAn operating system can refer to the iOS mobile operating system; it can also refer to various open-source operating systems or their derivatives, such as Linux OS and other embedded operating systems; or it can refer to future new operating systems, such as AI operating systems based on artificial intelligence. An operating system is a set of interconnected system software programs that manage and control the operation of electronic devices, utilize and run hardware and software resources, and provide public services to organize user interactions. In electronic devices, the operating system connects downwards to the physical devices at the hardware layer and upwards to provide a runtime environment for application software.
[0063] An operating system typically includes a kernel layer, a middleware layer, and an application layer. The application layer includes applications, which can include system applications and third-party applications. The middleware layer includes a suite of software providing various services to application developers, or frameworks providing services such as databases, multimedia, and graphics, or capabilities such as distributed scheduling and system scaling. For example, the middleware layer may include a framework layer and / or a system service layer. The framework layer provides application programming interfaces (APIs) and programming frameworks for applications in the application layer. The system service layer includes the system's core capabilities, providing services to applications through the framework layer. The kernel layer is the layer between hardware and software. The kernel layer may include hardware drivers and the operating system kernel. In addition to providing hardware drivers, the kernel layer also supports functions such as memory management and system process management.
[0064] The electronic devices we use in our daily lives come in various types and forms, and are applied in a wide range of scenarios. Therefore, based on the different forms and functions of electronic devices, different application scenarios, and different user needs, the operating systems used in these devices may also differ. The basic functions implemented by the electronic device provided in this application can be implemented using a general-purpose operating system or a dedicated operating system. To more clearly illustrate the implementation of the embodiments of this application under a specific operating system, the architecture of HarmonyOS is shown below. Those skilled in the art can deduce the implementation of the embodiments of this application under other specific operating systems, such as Android. TM Implementation under operating systems, etc.
[0065] In some embodiments, such as Figure 2 As shown, the software architecture of electronic device 100 can be divided into several layers, from bottom to top: kernel layer, system service layer, framework layer, and application layer. Layers communicate with each other through software interfaces. System functions can be tailored, added, or combined at the subsystem granularity in different device deployment scenarios, and each subsystem can also be tailored, added, or combined at the functional granularity.
[0066] The kernel layer includes the kernel abstract layer (KAL), the kernel subsystem, and the driver subsystem.
[0067] KAL: By shielding the differences between multiple kernels, it provides basic kernel capabilities to the upper layers, including but not limited to process / thread management, memory management, file system, network management, and peripheral device management.
[0068] Kernel Subsystem: Supports the selection of a suitable OS kernel for different resource-constrained devices, including but not limited to Linux kernel, HarmonyOS kernel, LiteOS (lite operating system), etc.
[0069] Driver Subsystem: The driver framework is the foundation for the open system hardware ecosystem, providing unified peripheral access capabilities and a framework for driver development and management. The driver framework includes: display drivers, camera drivers, audio drivers, Bluetooth drivers, sensor drivers, etc.
[0070] The system service layer includes a set of subsystems, distributed task scheduling, distributed data management, distributed soft bus, and Ark multi-language runtime.
[0071] The system service layer comprises the core capabilities of the system, providing services to applications through the framework layer. This layer includes, but is not limited to, the following subsystems:
[0072] The system's basic capability subsystem set provides fundamental capabilities for the operation, scheduling, and migration of distributed applications across multiple devices. This set may include distributed soft bus, distributed data management, distributed task scheduling, and Ark multi-language runtime; it may also include multi-modal input subsystem, graphics subsystem, security subsystem, and AI business subsystem.
[0073] Basic software service subsystem set: provides public and general software services; the basic software service subsystem set may include event notification subsystem, telephone service subsystem, multimedia subsystem, etc.
[0074] Enhanced software service subsystem suite: Provides differentiated enhanced software services for different devices; the enhanced software service subsystem suite may include smart screen proprietary business subsystem, wearable proprietary business subsystem, IoT proprietary business subsystem, etc.
[0075] Hardware service subsystem set: Provides hardware services; the hardware service subsystem set may include location service subsystem, unified identity and access management (IAM) subsystem, wearable proprietary hardware service subsystem, etc.
[0076] Distributed task scheduling enables distributed service management (discovery, synchronization, registration, and invocation), supporting remote startup, remote invocation, remote connection, and migration of applications across devices.
[0077] Distributed data management enables data synchronization, data storage, data sharing, and data access across all scenarios and devices.
[0078] The distributed soft bus provides communication-related capabilities for seamless interconnection between multiple devices, including: WLAN service capabilities, Bluetooth service capabilities, soft bus, inter-process communication (remote procedure call, RPC), and StarFlash communication capabilities.
[0079] Ark Multilingual Runtime is a unified compilation runtime platform designed to support the joint compilation and execution of multiple programming languages and multiple chip platforms.
[0080] The framework layer provides application programming interfaces (APIs) and programming frameworks for applications in the application layer. The framework layer includes: the ArkUI framework (which provides a complete infrastructure for UI development of system applications, including UI functions such as components, layouts, animations, and interactive events, as well as a real-time interface preview tool), the user application framework, and the Ability framework (an Ability is a lightweight application; the Ability framework schedules and manages the operation and lifecycle of Abilities). Different devices may have different operating systems, and the APIs they support may also differ.
[0081] The HarmonyOS API is a series of open capabilities provided to support HarmonyOS application development. The HarmonyOS API can be set at the framework layer or independently of the framework layer. The HarmonyOS API includes the Audio API (audio service), Push API (push service), and Account API (account service), among others.
[0082] The application layer can include system applications and extended / third-party applications. System applications can include the desktop, control bar, settings, contacts, phone, camera, etc., while extended / third-party applications can include social applications, travel applications, etc.
[0083] In some embodiments, when the application is an extended application / third-party application, if the application's executable file is compiled with a processor architecture different from that of the electronic device, the electronic device can translate the application's executable file to obtain a translated file, and delete the translated original code fragments in the application's executable file, so that the executable file after deleting the translated original code fragments can be loaded into memory for dynamic translation, thereby enabling the application to run correctly on the electronic device.
[0084] based on Figure 2 The electronic device shown implements the application running method in the embodiments of this application, which can reduce the number of original code segments loaded into memory, thereby reducing memory usage and improving IO performance.
[0085] The aforementioned electronic devices can be mobile phones, tablets, wearable devices (such as smartwatches, smart bracelets, etc.), smart home devices (such as smart TVs, smart screen devices, smart central control devices, etc.), in-vehicle systems (such as in-vehicle computers), handheld computers, laptops, personal computers (PCs), ultra-mobile personal computers (UMPCs), netbooks, personal digital assistants (PDAs), augmented reality (AR) / virtual reality (VR) devices, and other terminal devices.
[0086] The following uses a mobile phone as an example to illustrate the method for translating executable files provided in the embodiments of this application.
[0087] See Figure 3 As shown, the above application operation method may include the following steps S301-S302.
[0088] S301, The mobile phone loads the first executable file and the first code fragment of the application into memory.
[0089] The first executable file includes the original code segment of the application after the first original code segment has been removed, and the first original code segment can be translated into the first code segment.
[0090] For example, the first executable file of the application is the file after the first original code segment of the application's executable file has been deleted. The application's executable file is compiled by another electronic device with a different processor architecture than the mobile phone. In order to ensure that the application can run correctly on the mobile phone, the mobile phone needs to translate the application's executable file to obtain a translated file. The translated file includes the first code segment, which is the translation result obtained after translating the first original code segment in the executable file. The mobile phone deletes the translated first original code segment in the executable file to obtain the first executable file.
[0091] For example, the mobile phone can load the first executable file and the first code fragment of the application into memory before or during the application's operation, according to the application's requirements. The first code fragment is also stored in the mobile phone's non-volatile storage space in the form of a file. The mobile phone can map the various program instructions included in the original code fragment in the first executable file and the various program instructions included in the first code fragment to the corresponding locations in memory according to the file format, and can obtain the memory address of each program instruction.
[0092] S302. The mobile phone runs the application based on the first code snippet and / or the first executable file.
[0093] During application execution, the phone's program counter (PC) points to the memory address of the next program instruction to be executed, controlling the phone to retrieve program instructions from the corresponding memory address one by one and execute the program instructions to run the application.
[0094] For example, when the PC points to the memory address of a program instruction, the mobile phone will read the corresponding program instruction from that memory address. After the mobile phone reads the program instruction, the PC will automatically increment a value, which is usually the number of bytes of the program instruction, so that the PC can point to the memory address of the next program instruction to be executed.
[0095] For example, if the program instruction is a jump instruction, the pointer address of the program instruction to which it jumps can be parsed. The phone updates the PC value according to the pointer address in the jump instruction to point to the memory address of the jump instruction corresponding to the pointer address. Then, the phone retrieves the jump instruction from that memory address and continues executing the program.
[0096] In some embodiments, the mobile phone reads program instructions to be executed from memory. If the program instructions to be executed are program instructions included in a first code segment, the program instructions to be executed are executed. If the program instructions to be executed are program instructions included in an original code segment, the program instructions to be executed are translated to obtain translated program instructions, and the translated program instructions are run to run the application.
[0097] It is understood that the above-mentioned "translation" can be binary translation, or it can be translating the original code into other translation methods adapted to mobile phones. This application embodiment does not impose specific limitations on this.
[0098] For example, whether a program instruction to be executed needs to be translated can be determined by the translator on the phone. For instance, after the phone retrieves the program instruction from the memory address based on the PC's value, before the phone executes the instruction, the phone's binary dynamic translator determines whether the instruction is compatible with the phone's instruction set. If the instruction is incompatible, it means the instruction is part of the original code segment. In this case, the instruction or the original code segment containing the instruction is translated, and the translated instruction or code segment is stored in a translation cache (used to store the translation results of program instructions in memory). This allows the phone to read and execute the translated instruction from the translation cache when needed. If the instruction is compatible with the phone's instruction set, it means the instruction is part of the first code segment, and the phone can directly execute the instruction. This not only improves application efficiency but also enhances accuracy.
[0099] For example, if the binary dynamic translator determines that the program instruction is incompatible with the phone's instruction set, it can first retrieve the translated program instruction from the translation cache. If the translated program instruction does not exist in the translation cache, the binary dynamic translator translates the program instruction or the original code segment containing the program instruction, and stores the translated program instruction or code segment in the translation cache. If the translated program instruction exists in the translation cache, the phone retrieves the translated program instruction from the translation cache and executes it. The translation cache is used to store the program instructions before translation by the binary dynamic translator and the translated program instructions corresponding to each pre-translation program instruction to improve translation speed.
[0100] The steps shown in S301-S302 above implement the application running method in the embodiments of this application. By removing the translated code segments in the executable file, the number of times the executable file is loaded page by page is reduced, the I / O loading overhead is reduced, the memory occupation is reduced, and the speed at which the executable file is loaded into memory is increased, thereby improving the performance of the mobile phone.
[0101] In some embodiments, before performing step S301, the mobile phone needs to obtain the executable file of the application. During this process, the mobile phone can obtain the installation package of the application and decompress the installation package to obtain the executable file of the application.
[0102] For example, the installation package can be a file package or a compressed package. The installation package can be downloaded to the mobile phone via the network or transferred to the mobile phone via a USB flash drive, data cable or other transfer tools.
[0103] For example, if the installation package is a file package, the phone can directly obtain the executable file in the file package. If the installation package is a compressed package, the phone can call a decompression tool to decompress the installation package and obtain the application's executable file. The choice of decompression tool depends on the compression format of the installation package. Common compression formats include ZIP, RAR, TAR, etc., and each format has a corresponding decompression tool.
[0104] In some embodiments, the mobile phone can obtain fourth information indicating that the installation package has been decompressed. Based on the fourth information, the mobile phone can write the executable file after the installation package has been decompressed into the non-volatile storage space of the mobile phone.
[0105] For example, based on the fourth information, the mobile phone stores the decompressed file package in the phone's disk or hard drive, or other non-volatile storage. It can be stored in the phone's default storage location or in a storage location selected by the user, so as to save it permanently.
[0106] After a mobile phone obtains the executable file of an application, it needs to determine whether to translate the executable file in the installation package. This can be determined before the executable file is loaded into memory. For example, the mobile phone can determine whether translation is needed immediately after obtaining the executable file, or it can determine whether translation is needed during the preparation stage before installing the application (such as configuring environment variables, checking dependencies, etc.), or it can determine whether translation is needed immediately after obtaining the installation package.
[0107] In some embodiments, the mobile phone can determine whether binary translation of the executable file in the installation package is required based on any of the following factors: processor architecture, binary format compatibility, or automated detection tools. Alternatively, the user can manually intervene to determine the binary translation, in order to ensure the correct execution of the application.
[0108] For example, in response to a mismatch between the format of the executable file and the format of the phone's operating system, the phone calls its binary static translator to translate the executable file; or, in response to an operation on a selection control on the user interface, the phone calls its binary static translator to translate the executable file; or, in response to a mismatch between the processor architecture on which the executable file runs and the phone's processor architecture, the phone calls its binary static translator to translate the executable file.
[0109] For example, after receiving an application's installation package, the phone checks whether the application's executable file format is compatible with the binary format of the phone's operating system. Different operating systems and hardware platforms may support different binary formats. If the binary formats are incompatible, the phone can call a binary static translator to perform binary translation of the executable file.
[0110] For example, after receiving an application's installation package, the phone checks whether the phone's processor architecture matches the processor architecture targeted by the executable file in the installation package. If the two processor architectures are different, the phone can call a binary static translator to perform binary translation of the executable file, so as to convert the executable file into a form that the phone can execute.
[0111] For example, the phone is equipped with an automated detection tool to automatically scan the executable files in the installation package and perform the processor architecture and / or binary format compatibility tests mentioned above. If a binary translation is detected, the phone can prompt the user to perform the corresponding operation or automatically execute the translation process.
[0112] For example, users can manually intervene and configure their phones to determine whether the phone performs binary translation of executable files. For instance, in some cross-platform applications, users can select their phone's platform and configure the corresponding translation options among the provided platform and translation options, or they can click the "Translate" control on the phone's interface during installation to perform binary translation of executable files.
[0113] As can be seen, mobile phones can determine whether to translate executable files in multiple ways to ensure that the mobile phone can correctly execute executable files in the future.
[0114] In some embodiments, the mobile phone obtains a first code segment based on a first original code segment in the executable file, and writes the first code segment into the mobile phone's non-volatile storage space.
[0115] For example, the mobile phone performs binary translation on the executable file to obtain the first code segment after translation of the first original code segment in the executable file. The first code segment can be written to a newly created file in the non-volatile storage space such as the mobile phone's disk or hard drive, or it can be written to the executable file to permanently store the first code segment and improve the running speed of subsequent applications.
[0116] For example, when it is determined that an executable file is to be pre-translated, the binary static translator on the mobile phone will determine the first source code segment to be pre-translated from at least one source code segment included in the executable file according to preset conditions. The preset conditions can be determined based on performance requirements. For source code segments with high performance requirements, the binary static translator is used for pre-translation to improve execution efficiency. For source code segments with less stringent performance requirements, or source code segments that need to be frequently modified, the binary dynamic translator is used to ensure translation accuracy. For example, the preset conditions could be that source code segments with a stability index greater than a first preset threshold are pre-translated (the code segments are stable and have a low probability of changing during runtime), and source code segments with a response time less than a second preset threshold are pre-translated.
[0117] For example, after the binary static translator determines the first source code segment to be pre-translated, the binary static translator on the mobile phone analyzes the program instructions in the first source code segment of the executable file. Based on the instruction set supported by the mobile phone's processor, it translates the first source code segment containing the program instructions into a first code segment executable by the mobile phone. The translated first code segment is then stored in a new file, or in the executable file. Alternatively, the mobile phone can also translate the program instructions into executable program instructions based on the instruction set supported by the mobile phone's processor, organize the executable program instructions into a new first code segment, and store it in a new file, or in the executable file.
[0118] In some embodiments, the mobile phone obtains first information, obtains a first executable file based on the first information, and writes the first executable file into the non-volatile storage space of the mobile phone.
[0119] The first information includes first label information and / or second label information; the first label information is used to indicate the first original code segment in the executable file, and the second label information is used to indicate the original code segments in the executable file other than the first original code segment.
[0120] The first executable file is the executable file after the first original code segment has been removed.
[0121] For example, when a mobile phone performs binary translation on an executable file, it not only translates the first original code segment in the executable file into a first code segment, but also marks the translated first original code segment to obtain first tag information. It can also mark the untranslated / unsuccessfully translated original code segments to obtain second tag information. This allows the mobile phone to process the executable file (including deletion, updates, etc.) based on the first tag information and / or the second tag information, thus obtaining the first executable file.
[0122] For example, the initial information can be stored in an executable file or in a newly created file on the phone.
[0123] For example, a mobile phone can obtain the first information in any of the following ways: record the position of the translated first original code segment in the executable file code segment, mark the first original code segment by hash value, mark the first original code segment by character information, mark the first original code segment by comments, etc.
[0124] For example, such as Figure 4 As shown, the original code segments stored in the code segment of the executable file include a first original code segment that can be pre-translated (non-shaded area, i.e., the original code segment with the first label information "0") and an original code segment that needs to be dynamically translated (shaded area, i.e., the original code segment with the second label information "1"). The mobile phone can determine the first original code segment in the executable file based on the first label information and delete the determined first original code segment to obtain the first executable file.
[0125] For example, when deleting the first original code segment, the mobile phone can do so in the following ways: 1. The mobile phone can delete the identified first original code segments one by one; 2. The mobile phone can aggregate the first original code segments and delete the aggregated first original code segments as a whole; 3. The mobile phone can use the second tag information to identify the original code segments in the executable file other than the first original code segment, aggregate the original code segments in the executable file other than the first original code segment, and then delete the aggregated first original code segment as a whole.
[0126] For example, the mobile phone stores the first original code fragments consecutively in the second storage area of the executable file code segment to aggregate the first original code fragments in the executable file. The mobile phone can delete at least one first original code fragment in the executable file by directly deleting the code fragments in the second storage area. After deleting the first original code fragments, the mobile phone can store the remaining original code fragments in the executable file consecutively starting from the beginning of the code segment to obtain the first executable file.
[0127] For example, such as Figure 5 As shown, the mobile phone stores the original code segments (excluding the first original code segment) consecutively in a first storage region within the executable file's code segment (the starting position of the first storage region is the starting position of the code segment in the executable file) to aggregate the original code segments in the executable file. The mobile phone then deletes the original code segments in the region following the first storage region in the executable file's code segment to delete at least one of the first original code segments from the executable file, resulting in the following... Figure 6 The first executable file shown.
[0128] For example, the phone can rewrite the obtained first executable file into the phone's non-volatile storage space so that the phone can subsequently retrieve the first executable file from the non-volatile storage space and load it into memory.
[0129] In some embodiments, the original code fragment in the first executable file includes multiple program instructions, which are stored consecutively in the first executable file. If a first program instruction exists among the multiple program instructions, and the storage location of the first program instruction in the first executable file is different from the storage location of the first program instruction in the executable file, the pointer address of the first program instruction also needs to be updated. The pointer address is used to indicate the storage location of the first program instruction.
[0130] For example, if the original code segment of the first executable file or the first code segment includes a program instruction (such as a jump instruction, a call instruction, etc.) with a pointer address of a first program instruction, and the storage location of the first program instruction changes, it is necessary to update the pointer address of the first program instruction included in the original code segment or the first code segment to ensure that the mobile phone subsequently obtains the accurate first program instruction from memory.
[0131] This application provides a method for detecting the content loaded in an electronic device. It can detect the content output from the non-volatile memory in the electronic device, or the content loaded into memory, or the read and write operations of files, to prove that the first executable file and the first code fragment of the application have been loaded into memory.
[0132] This application provides a file detection method. After downloading the installation package of an application or obtaining the installation package from another device via a transmission line, the size of the executable file in the application's installation package is detected. If the executable file has become smaller, the contents of the executable file before and after the change can be compared to prove that the translated first original code segment has been deleted from the executable file.
[0133] It is understood that, in order to achieve the above functions, the aforementioned electronic device includes hardware and / or software modules corresponding to perform each function. Based on the algorithmic steps of the various examples described in conjunction with the embodiments disclosed herein, this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed in hardware or by computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application in conjunction with the embodiments, but such implementation should not be considered beyond the scope of this application.
[0134] This application embodiment can divide the electronic device into functional modules according to the above method example. For example, each function can be divided into its own functional module, or two or more functions can be integrated into one processing module. The integrated module can be implemented in hardware. It should be noted that the module division in this embodiment is illustrative and only represents one logical functional division. In actual implementation, there may be other division methods.
[0135] This application also provides an electronic device, such as... Figure 7 As shown, the electronic device may include one or more processors 701, memory 702, and communication interface 703.
[0136] The memory 702, communication interface 703, and processor 701 are coupled together. For example, the memory 702, communication interface 703, and processor 701 can be coupled together via bus 704.
[0137] The communication interface 703 is used for data transmission with other devices. The memory 702 stores computer program code. The computer program code includes computer instructions, which, when executed by the processor 701, cause the electronic device to perform the application execution method described in this embodiment.
[0138] The processor 701 can be a processor or controller, such as a central processing unit (CPU), a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with this disclosure. The processor can also be a combination that implements computational functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.
[0139] The bus 704 can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The bus 704 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 7 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0140] This application also provides a computer-readable storage medium storing computer program code. When the processor executes the computer program code, the electronic device executes the relevant method steps in the above method embodiments.
[0141] The electronic devices and computer storage media provided in this application are used to execute the corresponding methods provided above. Therefore, the beneficial effects they can achieve can be referred to the beneficial effects of the corresponding methods provided above, and will not be repeated here.
[0142] Through the above description of the embodiments, those skilled in the art can clearly understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0143] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0144] The units described as separate components may or may not be physically separate. A component shown as a unit can be one or more physical units; that is, it can be located in one place or distributed in multiple different locations. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0145] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0146] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiments of this application, in essence, or the part that contributes, or all or part of the technical solution, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to cause a device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0147] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. An application running method, characterized in that, The method is applied to an electronic device on which an application is installed; the method includes: Load the first executable file and the first code fragment of the application into the memory of the electronic device; the first executable file includes the original code fragment of the application after the first original code fragment has been removed; the first original code fragment can be translated into the first code fragment; The application is run based on the first code snippet and / or the first executable file.
2. The method according to claim 1, characterized in that, Before loading the first executable file and the first code fragment of the application into the memory of the electronic device, the method further includes: Obtain the executable file of the application; The first code segment is obtained based on the first original code segment in the executable file; The first code snippet is written to the non-volatile memory space of the electronic device.
3. The method according to claim 2, characterized in that, The method further includes: Obtain first information; wherein the first information includes first tag information and / or second tag information; the first tag information is used to indicate a first original code segment in the executable file, and the second tag information is used to indicate original code segments in the executable file other than the first original code segment; Based on the first information, a first executable file is obtained; wherein, the first executable file is the executable file after the first original code segment has been removed; The first executable file is written to the non-volatile storage space of the electronic device.
4. The method according to claim 2 or 3, characterized in that, Obtaining the first code fragment includes: In response to a mismatch between the format of the executable file and the format of the operating system of the electronic device, the first source code segment in the executable file is translated to obtain a first code segment; or, In response to an operation on a selection control on the user interface, the first source code segment in the executable file is translated to obtain a first code segment; or... In response to a mismatch between the processor architecture of the executable file and the processor architecture of the electronic device, the first source code segment in the executable file is translated to obtain a first code segment.
5. The method according to any one of claims 1-4, characterized in that, The original code fragment in the first executable file includes multiple program instructions, which are stored consecutively in the first executable file.
6. The method according to claim 5, characterized in that, If a first program instruction exists among the plurality of program instructions, and the storage location of the first program instruction in the first executable file is different from the storage location of the first program instruction in the executable file, then the method further includes: Update the pointer address of the first program instruction, the pointer address being used to indicate the storage location of the first program instruction.
7. The method according to any one of claims 1-6, characterized in that, Running the application includes: Read the program instructions to be executed from the memory; If the program instructions to be executed are program instructions included in the first code segment, the program instructions to be executed are executed to run the application.
8. The method according to claim 7, characterized in that, The method further includes: If the program instructions to be executed are program instructions included in the original code segment, the program instructions to be executed are translated to obtain translated program instructions; Run the translated program instructions to run the application.
9. An electronic device, characterized in that, The device includes a memory and one or more processors; the memory is coupled to the processors; wherein the memory stores computer program code, the computer program code including computer instructions, which, when executed by the processor, cause the electronic device to perform the application running method as described in any one of claims 1-8.
10. A computer-readable storage medium, characterized in that, Includes computer instructions that, when executed on an electronic device, cause the electronic device to perform the application execution method as described in any one of claims 1-8.
11. A computer program product, characterized in that, When the computer program product is run on a computer, the computer performs the application running method as described in any one of claims 1-8.