Application program running method, device, terminal device and medium
By identifying and initializing static classes in applications in advance and generating class list files, it solves the problems of low operating efficiency and high disk overhead during virtual machine conversion, and achieves more efficient application operation.
Patent Information
- Application Number
- CN201911156475.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-11-22
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2039-11-22
AI Technical Summary
In the existing technology, the process of converting bytecode into machine code by a virtual machine leads to a reduction in application running efficiency, and optimization during the compilation phase requires the use of a designated virtual machine, which increases developer workload and disk overhead.
By identifying static classes in the application that can be initialized in advance, a class list file is generated, and these classes are initialized in advance to reduce the amount of data and disk usage in virtual machine conversion and improve operating performance.
There is no need to recompile the application program to generate instructions for direct execution by the operating system, reducing disk space usage and improving the running performance of the application program.
Smart Images

Figure CN112947927B_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of information technology, and in particular, relates to an application running method, device, terminal device and medium. Background Art
[0002] In order to improve programming efficiency, object-oriented cross-platform programming languages such as Java and Python are very popular. Compared with traditional programming languages that need to be compiled on the corresponding operating system platform before they can be executed, cross-platform programming languages can be executed on different operating system platforms after one compilation. In order to achieve this feature, the application does not run directly on the operating system, but on a specified virtual machine, such as the Java virtual machine, Python virtual machine, etc. Figure 1 As shown in FIG. 1 , it is a virtual machine architecture diagram in the prior art. Figure 1 In the architecture shown in the figure, the application runs in a specified virtual machine, which shields all kinds of information related to the specific operating system platform. The running process of the application in the virtual machine is as follows: Figure 2 As shown in FIG. 1 , the source code is first compiled into bytecodes that can be understood by the virtual machine, and then converted by the virtual machine into machine codes that can be understood by different hardware platforms, and then executed. However, the process of converting bytecodes into machine codes by the virtual machine will result in a relatively low operating efficiency. In view of this situation, how to generate instructions that can be directly executed by the operating system more quickly becomes the key to improving system performance. In the prior art, the operating efficiency of the application can be improved by two methods: optimization at the compilation stage and optimization at the execution stage.
[0003] Compile-time optimization identifies parts of the code and processes them during the compile-time phase, thereby reducing the amount of data waiting for the virtual machine to convert and improving operational efficiency. Figure 3 As shown in FIG. , it is a schematic diagram of the process of compiling phase optimization in the prior art. Figure 3 The original pseudocode shown, if it is recognized during compilation that the code corresponding to Source2 can be executed in advance, then this part of the code will no longer be compiled into bytecode, but can be directly extracted and compiled into directly executable machine code. When the application is running, when the code logic corresponding to Source2 is executed, the extracted compilation result can be directly executed. Execution stage optimization does not require special processing of the code during the compilation stage, but all of it is compiled into bytecode. After the application is installed on the corresponding operating system platform, the program will be recompiled into instructions that the system can directly execute at a specified time. Figure 4 As shown in FIG. , it is a schematic diagram of the process of execution phase optimization in the prior art. Figure 4The original pseudocode shown is compiled into bytecode in the compilation stage. Then, when the application is running, when the code logic corresponding to ByteCode2 is executed, the compiled machine code is directly executed, omitting the overhead of converting ByteCode2 from the virtual machine to RunCode2, thereby improving performance.
[0004] Compilation phase optimization requires developers to compile using a specified virtual machine environment and run on a specified virtual machine to obtain the corresponding performance benefits. However, there are many different virtual machines on the market. If developers are required to recompile using a specified virtual machine, it will increase the workload and the cost of compilation. On the other hand, the application itself usually has the behavior of modifying the original application files such as patching and hot updating, and will also access files within the application. Using the execution phase optimization method to compile the bytecode into machine code still cannot delete the original application file, which is equivalent to adding a new file, which will bring additional disk overhead. Summary of the invention
[0005] The embodiments of the present application provide an application running method, apparatus, terminal device and medium, which can improve the running performance of the application.
[0006] In a first aspect, an embodiment of the present application provides an application running method, applicable to a terminal device, the method comprising:
[0007] When detecting that an application is started, obtaining a class list file corresponding to the application;
[0008] Identify a target class in the class list file;
[0009] A target thread is started, and the target class is initialized using the target thread.
[0010] Exemplarily, the terminal device may be an Android-based device, and the source code of the application may be obtained to identify the static class in the source code; then based on the static class, a class list file corresponding to the application may be generated. The class list file may include the class names of various classes that can be initialized in advance.
[0011] It should be understood that the classes that can be initialized in advance can be identified by parsing the classes in the source code, finding out the classes that contain variables and code segments marked with preset characters in the source code, and whose initialization codes corresponding to the classes do not include other task execution logic.
[0012] On the other hand, in order to ensure the accuracy of identifying classes that can be initialized in advance, based on the above steps, it is also possible to determine whether the class has a calling relationship with other classes. If there is no calling relationship, the class can be confirmed as a static class that can be initialized in advance; if there is a calling relationship, the class can only be identified as a static class that can be initialized in advance if it is determined that the class and all classes on the calling path are static classes. Through two identifications, the accuracy of the identified static classes can be guaranteed.
[0013] Exemplarily, when generating the class list file, the initialization phase of each static class may be determined, a mapping relationship between the class name of each static class and the corresponding initialization phase may be established, and the mapping relationship may be written into the class list file.
[0014] Since initializing static classes in advance requires corresponding memory support, whether the system can initialize all static classes in advance has a great relationship with the memory size of the system. If the system memory is not particularly sufficient, you can establish a mapping relationship between each static class and its initialization stage in the class list file, so that when the application is running, each static class can be initialized in stages to reduce the occupation of system memory and disk.
[0015] Exemplarily, the generated class list file can be uploaded to the server. When other terminal devices download the application from the server, the server can send the corresponding class list file to other terminal devices. When other terminal devices start the application, they can directly extract the received class list file and perform initialization operations on the target class in the file in advance.
[0016] In a second aspect, an embodiment of the present application provides a method for generating a class list file, including:
[0017] Get the source code of the application;
[0018] identifying static classes in the source code;
[0019] Based on the static class, a class list file corresponding to the application is generated.
[0020] In a third aspect, an embodiment of the present application provides an application running device, applicable to a terminal device, the device comprising:
[0021] An acquisition module, used for acquiring a class list file corresponding to the application when detecting that the application is started;
[0022] An identification module, used for identifying a target class in the class list file;
[0023] The initialization module is used to start the target thread and use the target thread to initialize the target class.
[0024] In a fourth aspect, an embodiment of the present application provides a device for generating a class list file, including:
[0025] The acquisition module is used to obtain the source code of the application;
[0026] An identification module, used for identifying static classes in the source code;
[0027] A generation module is used to generate a class list file corresponding to the application based on the static class.
[0028] In a fifth aspect, an embodiment of the present application provides a terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the application program running method described in any one of the first aspects above is implemented.
[0029] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the application running method described in any one of the above-mentioned first aspects is implemented.
[0030] In a seventh aspect, an embodiment of the present application provides a computer program product, which, when executed on a terminal device, enables the terminal device to execute the application program running method described in any one of the above-mentioned first aspects.
[0031] Compared with the prior art, the embodiments of the present application include the following beneficial effects:
[0032] In the embodiment of the present application, when the application is detected to be started, the class list file corresponding to the application is obtained and the target class in the class list file is identified, and then the target thread can be started, and the target classes are initialized using the target thread. By identifying the classes that can be initialized in advance in the program, this embodiment can generate instructions that can be directly executed by the operating system more quickly without recompiling the application in a specified compiler, and does not need to compile the application code into a machine code file, thereby reducing the repeated occupation of disk space. All classes that meet the conditions for early initialization will obtain corresponding performance optimization benefits when initialized, which helps to improve the running performance of the application. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments or prior art descriptions. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0034] Figure 1 It is a schematic diagram of a virtual machine architecture in the prior art;
[0035] Figure 2 It is a schematic diagram of the running process of an application program in a virtual machine in the prior art;
[0036] Figure 3 It is a schematic diagram of a process of compile phase optimization in the prior art;
[0037] Figure 4 It is a schematic diagram of a process of execution phase optimization in the prior art;
[0038] Figure 5 It is a schematic diagram of a process of executing a class through a thread in the prior art;
[0039] Figure 6 It is a schematic diagram of the hardware structure of a mobile phone to which the application program running method provided in an embodiment of the present application is applicable;
[0040] Figure 7 It is a schematic diagram of the software structure of a mobile phone to which the application program running method provided in one embodiment of the present application is applicable;
[0041] Figure 8 is a schematic flowchart of a method for running an application program provided in an embodiment of the present application;
[0042] Fig. 9 is a schematic flowchart of a method for running an application program provided in another embodiment of the present application;
[0043] FIG. 10( a ) is a schematic diagram of the first scanning and parsing process when identifying a static class according to an embodiment of the present application;
[0044] FIG10( b ) is a schematic diagram of a second scanning and parsing process for identifying a static class provided by an embodiment of the present application;
[0045] Fig.11 is a schematic flowchart of a method for running an application program provided in another embodiment of the present application;
[0046] Fig.12 This is a schematic diagram of a class initialization process provided by an embodiment of the present application;
[0047] Fig.13 is a schematic flowchart of the steps of a method for generating a class list file provided in an embodiment of the present application;
[0048] Fig.14 is a schematic diagram of a system architecture to which the application program running method provided in an embodiment of the present application is applied;
[0049] Fig.15 is a structural block diagram of an application program running device provided in an embodiment of the present application;
[0050] Fig.16 It is a structural block diagram of a device for generating a class list file provided in an embodiment of the present application;
[0051] Fig.17 It is a structural diagram of a terminal device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0052] In the following description, specific details such as specific system structures, technologies, etc. are proposed for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application can also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from hindering the description of the present application.
[0053] The terms used in the following embodiments are only for the purpose of describing specific embodiments and are not intended to be limiting of the present application. As used in the specification and appended claims of the present application, the singular expressions "one", "a kind", "said", "above", "the" and "this" are intended to also include expressions such as "one or more", unless there is a clear contrary indication in the context. It should also be understood that in the embodiments of the present application, "one or more" refers to one, two or more; "and / or" describes the association relationship of associated objects, indicating that three relationships may exist; for example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship.
[0054] The application program running method provided in the embodiment of the present application can perform initialization optimization for all object-oriented, cross-platform language program classes to improve the execution performance of the application program. For ease of understanding, the characteristics of such languages related to the present embodiment are first introduced.
[0055] In object-oriented programming languages, there are "classes" in the code one by one, and everything in the system is an "object". An "object" is an instance of a "class". When the program is executed, the required "class" will be initialized as an "instance" and then executed.
[0056] In order to ensure the correctness of the execution of object-oriented programming languages, there are strict regulations on the initialization of "classes". Taking JAVA as an example, a class will only be initialized once and follow the principle of "initialization at first active use", that is, it will be initialized only when the class is used. If this principle is not followed, if class A references class B during initialization, but class B has not been executed yet, class A will produce an incorrect initialization result.
[0057] like Figure 5 The figure below is a schematic diagram of the process of executing a class through a thread. The code for class initialization must also be converted by the "virtual machine" before execution, and at the same time, it must follow the above principles. This part of the logic will be executed completely in a serial manner, resulting in serious performance consumption.
[0058] Usually, applications will define a "static" domain to define constants, execute static methods, etc. The code belonging to the "static" domain will be modified by a special word, usually static. The initialization of the "static" domain is special and does not depend on a specific "instance", so there is no need to wait for the initialization of a certain class, and it can be initialized independently without the above specifications.
[0059] Therefore, the application running method provided in the embodiment of the present application can improve the execution performance of the application by identifying classes that can be initialized individually and do not affect the correctness of the program, and then initializing these classes in advance in parallel at the appropriate time.
[0060] The application running method provided in the embodiments of the present application can be applied to terminal devices such as mobile phones, tablet computers, wearable devices, vehicle-mounted devices, augmented reality (AR) / virtual reality (VR) devices, laptop computers, ultra-mobile personal computers (UMPC), netbooks, personal digital assistants (PDA), etc. The embodiments of the present application do not impose any restrictions on the specific types of terminal devices.
[0061] For example, the terminal device can be a station (STAION, ST) in a wireless local area network (Wireless Local Area Network, WLAN), a cellular phone, a cordless phone, a Session Initiation Protocol (SIP) phone, a Wireless Local Loop (WLL) station, a PDA device, a handheld device with wireless communication function, a computing device or other processing device connected to a wireless modem, a vehicle-mounted device, a vehicle networking terminal, a computer, a laptop computer, a handheld communication device, a handheld computing device, a satellite wireless device, a wireless modem card, a TV set-top box (Set Top Box, STB), a customer premises equipment (Customer Premise Equipment, CPE) and / or other equipment for communicating on a wireless system and a next-generation communication system, for example, a mobile terminal in a 5G network or a mobile terminal in a future evolved public land mobile network (Public Land Mobile Network, PLMN), etc.
[0062] As an example but not limitation, when the terminal device is a wearable device, the wearable device can also be a general term for wearable devices that are intelligently designed and developed using wearable technology for daily wear, such as glasses, gloves, watches, clothing and shoes. A wearable device is a portable device that is worn directly on the body or integrated into the user's clothes or accessories. Wearable devices are not just hardware devices, but can also achieve powerful functions through software support, data interaction, and cloud interaction. Broadly speaking, wearable smart devices include those that are fully functional, large in size, and can achieve complete or partial functions without relying on smartphones, such as smart watches or smart glasses, as well as those that only focus on a certain type of application function and need to be used in conjunction with other devices such as smartphones, such as various smart bracelets and smart jewelry for vital sign monitoring.
[0063] Take the terminal device as a mobile phone as an example. Figure 6 The block diagram shows a partial structure of a mobile phone provided in an embodiment of the present application. Figure 6 The mobile phone includes: a radio frequency (RF) circuit 610, a memory 620, an input unit 630, a display unit 640, a sensor 650, an audio circuit 660, a wireless fidelity (Wi-Fi) module 670, a processor 680, and a power supply 690. Those skilled in the art will understand that Figure 6 The mobile phone structure shown in the figure does not constitute a limitation on the mobile phone, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0064] Combine the following Figure 6 A detailed introduction to the various components of the mobile phone:
[0065] The RF circuit 610 can be used for receiving and sending signals during information transmission or calls. In particular, after receiving the downlink information of the base station, it is sent to the processor 680 for processing; in addition, the designed uplink data is sent to the base station. Generally, the RF circuit 610 includes but is not limited to an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier (Low Noise Amplifier, LNA), a duplexer, etc. In addition, the RF circuit 610 can also communicate with the network and other devices through wireless communication. The above wireless communication can use any communication standard or protocol, including but not limited to Global System of Mobile communication (Global System of Mobile communication, GSM), General Packet Radio Service (General Packet Radio Service, GPRS), Code Division Multiple Access (Code Division Multiple Access, CDMA), Wideband Code Division Multiple Access (Wideband Code Division Multiple Access, WCDMA), Long Term Evolution (Long Term Evolution, LTE)), email, Short Messaging Service (SMS), etc.
[0066] The memory 620 can be used to store software programs and modules. The processor 680 executes various functional applications and data processing of the mobile phone by running the software programs and modules stored in the memory 620. The memory 620 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, etc.), etc. In addition, the memory 620 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0067] The input unit 630 can be used to receive input digital or character information, and to generate key signal input related to the user settings and function control of the mobile phone 600. Specifically, the input unit 630 may include a touch panel 631 and other input devices 632. The touch panel 631, also known as a touch screen, can collect the user's touch operation on or near it (such as the user's operation on the touch panel 631 or near the touch panel 631 using any suitable object or accessory such as a finger, stylus, etc.), and drive the corresponding connection device according to a pre-set program. Optionally, the touch panel 631 may include a touch detection device and a touch controller. Among them, the touch detection device detects the user's touch orientation, detects the signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts it into the touch point coordinates, and then sends it to the processor 680, and can receive and execute the command sent by the processor 680. In addition, the touch panel 631 can be implemented in various types such as resistive, capacitive, infrared, and surface acoustic wave. In addition to the touch panel 631, the input unit 630 may also include other input devices 632. Specifically, the other input devices 632 may include but are not limited to one or more of a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, a joystick, etc.
[0068] The display unit 640 can be used to display information input by the user or information provided to the user and various menus of the mobile phone. The display unit 640 may include a display panel 641. Optionally, the display panel 641 may be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), etc. Further, the touch panel 631 may cover the display panel 641. When the touch panel 631 detects a touch operation on or near it, it is transmitted to the processor 680 to determine the type of touch event. Subsequently, the processor 680 provides a corresponding visual output on the display panel 641 according to the type of touch event. Although in Figure 6 In the embodiment, the touch panel 631 and the display panel 641 are used as two independent components to realize the input and output functions of the mobile phone, but in some embodiments, the touch panel 631 and the display panel 641 can be integrated to realize the input and output functions of the mobile phone.
[0069] The mobile phone 600 may also include at least one sensor 650, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor, wherein the ambient light sensor may adjust the brightness of the display panel 641 according to the brightness of the ambient light, and the proximity sensor may turn off the display panel 641 and / or the backlight when the mobile phone is moved to the ear. As a type of motion sensor, the accelerometer sensor can detect the magnitude of acceleration in all directions (generally three axes), and can detect the magnitude and direction of gravity when stationary. It can be used for applications that identify the posture of the mobile phone (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, tapping), etc.; as for other sensors that can be configured in the mobile phone, such as gyroscopes, barometers, hygrometers, thermometers, infrared sensors, etc., they will not be repeated here.
[0070] The audio circuit 660, the speaker 661, and the microphone 662 can provide an audio interface between the user and the mobile phone. The audio circuit 660 can transmit the received audio data to the speaker 661 after converting the received audio data into an electrical signal, which is converted into a sound signal for output; on the other hand, the microphone 662 converts the collected sound signal into an electrical signal, which is received by the audio circuit 660 and converted into audio data, and then the audio data is output to the processor 680 for processing, and then sent to another mobile phone through the RF circuit 610, or the audio data is output to the memory 620 for further processing.
[0071] Wi-Fi is a short-range wireless transmission technology. The mobile phone can help users send and receive emails, browse web pages and access streaming media through the Wi-Fi module 670, which provides users with wireless broadband Internet access. Figure 6 A Wi-Fi module 670 is shown, but it is understandable that it is not an essential component of the mobile phone 600 and can be omitted as needed without changing the essence of the present application.
[0072] The processor 680 is the control center of the mobile phone. It uses various interfaces and lines to connect various parts of the entire mobile phone. By running or executing software programs and / or modules stored in the memory 620, and calling data stored in the memory 620, it executes various functions of the mobile phone and processes data, thereby monitoring the mobile phone as a whole. Optionally, the processor 680 may include one or more processing units; preferably, the processor 680 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 680.
[0073] The mobile phone 600 also includes a power source 690 (such as a battery) for supplying power to various components. Preferably, the power source can be logically connected to the processor 680 through a power management system, so that the power management system can manage charging, discharging, power consumption and other functions.
[0074] Although not shown, the mobile phone 600 may further include a camera. Optionally, the camera may be located at the front or rear of the mobile phone 600, which is not limited in the present embodiment.
[0075] Optionally, the mobile phone 600 may include a single camera, a dual camera, or a triple camera, etc., which is not limited in the embodiments of the present application.
[0076] For example, the mobile phone 600 may include three cameras, one of which is a main camera, one is a wide-angle camera, and one is a telephoto camera.
[0077] Optionally, when the mobile phone 600 includes multiple cameras, all of the multiple cameras may be front-mounted, or all of the cameras may be rear-mounted, or some may be front-mounted and others may be rear-mounted, and this embodiment of the present application is not limited to this.
[0078] In addition, although not shown, the mobile phone 600 may also include a Bluetooth module, etc., which will not be described in detail here.
[0079] Figure 7 Schematic diagram of the software structure of the mobile phone 600 of the embodiment of the present application. Taking the Android system as an example, in some embodiments, the Android system is divided into four layers, namely, the application layer, the application framework layer (Framework, FWK), the system layer and the hardware abstraction layer, and the layers communicate with each other through software interfaces.
[0080] like Figure 7 As shown, the application layer may include a series of application packages, and the application packages may include short message, calendar, camera, video, navigation, gallery, call and other applications.
[0081] The application framework layer provides an application programming interface (API) and a programming framework for the application programs of the application layer. The application framework layer may include some predefined functions, such as a function for receiving events sent by the application framework layer.
[0082] like Figure 7 As shown, the application framework layer may include a window manager, a resource manager, a notification manager, and the like.
[0083] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc. The content provider is used to store and obtain data and make the data accessible to applications. The data may include video, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0084] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0085] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.
[0086] The application framework layer may also include:
[0087] The view system includes visual controls, such as controls for displaying text, controls for displaying pictures, etc. The view system can be used to build applications. The display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying pictures.
[0088] The phone manager is used to provide communication functions of the mobile phone 600, such as management of call status (including answering, hanging up, etc.).
[0089] The system layer may include multiple functional modules, such as sensor service module, physical state recognition module, 3D graphics processing library (such as OpenGL ES), etc.
[0090] The sensor service module is used to monitor the sensor data uploaded by various sensors at the hardware layer and determine the physical state of the mobile phone 600;
[0091] Physical state recognition module, used to analyze and recognize user gestures, faces, etc.;
[0092] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
[0093] The system layer may also include:
[0094] The surface manager is used to manage the display subsystem and provide the fusion of 2D and 3D layers for multiple applications.
[0095] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0096] The hardware abstraction layer is a layer between hardware and software. The hardware abstraction layer can include display drivers, camera drivers, sensor drivers, etc., which are used to drive related hardware of the hardware layer, such as display screens, cameras, sensors, etc.
[0097] The following embodiments can be implemented on a mobile phone 600 having the above hardware structure / software structure. The following embodiments will take the mobile phone 600 as an example to illustrate the application program running method provided in the embodiments of the present application.
[0098] Reference Figure 8 , shows a schematic flow chart of steps of a method for running an application program according to an embodiment of the present application. As an example but not a limitation, the method can be applied to the mobile phone 600 described above. The method can specifically include the following steps:
[0099] S801, when it is detected that an application is started, obtaining a class list file corresponding to the application;
[0100] The class list file in this embodiment may be pre-generated and stored in the terminal device, and the file may record which classes in the currently started application program can be initialized in advance.
[0101] Generally, static classes defined in application code do not depend on specific instantiated objects and can be initialized or executed independently. In this embodiment, the classes that can be initialized in advance may refer to these static classes.
[0102] Generally, static classes are modified with special words in the code, such as static. Therefore, in the specific implementation, the information of static classes that can be initialized in advance can be obtained by scanning and parsing the source code of the application. After the class names of these static classes that can be initialized in advance are written into the file, the corresponding class list file can be obtained.
[0103] S802, identifying the target class in the class list file;
[0104] The target class in the class list file may refer to all static classes that can be initialized in advance and are recorded in the file, or may refer to a part of the static classes, which is not limited in this embodiment.
[0105] Since initializing static classes in advance requires corresponding memory support, whether the system can initialize all static classes in advance has a great relationship with the memory size of the system. Therefore, if the system memory is sufficient or the application is expected to use all functional logic, all static classes in the class list file can be identified as target classes and initialized in advance.
[0106] If the system memory is not sufficient, only some static classes can be initialized during the advance initialization, and the target class can be a part of all static classes. Those skilled in the art can determine which static classes to identify as target classes in this case according to actual conditions, and this embodiment does not limit this.
[0107] S803: Start a target thread, and use the target thread to initialize the target class.
[0108] In this embodiment, the target thread may refer to a new thread that can be used to initialize a static class.
[0109] Usually, there may be multiple static classes that can be initialized in advance. When the static classes need to be initialized in advance, multiple target threads can be started based on the capabilities of the system's multi-core CPU, and the multiple target threads can initialize each target class in parallel to improve the running performance of the application.
[0110] In an embodiment of the present application, when the application is detected to be started, the target thread can be started by obtaining the class list file corresponding to the application and identifying the target class in the class list file, and then the target thread can be used to initialize these target classes. This embodiment can generate instructions that can be directly executed by the operating system more quickly by identifying the classes that can be initialized in advance in the program, without the need to recompile the application in a specified compiler, and without the need to compile the application code into a machine code file, thereby reducing the repeated occupation of disk space. All classes that meet the conditions for early initialization will obtain corresponding performance optimization benefits when initialized, which helps to improve the running performance of the application.
[0111] Reference Fig. 9 , shows a schematic flowchart of the steps of an application program running method according to another embodiment of the present application, and the method may specifically include the following steps:
[0112] S901, obtaining the source code of the application, and identifying the static class in the source code;
[0113] Since static classes defined in application code are generally modified by specific characters, such as static, before identifying static classes, the source code of the application can be obtained first, and then the source code can be scanned by a scanner component to generate a class list file corresponding to the application. The above class list file is a class subset that the application can use for early initialization.
[0114] In a specific implementation, the application package can be first obtained, and then the bytecode of the application can be obtained by parsing the package. Currently, there are many tools that can parse the code in the package into bytecode, such as decompressing a jar file: jar xf***.jar, etc.
[0115] After obtaining the above bytecode, a decompilation tool can be used to decompile the bytecode into source code, such as a decompilation JAVA tool: java decompiler***.class, etc.
[0116] It should be noted that the package parsing tools and decompilation tools introduced as examples above are all for the JAVA language, but those skilled in the art should understand that the package parsing tools and decompilation tools used for packages written in different programming languages may be different, and this embodiment does not limit this.
[0117] Of course, decompiling bytecodes into source codes is only one way to obtain source codes. If the application source codes can be directly obtained, the existing source codes can also be directly analyzed, which is not limited in this embodiment.
[0118] For the obtained source code, the static class of the application program can be identified by scanning the source code and parsing each class in the source code.
[0119] In a specific implementation, identifying a static class may include two scanning and parsing processes. First, when the source code is scanned for the first time, the initial static class can be identified. Taking JAVA language as an example, if the source code corresponding to a class contains variables and code segments marked with preset characters, and the initialization code corresponding to the class does not include other task execution logic, then the class can be identified as the initial static class, and the above-mentioned class can refer to any one of the classes. That is, for source code written in JAVA language, the initial static class should meet the following conditions: there are variables and code segments marked with static, and the initialization code does not contain other task execution logic. Among them, other task execution logic may refer to variables and code segments that are not marked with the preset character static.
[0120] As shown in Figure 10(a), it is a schematic diagram of the first scanning and parsing process when identifying static classes provided by an embodiment of the present application. By scanning the source code, parsing each class of the source code, and finding the static variables and static execution segments contained therein, and then analyzing whether the initialization code corresponding to these static variables and static execution segments does not include other task execution logic, if so, it can be preliminarily identified as a class that can be initialized in advance, that is, an initial static class.
[0121] Then, it is possible to detect whether the initialization code of the target initial static class has a calling relationship with other classes, and the above-mentioned target initial static class is any one of the initial static classes. If the initialization code of the target initial static class does not have a calling relationship with other classes, the target initial static class can be identified as a static class; if the initialization code of the target initial static class has a calling relationship with other classes, it is necessary to continue to determine whether the other classes with calling relationships are all initial static classes. Only when a certain target initial static class itself is a static class and the other classes called by its initialization code are all static classes, can the target initial static class be identified as a static class, otherwise, the target initial static class is identified as a non-static class.
[0122] As shown in Figure 10 (b), it is a schematic diagram of the second scanning and parsing process when identifying static classes provided by an embodiment of the present application. By scanning the source code, parsing each class of the source code, and finding the static variables and static execution segments contained therein, and then analyzing the inheritance relationship of the initialization code corresponding to these static variables and static execution segments. If it inherits from another class, it can be identified whether the class belongs to a static class based on the determination result of the parent class. If it does not inherit from another class, it can be determined whether the class references other classes. For those with multiple layers of nested calls, it can only be identified as a static class when all classes on its call path are static classes. Taking JAVA language as an example, if it is identified that the initialization code includes the ClassRef.methd or ClassRef.Variable format, it can be determined that the initialization code calls other classes.
[0123] As shown in Figure 10(b), when identifying whether the class belongs to a static class based on the judgment result of the parent class, there are two situations: one is that the judgment result of the parent class is a non-static class, then the currently identified class should also be identified as a non-static class; the other is that the judgment result of the parent class is a static class, at this time, the subsequent logic can continue to be executed to determine whether it references other classes to confirm whether the class can be initialized in advance.
[0124] S902, generating a class list file corresponding to the application based on the static class;
[0125] After scanning the application source code and identifying all static classes therein, a class list file of the application that can be initialized in advance can be generated. The class list file can record the class names of all static classes that can be initialized in advance.
[0126] S903, uploading the class list file to the server;
[0127] Since the class list file is independent of the operating system platform and only related to the application, the generated class list file can be uploaded to a server, which can be an application store or a cloud server. When other terminal devices obtain an application from the server and install it, the server can send the class list file corresponding to the application to the terminal device for use when the terminal device runs the application.
[0128] S904, when it is detected that the application is started, obtaining a class list file corresponding to the application;
[0129] S905, identifying the target class in the class list file;
[0130] S906: Start the target thread, and use the target thread to initialize the target class.
[0131] After generating a class list file corresponding to an application, when the application is started on a terminal device, the terminal device can first obtain the list file corresponding to the application, and then start the thread and initialize these classes in advance according to the class names of the static classes that can be initialized in advance recorded in the class list file.
[0132] It should be noted that since steps S904-S906 of this embodiment are similar to steps S801-S803 of the aforementioned embodiment, they can refer to each other, and are not described in detail in this embodiment.
[0133] In the embodiment of the present application, by scanning the source code of the application, the static classes that can be initialized in advance can be identified. After generating a class list file based on these static classes, the class list file can be uploaded to the server for download and use by other terminal devices, thereby expanding the scope of use of the class list file. At the same time, when identifying static classes based on the source code of the application, by judging whether other classes on the calling path of each static class with multiple layers of nested calls are also static classes, it is identified as a static class only when it itself and other classes on the calling path are static classes, thereby ensuring the accuracy of identification.
[0134] Reference Fig.11 , shows a schematic flowchart of the steps of a method for running an application program according to another embodiment of the present application, and the method may specifically include the following steps:
[0135] S1101, obtaining the source code of the application, and identifying the static class in the source code;
[0136] It should be noted that since step S1101 of this embodiment is similar to step S901 of the aforementioned embodiment, they can refer to each other, and this embodiment will not describe them in detail.
[0137] S1102, determining the initialization stage of each static class, and establishing a mapping relationship between the class name of each static class and the corresponding initialization stage;
[0138] Since initializing static classes in advance requires corresponding memory support, whether the system can initialize all static classes in advance has a great relationship with the memory size of the system. If the system memory is not particularly sufficient, you can establish a mapping relationship between each static class and its initialization stage in the class list file, so that when the application is running, each static class can be initialized in stages to reduce the occupation of system memory and disk.
[0139] In an embodiment of the present application, the mapping relationship between program activities and static class initialization can be completed through machine learning or custom notation, so as to initialize different static classes at the appropriate stage and reduce the resource overhead caused by excessive one-time initialization.
[0140] Since human-computer interaction is most sensitive to performance, this embodiment focuses on two implementation methods of establishing a mapping relationship for human-computer interaction in the Android operating system.
[0141] Startup phase: when the application startup is detected, the first static class that performs initialization operations within a preset time period from the start of the application startup is recorded, and the initialization phase of the first static class is determined as the startup phase.
[0142] In a specific implementation, the duration of the preset time period can be customized according to the system resource tolerance. For example, if the system memory is 2G, you can set it to record the first static class that is initialized within 2 seconds after the application is started. Generally, the more sufficient the memory resources are, the longer the above duration can be.
[0143] Take the preset time period of 2 seconds as an example. When the application is detected to be started, the static class initialized in this process can be recorded. When the 2 seconds are reached, the static class initialized can be stopped. Then, all static classes initialized within these 2 seconds are exported as the first static class in the startup phase.
[0144] Application execution phase: when it is detected that any interface of the application is started, the second static class that performs initialization operations during the period from the start of the interface to the completion of the interface startup is recorded, and the initialization phase of the second static class is determined as the application execution phase.
[0145] For example, when a user opens an interface of an application by clicking, the Android system can monitor the newly opened Activity interface and record all static classes initialized during this process. After the Activity interface is started, it stops recording the initialized static classes and exports all static classes initialized during this process as the second static class in the application execution phase.
[0146] S1103, generating a class list file corresponding to the application according to the mapping relationship;
[0147] After determining the mapping relationship between each static class and its initialization stage, the mapping relationship can be written into a class list file. The class list file records the class names of multiple static classes that can be initialized in advance and the initialization stage information of each static class.
[0148] S1104, when it is detected that the application is started, obtaining a class list file corresponding to the application; identifying a first static class in the class list file;
[0149] Since the first static classes are static classes that are initialized at the startup stage, when the startup of the application is detected, these first static classes can be firstly identified from the class list file.
[0150] S1105, start multiple target threads, determine the first static class corresponding to each target thread; and use each target thread to initialize the corresponding first static class in parallel;
[0151] Usually, the first static class belonging to the startup phase may include multiple classes, and most terminal devices also have multi-core CPU processing capabilities. Therefore, based on the multi-core CPU processing capabilities, multiple target threads can be started, and each first static class can be initialized in parallel by each target thread.
[0152] By identifying and initializing the first static class when detecting the application startup, rather than initializing all static classes in the process, the memory and disk space occupied by the initialized static classes can be effectively reduced, further improving the running performance of the application.
[0153] S1106. When it is detected that any interface of the application is started, identify the second static class in the class list file; start a new target thread, and use the new target thread to initialize the second static class.
[0154] For the second static class that performs initialization operation only during the application execution phase, when it is detected that the Activity interface of the application program is started, a new target thread can be started to perform the initialization operation of the second static class.
[0155] like Fig.12 As shown, it is a schematic diagram of the class initialization process of an embodiment of the present application. Fig.12 The process shown, by determining the initialization stage of each static class that can be initialized in advance, during the running of the application, when the corresponding time period is detected to have arrived, the thread can be started to initialize the static class of this stage, and then other program execution processes can be continued. This can reduce the resource overhead caused by initializing multiple static classes at one time during the running of the application, and more effectively improve the running performance of the application.
[0156] Reference Fig.13 , shows a schematic flowchart of the steps of a method for generating a class list file according to an embodiment of the present application, and the method may specifically include the following steps:
[0157] S1301, obtaining the source code of the application;
[0158] S1302, identifying static classes in the source code;
[0159] S1303: Generate a class list file corresponding to the application based on the static class.
[0160] It should be noted that the method for generating the class list file in this embodiment can be implemented in a terminal device or in a server, and this embodiment does not limit this.
[0161] If the class list file is generated in the terminal device, the terminal device can also upload the class list file to the server. When other terminal devices install the application, the server can send the corresponding class list file to the terminal device. The terminal device can directly use the class list file sent by the server to identify which classes can be initialized in advance.
[0162] Since steps S1301 - S1303 in this embodiment are similar to steps S901 - S902 and S1101 - S1103 in the aforementioned embodiment, relevant details may be referred to each other, and will not be described in detail in this embodiment.
[0163] For ease of understanding, the following describes the method for generating a class list file and the method for running an application program in this embodiment in combination with a specific system architecture, taking the Android operating system as an example.
[0164] like Fig.14 FIG. 1 is a schematic diagram of a system architecture to which the application program running method of this embodiment is applied. Fig.14 The system architecture shown includes a scanner, a class mapper, an application store / cloud server, and an asynchronous loader, etc. Each component is introduced in detail below.
[0165] 1. Scanner
[0166] The scanner component is responsible for scanning the source code of the application and generating a subset of classes that can be used for pre-initialization corresponding to the application, which is collectively referred to as "subset" below. The scanner can be deployed on Windows / Linux platforms and implemented in JAVA language. The scanned subset is copied to the class mapper or directly uploaded to the application store or cloud server.
[0167] You can add interfaces to the ART (Android Runtime) virtual machine to count the static classes initialized by the ART virtual machine.
[0168] The process may include:
[0169] 1.1. Parse the application package and parse the code in the package into the "bytecode" code;
[0170] 1.2. Decompile the "bytecode" code into "source code";
[0171] 1.3. Scan all source code for the first time and identify static classes. Taking JAVA language as an example, this class meets the following conditions: there are variables and code segments marked with static, and the initialization code does not contain other task execution logic;
[0172] 1.4. Scan all source codes for the second time, identify other classes that are called during initialization and are static classes, and put them into the static class subset. For those with multiple layers of nested calls, all classes on the calling path are required to be static classes. Taking JAVA language as an example, all methods of calling other classes in the initialization code are in the format of ClassRef.methd or ClassRef.Variable;
[0173] 1.5. After the scan is completed, a class list file is generated that can be initialized in advance for the application.
[0174] 2. Class mapper (optional)
[0175] Used to establish a mapping relationship between each class in the static class subset and the application execution stage. If the system memory is sufficient or it is expected that the application will use all functional logic, this step can be ignored, that is, all classes in the static class subset are directly loaded in the asynchronous loader.
[0176] The class mapper can be implemented in the Android operating system. At the Framework layer, it can monitor the startup of the application and the opening of a certain Activity interface, and call the corresponding interface of the ART virtual machine. The class mapper only needs to be deployed on a dedicated Android device, and after generating the class mapping result (class list file), it is uploaded to the application store or cloud server for storage.
[0177] The mapping relationship between program activities and static class initialization can be completed through machine learning or custom dotting, with the goal of initializing these static classes at the appropriate stage to reduce the resource overhead caused by excessive initialization. Since human-computer interaction is most sensitive to performance, the following focuses on two implementation methods for establishing mapping for human-computer interaction in the Android operating system:
[0178] Startup phase: Start timing when the application startup is detected, and notify the virtual machine to record all static classes initialized during this process. You can customize the time or quantity according to the system resource tolerance. For example, if you specify that a 2G memory system collects for 2 seconds, the more memory resources are available, the more time you can collect. When the collection time ends, notify the virtual machine to stop recording the initialized static classes, export all initialized static classes from the virtual machine, and define this subset as the "startup class subset."
[0179] Application execution phase: When the user clicks to open the interface, the Android system monitors the newly opened Activity interface and notifies the virtual machine to record all static classes initialized during this process. After the Activity interface is started, the virtual machine is notified to stop recording the initialized static classes, and all initialized static classes are exported from the virtual machine. The subset is defined as the "application execution class subset".
[0180] After the learning is completed, a class list file of the initialization phase corresponding to different execution phases of the application is generated.
[0181] 3. App Store / Cloud Server
[0182] Since the subset and class mapping relationship is independent of the operating system platform and only related to the application itself, the generated class list file can be uploaded to the application store or cloud server. When other terminal devices use the corresponding application, they can be directly downloaded from the server.
[0183] 4. Asynchronous Loader
[0184] It is used to asynchronously load and initialize the static class of the corresponding stage of the application, which can make full use of the multi-core CPU capabilities of the current terminal device and improve the running performance of the application.
[0185] The asynchronous loader can be implemented in the Android operating system. It downloads the class mapping results from the app store or cloud server. After monitoring the activity of the application at the Framework layer, it compares the results with the class mapping results, queries the corresponding class subset that needs to be initialized for the current activity, starts a new thread, calls the ART virtual machine reflection interface, and initializes these classes in parallel in advance.
[0186] It should be noted that although the various embodiments of this application take the Android system and JAVA language as examples to implement a solution for class initialization optimization, this application is essentially an initialization optimization method for program classes of all object-oriented and cross-platform languages. Therefore, in terms of application scenarios, this application is not only for Android as an operating system and JAVA as a programming language, but similar operating systems and object-oriented and cross-platform languages can also implement the deployment of this application to improve the operating performance of the application.
[0187] In addition, it should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0188] Corresponding to the application program running method of the above embodiment, Fig.15 The structural block diagram of an application program running device provided by an embodiment of the present application is shown, and the device can be applied to a terminal device. For the convenience of description, only the part related to the embodiment of the present application is shown.
[0189] Reference Fig.15 The application running device may specifically include the following modules:
[0190] The acquisition module 1501 is used to acquire a class list file corresponding to the application when detecting that the application is started;
[0191] An identification module 1502, used to identify a target class in the class list file;
[0192] The initialization module 1503 is used to start the target thread and use the target thread to initialize the target class.
[0193] In the embodiment of the present application, the device may further include the following modules:
[0194] A static class identification module, used to obtain the source code of the application and identify the static classes in the source code;
[0195] The class list file generating module is used to generate a class list file corresponding to the application based on the static class.
[0196] In the embodiment of the present application, the static class identification module may specifically include the following submodules:
[0197] A program package acquisition submodule, used to acquire the program package of the application;
[0198] A program package parsing submodule, used for parsing the program package to obtain the bytecode of the application program;
[0199] The bytecode decompilation submodule is used to decompile the bytecode into source code.
[0200] In the embodiment of the present application, the static class identification module may further include the following submodules:
[0201] A class parsing submodule, used for parsing each class in the source code;
[0202] An initial static class identification submodule, for identifying a class as an initial static class if the source code corresponding to any class contains variables and code segments marked with preset characters, and the initialization code corresponding to the class only includes constants;
[0203] A call relationship detection submodule, used to detect whether the initialization code of the target initial static class has a call relationship with other classes, the target initial static class being any one of the initial static classes;
[0204] The static class identification submodule is used to identify the target initial static class as a static class if the initialization code of the target initial static class does not have a calling relationship with other classes; if the initialization code of the target initial static class has a calling relationship with other classes, it is used to determine whether the other classes with the calling relationship are all initial static classes. If so, the target initial static class is identified as a static class; otherwise, the target initial static class is identified as a non-static class.
[0205] In the embodiment of the present application, the class list file generation module may specifically include the following submodules:
[0206] A mapping relationship establishment submodule, used to determine the initialization phase of each static class, and establish a mapping relationship between the class name of each static class and the corresponding initialization phase;
[0207] The class list file generating submodule is used to generate a class list file corresponding to the application according to the mapping relationship.
[0208] In the embodiment of the present application, the mapping relationship establishment submodule may specifically include the following units:
[0209] A first static class identification unit is used to record, when detecting that the application is started, a first static class that performs an initialization operation within a preset time period from the start of the application, and determine that the initialization phase of the first static class is a startup phase;
[0210] The second static class identification unit is used to record the second static class that performs initialization operations within the time period from the start of the interface startup to the completion of the interface startup when detecting the startup of any interface of the application, and determine the initialization stage of the second static class as the application execution stage.
[0211] In the embodiment of the present application, the device may further include the following modules:
[0212] The class list file uploading module is used to upload the class list file to the server.
[0213] In the embodiment of the present application, the identification module 1502 may specifically include the following submodules:
[0214] The first static class identification submodule is used to identify the first static class in the class list file.
[0215] In the embodiment of the present application, the first static class may include multiple ones, and the initialization module 1503 may specifically include the following submodules:
[0216] A target thread starting submodule, used to start multiple target threads and determine the first static class corresponding to each target thread;
[0217] The first static class initialization submodule is used to use each of the target threads to initialize the corresponding first static class in parallel.
[0218] In the embodiment of the present application, the initialization module 1503 may further include the following submodules:
[0219] A second static class identification submodule, configured to identify a second static class in the class list file when detecting that any interface of the application is started;
[0220] The second static class initialization submodule is used to start a new target thread and use the new target thread to initialize the second static class.
[0221] This embodiment identifies classes that can be initialized in advance in the program. This makes it possible to generate instructions that can be directly executed by the operating system more quickly without recompiling the application in a specified compiler, and without compiling the application code into a machine code file, thereby reducing the repeated occupation of disk space. All classes that meet the conditions for early initialization will obtain corresponding performance optimization benefits during initialization, which helps to improve the operating performance of the application.
[0222] Corresponding to the method for generating the class list file in the above embodiment, Fig.16 The structural block diagram of a device for generating a class list file provided by an embodiment of the present application is shown. For the sake of convenience, only the parts related to the embodiment of the present application are shown.
[0223] Reference Fig.16 The generation device of this type of list file may specifically include the following modules:
[0224] An acquisition module 1601 is used to acquire the source code of the application program;
[0225] An identification module 1602, used for identifying static classes in the source code;
[0226] The generating module 1603 is used to generate a class list file corresponding to the application based on the static class.
[0227] In the embodiment of the present application, the device may further include the following modules:
[0228] The uploading module is used to upload the class list file to a server, and the server is used to send the class list file to the terminal device when the terminal device installs the application.
[0229] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiment part.
[0230] Fig.17 This is a schematic diagram of the structure of a terminal device provided in an embodiment of the present application. Fig.17 As shown, the terminal device 1700 of this embodiment includes: at least one processor 1710 ( Fig.17 Only one is shown in the figure) a processor, a memory 1720, and a computer program 1721 stored in the memory 1720 and executable on the at least one processor 1710. When the processor 1710 executes the computer program 1721, the steps in each embodiment of the above-mentioned application program running method are implemented, for example Figure 8 Alternatively, when the processor 1710 executes the computer program 1721, the functions of each module in the above-mentioned device embodiments are implemented, for example Fig.15 Functions of modules 1501 to 1503 are shown.
[0231] Exemplarily, the computer program 1721 may be divided into one or more modules, which are stored in the memory 1720 and executed by the processor 1710 to complete the present application. The one or more modules may be a series of computer program instruction segments that can perform specific functions, and the instruction segments may be used to describe the execution process of the computer program 1721 in the terminal device 1700. For example, the computer program 1721 may be divided into an acquisition module, an identification module, and an initialization module), and the specific functions of each module are as follows:
[0232] An acquisition module, used for acquiring a class list file corresponding to the application when detecting that the application is started;
[0233] An identification module, used for identifying a target class in the class list file;
[0234] The initialization module is used to start the target thread and use the target thread to initialize the target class.
[0235] The terminal device 1700 may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The terminal device 1700 may include, but is not limited to, a processor 1710 and a memory 1720. Those skilled in the art will appreciate that Fig.17 It is only an example of the terminal device 1700 and does not constitute a limitation of the terminal device 1700. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the terminal device 1700 may also include input and output devices, network access devices, buses, etc.
[0236] The processor 1710 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0237] The memory 1720 may be an internal storage unit of the terminal device 1700, such as a hard disk or memory of the terminal device 1700. The memory 1720 may also be an external storage device of the terminal device 1700, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the terminal device 1700. Further, the memory 1720 may also include both an internal storage unit of the terminal device 1700 and an external storage device. The memory 1720 is used to store the computer program 1721 and other programs and data required by the terminal device 1700. The memory 1720 may also be used to temporarily store data that has been output or is to be output.
[0238] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In actual applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the application running device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in one processing unit, or each unit can exist physically separately, or two or more units and modules can be integrated in one unit. The above-mentioned integrated units and modules can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0239] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0240] Those of ordinary skill in the art will appreciate that the units, modules, and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0241] The units and modules described as separate components may or may not be physically separated, and the components shown as units and modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0242] If the integrated units and modules are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment of the application program running method and the class list file generation method, which can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of each embodiment of the above-mentioned application program running method and class list file generation method can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may at least include: any entity or device that can carry the computer program code to the terminal device, a recording medium, a computer memory, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), an electric carrier signal, a telecommunication signal and a software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk. In some jurisdictions, according to legislation and patent practice, a computer-readable medium may not be an electric carrier signal and a telecommunication signal.
[0243] The above-described embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application is described in detail with reference to the above-mentioned embodiments, a person skilled in the art should understand that the technical solutions described in the above-mentioned embodiments can still be modified, or some of the technical features can be replaced by equivalents; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application.
Claims
1. A method for running an application, characterized in that: include: When it is detected that an application is started, a class list file corresponding to the application is obtained, wherein the application is compiled in a cross-platform programming language, and the class list file records a plurality of static classes that can be initialized in advance, wherein the static classes include variables and code segments marked with preset codes, and the initialization code does not contain other task execution logic; Identify a target class among a plurality of static classes in the class list file; A target thread is started, and the target class is initialized in advance using the target thread.
2. The method according to claim 1, characterized in that: Before obtaining the class list file corresponding to the application, the method further includes: Obtaining source code of the application, and identifying static classes in the source code; Based on the static class, a class list file corresponding to the application is generated.
3. The method according to claim 2, characterized in that The obtaining of the source code of the application comprises: Obtaining a program package of the application; Parsing the program package to obtain the bytecode of the application program; The bytecode is decompiled into source code.
4. The method according to claim 2 or 3, characterized in that: The identifying of the static class in the source code comprises: Parsing each class in the source code; If the source code corresponding to a certain class includes variables and code segments marked with preset characters, and the initialization code corresponding to the certain class does not include other task execution logic, then the certain class is identified as an initial static class, and the other task execution logic is variables and code segments not marked with preset characters; Detect whether the initialization code of the target initial static class has a calling relationship with other classes, the target initial static class is any one of the initial static classes, and the other classes are classes among the classes except the one class; If the initialization code of the target initial static class has no calling relationship with other classes, the target initial static class is identified as a static class; If the initialization code of the target initial static class has a calling relationship with other classes, it is determined whether the other classes with the calling relationship are all initial static classes. If so, the target initial static class is identified as a static class; otherwise, the target initial static class is identified as a non-static class.
5. The method according to claim 2, characterized in that: The step of generating a class list file corresponding to the application based on the static class includes: Determine the initialization phase of each static class, and establish a mapping relationship between the class name of each static class and the corresponding initialization phase; According to the mapping relationship, a class list file corresponding to the application is generated.
6. The method according to claim 5, characterized in that Determining the initialization phase of each static class includes: When the application is detected to be started, a first static class that performs initialization operations within a preset time period starting from the start of the application is recorded, and the initialization phase of the first static class is determined to be a startup phase; When detecting that any interface of the application is started, recording the second static class that performs initialization operations during the time period from the start of the interface startup to the completion of the interface startup, and determining the initialization stage of the second static class as the application execution stage.
7. The method according to claim 2, 5 or 6, characterized in that: Also includes: Upload the class list file to the server.
8. The method according to claim 6, characterized in that The step of identifying a target class among a plurality of static classes in the class list file comprises: A first static class in the class list file is identified.
9. The method according to claim 8, characterized in that The first static class includes a plurality of classes, and the starting of the target thread and initializing the target class in advance using the target thread include: Start multiple target threads and determine the first static class corresponding to each target thread; The target threads are used to initialize the corresponding first static classes in parallel.
10. The method according to claim 8, characterized in that Also includes: When it is detected that any interface of the application is started, identifying the second static class in the class list file; A new target thread is started, and the second static class is initialized using the new target thread.
11. A method for generating a class list file, characterized in that: include: Get the source code of the application; Identifying a static class in the source code, wherein the application is compiled using a cross-platform programming language, the static class includes variables and code segments marked with preset codes, and the initialization code does not include other task execution logic; Based on the static class, a class list file corresponding to the application is generated, wherein the class list file is used to identify a target class among multiple static classes when detecting the start of the application, and initialize the target class in advance through a target thread.
12. The method according to claim 11, characterized in that Also includes: The class list file is uploaded to a server, and the server is used to send the class list file to the terminal device when the terminal device installs the application.
13. An application program running device, characterized in that: include: An acquisition module is used to acquire a class list file corresponding to the application when detecting that the application is started, wherein the application is compiled in a cross-platform programming language, and the class list file records a plurality of static classes that can be initialized in advance, wherein the static classes include variables and code segments marked with preset codes, and the initialization code does not contain other task execution logic; An identification module, used for identifying a target class among a plurality of static classes in the class list file; The initialization module is used to start the target thread and use the target thread to initialize the target class in advance.
14. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the application running method according to any one of claims 1 to 10 is implemented.
15. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the application program running method according to any one of claims 1 to 10 is implemented.
