Application class generation method and device, equipment, medium and product

By creating class object index information and product information in the Android system, loading target data and controlling the effectiveness of target class objects, the compilation failure and product unavailability problems in the dex2oat compilation process are solved, and the operating efficiency of the application is improved.

CN120596099APending Publication Date: 2025-09-05BEIJING ZITIAO NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510692264.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-27
Publication Date
2025-09-05

AI Technical Summary

Technical Problem

In the Android system, the dex2oat compilation process is prone to compilation failure, unusable compilation products, or no compilation products, making it difficult to improve the operating efficiency of the application.

Method used

By creating class object index information and product information, loading target data and associating it with the class object index information, generating and controlling the effectiveness of the target class object, thereby generating the target compilation product, and realizing fast search and use of the target compilation product.

Benefits of technology

When the compilation information lacks the target compilation product, the effect similar to the existence of the compilation product is achieved, thereby improving the operating efficiency of Android system applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120596099A_ABST
    Figure CN120596099A_ABST
Patent Text Reader

Abstract

The invention discloses a class generation method and device of an application program, equipment, a medium and a product, and relates to the technical field of computers, the method comprises the following steps: obtaining compiling information generated for the application program; if the target compiling product is missed in the compiling information, creating class object index information and product information corresponding to the class object index information; loading target data corresponding to the product information, and associating the target data with the class object index information to obtain a target class object; and controlling the target class object to take effect, and generating a target compiling product corresponding to the target class object. According to the technical scheme, under the conditions that compiling fails, the compiling product is unavailable, no compiling product exists and the like, the target class object is used for achieving rapid searching of the target compiling product, and the effect similar to existence of the compiling product is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method, apparatus, device, medium and product for generating a class of an application program. Background Art

[0002] Currently, the Android system uses dex2oat to compile and generate products to accelerate application execution. However, triggering dex2oat inevitably leads to compilation failures, unusable compilation products, or even the absence of compilation products, making it difficult to utilize compilation products to improve application efficiency. Summary of the Invention

[0003] In view of this, the present invention provides a method, apparatus, device, medium and product for generating a class of an application program, so as to solve the problem that it is difficult to improve the operating efficiency of the application program by utilizing the compiled product.

[0004] In a first aspect, the present invention provides a class generation method for an application, comprising: obtaining compilation information generated for the application; if the target compilation product is missing in the compilation information, creating class object index information and product information corresponding to the class object index information; loading target data corresponding to the product information, associating the target data with the class object index information, and obtaining a target class object; controlling the target class object to take effect, and generating a target compilation product corresponding to the target class object.

[0005] In the second aspect, the present invention provides a class generation device for an application, including: a compilation information acquisition module, used to obtain compilation information generated for the application; a class object parameter acquisition module, used to create class object index information and product information corresponding to the class object index information if the target compilation product is missing in the compilation information; a loading module, used to load target data corresponding to the product information, associate the target data with the class object index information, and obtain a target class object; and an effectiveness control module, used to control the effectiveness of the target class object and generate a target compilation product corresponding to the target class object.

[0006] In a third aspect, the present invention provides an electronic device comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the class generation method of the application of the above-mentioned first aspect or any corresponding embodiment thereof by executing the computer instructions.

[0007] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the class generation method for an application program according to the first aspect or any corresponding embodiment thereof.

[0008] In a fifth aspect, the present invention provides a computer program product comprising computer instructions for causing a computer to execute the class generation method for an application program according to the first aspect or any corresponding embodiment thereof.

[0009] The application class generation method, apparatus, device, medium, and product provided by the embodiments of the present invention, when the target compilation product is missing from the compilation information, creates corresponding class object index information and its corresponding product information, loads corresponding target data based on the product information, and associates the target data with the class object index information to obtain a target class object. Subsequently, by controlling the target class object to take effect, a corresponding target compilation product can be generated based on the target class object. Thus, the target class object can be used to quickly search for the target compilation product, achieving an effect similar to that of the existing compilation product. Subsequently, the operation of the Android system application can be accelerated according to the generated target compilation product, thereby improving the operating efficiency of the Android system application. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in related technologies, the following briefly introduces the drawings required for use in the specific embodiments or related technical descriptions. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0011] Figure 1 is a schematic diagram of an application scenario according to an embodiment of the present invention;

[0012] Figure 2 is a flow chart of a method for generating a class of an application program according to an embodiment of the present invention;

[0013] Figure 3 is a flow chart of a class generation method for another application according to an embodiment of the present invention;

[0014] Figure 4 is a flow chart of a method for generating a class of another application according to an embodiment of the present invention;

[0015] Figure 5 is a structural block diagram of a device for generating a class for an application according to an embodiment of the present invention;

[0016] Figure 6 FIG. 4 is a schematic diagram of the hardware structure of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0017] To make the purpose, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making creative efforts shall fall within the scope of protection of the present invention.

[0018] It is understandable that before using the technical solutions disclosed in the various embodiments of this disclosure, the type, scope of use, usage scenarios, etc. of the personal information involved in this disclosure should be informed to the user and the user's authorization should be obtained in an appropriate manner in accordance with relevant laws and regulations.

[0019] For example, in response to a user's active request, a prompt message is sent to the user to clearly inform the user that the operation requested will require the acquisition and use of the user's personal information. This allows the user to independently choose whether to provide personal information to the electronic device, application, server, storage medium, or other software or hardware that performs the operations of the disclosed technical solution based on the prompt message.

[0020] As an optional but non-limiting implementation, in response to receiving a user's active request, the prompt information may be sent to the user in the form of a pop-up window, in which the prompt information may be presented in text form. Furthermore, the pop-up window may also contain a selection control for the user to select "agree" or "disagree" to provide personal information to the electronic device.

[0021] It is understandable that the above notification and user authorization process are merely illustrative and do not limit the implementation of the present disclosure. Other methods that comply with relevant laws and regulations may also be applied to the implementation of the present disclosure.

[0022] It is understandable that the data involved in this technical solution (including but not limited to the data itself, the acquisition or use of the data) must comply with the requirements of relevant laws, regulations and relevant provisions.

[0023] Currently, Android systems use dex2oat to compile and generate artifacts to accelerate application execution. However, dex2oat is generally triggered in two ways: 1) by invoking dex2oat commands in the application process to trigger compilation; 2) by detecting that the application is idle and charging.

[0024] Compilation method 1) can cause compilation failures (for example, OOM errors during compilation due to large dex sizes). Furthermore, differences between the compilation environment and the runtime environment can lead to unusable compilation products (for example, changes in plugin dependencies and a dependent plugin can cause product unusability). Compilation method 2) requires relatively stringent compilation conditions, making them virtually impossible to meet and thus preventing compilation.

[0025] Therefore, the current situation is that there are problems such as compilation failure, unusable compilation products, and no compilation products. Ultimately, it is impossible to use the compilation products to improve operating efficiency.

[0026] Based on this, the disclosed technical solution creates a class object, loads the target data required to compile the class object, sets the generated target data to the corresponding class object, and validates the class object to obtain the corresponding compiled product. Thus, the class lookup optimization effect of the compiled product can be achieved based on the currently valid class object.

[0027] As an optional application scenario of the embodiment of the present invention, Figure 1 As shown, the application scenario includes an initialization node 101, a loading node 102, a cache node 103, and a validation node 104. Specifically, the initialization node 101, the loading node 102, the cache node 103, and the validation node 104 are connected in communication. Among them, the initialization node 101 is used to initialize the class object, including obtaining the size of the class object, obtaining the relevant class object constructor and skipping the environment check, obtaining the function of generating and loading memory data, and obtaining the relevant function loaded from the original data in the memory. The loading node 102 is used to load the target data required for compiling the class object. If there is no cache, the relevant data is generated and loaded from the memory; if there is a cache, the cached data is read into the memory to obtain the original data, and then the relevant function loaded from the original data in the memory is called for loading. The cache node 103 is used to store the generated original data to the disk for direct reading and loading next time, reducing the generation time. The validation node 104 is used to set the generated data to the corresponding class object to make the class object effective.

[0028] Therefore, when searching for compiled products, the class search optimization effect of the compiled products can be achieved based on the currently effective class object.

[0029] The initialization node 101, the loading node 102, the cache node 103, and the validation node 104 are deployed on a computer device. The computer device represents a device having computing resources or computing capabilities, and can be a device with computing capabilities. For example, the computer device can be provided with a processor and memory, or can be equipped with a dedicated accelerator (such as a graphics processing unit (GPU)). In addition, the computer device can store and maintain data.

[0030] Examples of computer devices may include supercomputers, personal computers, laptop computers, vehicle-mounted computing devices, mobile devices (such as smartphones, tablet computers, etc.), or a combination of any one or more of the above devices. It should be understood that the computer devices described herein are merely exemplary and non-limiting, and for example, other different types of computer devices may also be used.

[0031] According to an embodiment of the present invention, an embodiment of a class generation method for an application is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0032] In this embodiment, a method for generating a class of an application is provided, which can be used for computer devices such as computers, tablet computers, mobile phones, etc. Figure 2 is a flow chart of a method for generating a class of an application according to an embodiment of the present invention. Figure 2 As shown, the process includes the following steps:

[0033] Step S201: Obtain compilation information generated for the application.

[0034] An application is a program deployed on the Android system; the compilation information is the compilation product generated by code development and code compilation for the Android system application. Specifically, the Android system will compile and generate products through the dex2oat method to speed up the running speed of the application. Among them, dex2oat is a tool in the application development process of the Android system, which is used to convert ".dex" files (i.e. Dalvik Executable, Dalvik executable file) into ".oat" files (i.e. Optimized Android Executable, optimized Android executable file). This process is an operation that must be completed before the Android system executes the ".dex" file on a computer device. dex2oat converts the ".dex" file into an optimized ".oat" file, including code optimization, data layout optimization and memory layout optimization. The corresponding compilation information is obtained by executing the ".oat" file.

[0035] Step S202: If the target compilation product is missing in the compilation information, create class object index information and product information corresponding to the class object index information.

[0036] The target compilation product is the compilation information required to load and deploy and run the application; the class object index information refers to the specific instance created by the class definition. The class object index information includes all metadata of the class object, such as properties, methods, and constructors. Among them, the class definition defines the properties and methods of the object and is used to create objects. The object is a specific instance of the class, which is the embodiment of the class definition. Each object has its corresponding data and methods; the product information is the compilation product corresponding to the class object. The product information is used to control the compilation process of the class object, optimize the compilation results, and provide specific guidance during the compilation process.

[0037] Traverse the classes in the compilation information to determine whether the target compilation product exists. If the target compilation product is missing, class object index information and the product information corresponding to the class object index information are required to accelerate the application's execution. Thus, even if the target compilation product is missing, creating the class object index information can achieve the same effect as if a compilation product existed.

[0038] Step S203: load the target data corresponding to the product information, associate the target data with the class object index information, and obtain the target class object.

[0039] The target data is the specific parameter value corresponding to the product information; the target class object is the class object generated by setting the target data on the class object index information. Specifically, the parameters corresponding to the product information are parsed, and the target data corresponding to the product information is filled into the corresponding parameters of the product information to complete the loading of the target data. Through the class lookup setting method (such as the SetTypeLookupTable method), the loaded target data is set to the corresponding class object index information, and the target data is associated with the class object index information to map different class objects to the corresponding processing functions and generate the corresponding target class objects.

[0040] Step S204: controlling the target class object to take effect and generating a target compilation product corresponding to the target class object.

[0041] Since the target class object is created for application development, after obtaining the target class object, you need to add a trigger opportunity for it and create a trigger entry method corresponding to the trigger opportunity. Then, using the trigger entry method, you validate the created target class object. Based on the validated target class object, you generate and load data for the class object index information, obtaining the target compilation product corresponding to the target class object.

[0042] The application class generation method provided in this embodiment, when the target compilation product is missing from the compilation information, creates corresponding class object index information and its corresponding product information, loads the corresponding target data based on the product information, and associates the target data with the class object index information to obtain a target class object. This target class object is then activated to generate the corresponding target compilation product based on it. This allows for rapid search of the target compilation product using the target class object, achieving a similar effect to the presence of the compilation product. This generated target compilation product can then be used to accelerate the operation of Android system applications, improving the operating efficiency of Android system applications.

[0043] In this embodiment, a method for generating a class of an application is provided, which can be used in computer devices such as computers, tablet computers, mobile phones, etc. Figure 3 is a flow chart of a method for generating a class of an application according to an embodiment of the present invention. Figure 3 As shown, the process includes the following steps:

[0044] Step S301: Obtain compilation information generated for the application program. Please refer to the description of the corresponding steps in the above embodiment for details, which will not be repeated here.

[0045] Step S302: If the target compilation product is missing in the compilation information, create class object index information and product information corresponding to the class object index information.

[0046] Specifically, the above step S302 includes:

[0047] Step S3021: If the target compilation product is missing in the compilation information, create class object index information. Please refer to the description of the corresponding steps in the above embodiment for details, which will not be repeated here.

[0048] Step S3022: Obtain the memory space corresponding to the class object index information.

[0049] The memory space is the storage space required for the memory structure of the related data of the class object index information. By analyzing the construction method of the class object (i.e., OatDexFile) index information, the construction logic of the class object OatDexFile is determined, and the memory space required to construct the class object OatDexFile is extracted from the construction logic.

[0050] In some optional implementations, step S3022 includes:

[0051] Step a1: When the creation of index information for a class object is triggered, the memory space is obtained using an anchor point method.

[0052] The anchor method is related to the Android system's handling of dex and oat files. Dex files are the executable file format for Android applications, containing Java bytecode. Oat files are optimized versions of dex files, used on Android devices to reduce memory usage and improve execution efficiency. OatDexFile is an Android class object used to load and parse oat files, which can be converted from dex files using the DexOpt tool.

[0053] The anchor method can only obtain memory space when the OatDexFile construction logic has been triggered. Specifically, it detects whether the construction logic for the class object index information has been triggered. If it is detected that the creation of the class object index information has been triggered, it means that the construction logic for the class object has been triggered. Then, the construction logic will include the method for obtaining the class object memory space. At this time, the memory space required by the class object has been determined at compile time, so the memory space will exist as a fixed value in the anchor method instruction.

[0054] In a specific example, the corresponding anchor method is selected based on the Android system version level. For example, when the Android system version level is below a first preset value, the anchor method "jit#CompileMethodsFromProfile" can be used; otherwise, the anchor method "jit#CreateThreadPool" can be used. The first preset value is a pre-set level value, such as Android 10 or API level 29.

[0055] Step a2: Analyze the key instructions corresponding to the class object index information to determine the target location of the key instructions.

[0056] Step a3: Determine the parameter value corresponding to the target position as the memory space.

[0057] The key instruction is the memory allocation instruction for the class object index information determined from the instruction set; the target location is the location of the key instruction in the instruction set. By analyzing the instruction patterns in the instruction set and the individual instruction codes, the target location of the key instruction is located. Based on the format of the key instruction, the parameter value corresponding to the key instruction is extracted and the parameter value is determined as memory space.

[0058] Specifically, by analyzing each instruction in the instruction set, parsing starts from the starting position of the anchor method, finding the position of the first jump target method (that is, the constructor of the class object OatDexFile), and then searching in reverse order. After finding the bl instruction again (that is, executing the new operation), find the target position of the first use of the mov instruction. The immediate value assigned to the register by the mov instruction is the memory space required to construct the class object OatDexFile.

[0059] In the above implementation, the memory space required for constructing the class object index information is obtained by obtaining the anchor point or instruction analysis, so as to construct the framework of the class object in the memory space according to the class object index information and realize the initialization of the class object.

[0060] Step S3023: triggering a creation operation for the class object index information, and determining product construction parameters and data loading parameters corresponding to the creation operation.

[0061] Product construction parameters are the parameters required to create the class object framework; data loading parameters are the parameters required to load the class object. After initialization is complete, the class object's object framework is obtained. At this point, the creation of class object index information can be triggered according to the object framework, and the product construction parameters and data loading parameters corresponding to the class object index information can be obtained.

[0062] In some optional implementations, step S3023 includes:

[0063] Step b1, obtaining the class generation method, class opening method, data length acquisition method and class compilation method corresponding to the creation operation.

[0064] Step b2: Initialize the class generation method to obtain product construction parameters corresponding to the class object index information.

[0065] Step b3: Initialize the class opening method, data length acquisition method, and class compilation method to obtain data loading parameters corresponding to the class object index information.

[0066] The class generation method TypeLookupTable#Create means traversing the information of all classes in the dex file through the information stored in the dex file to generate a map structure; the class opening method TypeLookupTable#Open means generating a map through the information stored in the dex file and combining it with the original data of the map structure serialized on the disk; the data length acquisition method indicates the amount of stored map data; the class compilation method indicates constructing the class object OatDexFile index information.

[0067] Specifically, the class object generation method TypeLookupTable#Create is initialized to obtain the class object generation method TypeLookupTableCreate applied to the Android system. Its address is obtained through the symbol, and the method is directly called to create class object index information. Among them, the class object generation method TypeLookupTableCreate applied to the Android system is used as a product construction parameter.

[0068] Specifically, the class object opening method TypeLookupTable#Open is initialized to obtain the class opening method TypeLookupTableOpen applied to the Android system, and its address is obtained through the symbol to directly call the method to open the class object index information.

[0069] Initialize the class object data TypeLookupTable#entries to obtain the class data length acquisition method TypeLookupTableRawDataLength applied to the Android system. Get its address through the symbol to directly call the method to read the class object index information to obtain the number of map data.

[0070] Initialize the class object OatDexFile construction method to obtain the class object construction method New_OatDexFile applied to the Android system, obtain its address through the symbol, and directly call the method to construct the application class object OatDexFile index information in the Android system.

[0071] The above-determined class opening method TypeLookupTableOpen applied to the Android system, the data length obtaining method TypeLookupTableRawDataLength applied to the Android system, and the class object construction method New_OatDexFile applied to the Android system are determined as data loading parameters.

[0072] In the above implementation, the class generation method, the class opening method, the data length acquisition method, and the class compilation method are initialized to conform to the system environment of the Android system, thereby ensuring that data can be loaded accurately and quickly.

[0073] In some optional embodiments, the above method further includes:

[0074] Step c1: Obtain the creation start position of the creation operation for the class object index information.

[0075] Step c2: traverse the creation instructions corresponding to the component operation from the creation start position, and determine whether the currently traversed creation instruction is an environment verification instruction.

[0076] Step c3: If it is determined that the currently traversed creation instruction is an environment check instruction, the environment check instruction is adjusted to a target instruction, and the target instruction is used to instruct to skip the environment check.

[0077] The creation starting position is the starting position of the class object OatDexFile construction method; the creation instruction represents an instruction for creating the class object OatDexFile index information; the environment verification instruction is an instruction for performing environment verification on the class object OatDexFile index information.

[0078] Specifically, through instruction parsing, the memory space required for the class object OatDexFile index information can be learned, and a construction method for the class object OatDexFile index information can be created. By parsing the construction method of the class object OatDexFile index information, the creation starting position of the class object OatDexFile index information is determined, and the creation instructions in the construction method of the class object OatDexFile are traversed from the creation starting position to determine whether the currently traversed creation instruction is an environment verification instruction. Since the construction method of the class object OatDexFile may carry an environment verification instruction, the instruction can be corrected at this time to skip the environment verification.

[0079] In a specific example, if the environment check instruction is determined by the CBZ instruction, the CBZ instruction is modified to a B instruction to skip the environment check and continue execution from the corresponding position.

[0080] In another specific example, if the environment check instruction is determined by the CBNZ instruction, the CBNZ instruction is modified into a NOP instruction to skip the environment check and continue execution from the corresponding position.

[0081] In the above implementation, the environment check instruction is adjusted to skip the environment check, thereby ensuring that the instruction can be executed smoothly in the Android system.

[0082] Step S303: load the target data corresponding to the product information, associate the target data with the class object index information, and obtain the target class object. Please refer to the description of the corresponding steps in the above embodiment for details, which will not be repeated here.

[0083] Step S304: Control the target class object to take effect and generate a target compilation product corresponding to the target class object. For details, please refer to the description of the corresponding steps in the above embodiment, which will not be repeated here.

[0084] The class generation method for the application provided in this embodiment obtains the memory space of the class object index information, creates corresponding product construction parameters and data loading parameters for the class object index information, facilitates the subsequent construction of the class object compilation product according to the product construction parameters, and loads the compilation parameters required for the class object index information according to the data loading parameters, so that even in the case of compilation failure, unavailable compilation products, or no compilation products, a class search optimization effect similar to that with compilation products can still be achieved.

[0085] In this embodiment, a method for generating a class of an application is provided, which can be used in computer devices such as computers, tablet computers, mobile phones, etc. Figure 4 is a flow chart of a method for generating a class of an application according to an embodiment of the present invention. Figure 4 As shown, the process includes the following steps:

[0086] Step S401: Obtain compilation information generated for the application program. Please refer to the description of the corresponding steps in the above embodiment for details, which will not be repeated here.

[0087] Step S402: If the target compilation product is missing from the compilation information, class object index information and product information corresponding to the class object index information are created. For details, please refer to the description of the corresponding steps in the above embodiment, which will not be repeated here.

[0088] Step S403: load the target data corresponding to the product information, associate the target data with the class object index information, and obtain the target class object.

[0089] Specifically, the above step S403 includes:

[0090] Step S4031: Check whether there is target data corresponding to the product information in the cache.

[0091] For previously created class objects, their product information can be stored in a cache, allowing for quick retrieval of the corresponding class object compilation product directly from the cache. When the target data corresponding to the product information needs to be loaded, the cache is first checked to see if the target data exists. If the target data corresponding to the product information does not exist in the cache, step S4032 is executed; otherwise, step S4035 is executed.

[0092] Step S4032: If the target data corresponding to the product information does not exist in the cache, the product information is parsed to determine the class identifier and class definition information of the class object.

[0093] The class identifier is an identifier used to indicate the uniqueness of a class object. For example, different class objects have different class names, and the class name can be used as the class identifier of the class object. The class definition information represents the definition information for the class object. Specifically, the class definition information ClassDef includes the definition of classes related to ClassDef optimization based on the Android system principle. For example, the entry function ClassDefOpt#OptClassLoader is used to pass in the class loader ClassLoader to execute subsequent actions; the conversion function ClassDefOpt#ConvertJavaArrayToDexFiles is used to convert the Java DexFile cookie to the native Native DexFile; initialization setting function ClassDefOpt#InitAndSetTypeLookupTable, used to initialize the class lookup table TypeLookupTable corresponding to the class object DexFile and set it to the corresponding class object DexFile; memory loading function ClassDefOpt#ReadTypeLookupTableFromMemory, used to load the class lookup table TypeLookupTable through memory; cache loading function ClassDefOpt#ReadTypeLookupTableFromDisk, used to load the class lookup table TypeLookupTable through disk cache; raw data writing function ClassDefOpt#WriteTypeLookupTableToDisk, used to write the raw data of TypeLookupTable#entries to the disk cache; class setting function ClassDefOpt#SetTypeLookupTable, used to set the currently generated class lookup table TypeLookupTable to the class object DexFile.

[0094] If it is determined that the target data corresponding to the product information does not exist in the cache, the product information is parsed to determine the class identifier and class definition information required to load the target data of each parameter corresponding to the product information.

[0095] Step S4033: Map the class identifier and the class definition information to generate a class mapping structure.

[0096] The class mapping structure represents the mapping relationship between a class identifier and its class definition information, ClassDef. After determining the class identifier (e.g., class name) and class definition information, a preset association algorithm (e.g., hash algorithm) is used to establish an association relationship between the class identifier and the class definition information. The class identifier and class definition information corresponding to the class object DexFile are mapped to form a corresponding class mapping structure (Map structure), which is then stored in the class lookup table TypeLookupTable.

[0097] Step S4034: Load target data required by the class mapping structure from the memory.

[0098] The original data related to the class mapping structure is called from the content (the original data is the target data required by the class mapping structure), and the corresponding data loading function is used to load the original data. At this point, the loading of the target data required by the class mapping structure is completed, and the construction of the class lookup table TypeLookupTable and the filling of target data are realized.

[0099] Step S4035: If the target data corresponding to the product information exists in the cache, the target data corresponding to the product information is directly read from the cache.

[0100] If the target data corresponding to the product information exists in the cache, the target data can be read from the disk into the cache in a preset format (such as uint8_t format), and the class opening method TypeLookupTableOpen method is used to complete the loading of the target data. It should be noted that in addition to the cached data, it is also necessary to additionally pass in the pointer to the beginning of the data in the dex file (including all data in the dex file, such as class definitions, fields, methods, annotations, etc.) and the size of the pointer array pointing to the ClassDef structure to determine the starting address and ending address of the ClassDef structure in the dex file.

[0101] Step S4036: Associating the target data with the class object index information to obtain the target class object.

[0102] Through the class lookup setting method SetTypeLookupTable, the target data generated through the memory or the target data directly read from the cache is set to the corresponding class object index information, so as to realize the association between the target data and the class object index information and obtain the target class object created for the target compilation product.

[0103] In some optional implementations, after loading the target data required by the class mapping structure from the memory, the method further includes: writing the object compilation parameters and the corresponding target data into the target cache.

[0104] The data length acquisition method TypeLookupTableRawDataLength is used to obtain the data volume of the product information and its corresponding target data, and the corresponding storage space is allocated for the product information and its corresponding target data. Then, the value of the class object data TypeLookupTable#entries is used to take the product information and its corresponding target data as the original data and write them into the target cache in a preset format (such as uint8_t) and the class object writing method WriteTypeLookupTableToDisk, which corresponds to reading the original data when loading from the cache.

[0105] In the above implementation, by writing the product information and the target data generated in the memory into the target cache, the subsequent loss caused by data generation is reduced and the data search efficiency is improved.

[0106] Step S404: controlling the target class object to take effect and generating a target compilation product corresponding to the target class object.

[0107] Specifically, the above step S404 includes:

[0108] Step S4041: determining a triggering timing for the target class object based on the object parameters of the target class object.

[0109] Object parameters are variable parameters carried by the target class object. These object parameters are stored in a cookie file. By reading the loaded target class object's cookie file, the required object parameters of the target class object are extracted from the cookie file. The triggering time is when the Android system application reads the corresponding information of the target class object.

[0110] Specifically, for the currently generated target class object, the class loading trigger component ClassLoader corresponding to the target class object is obtained, and the trigger timing for creating the target class object is determined by the class loading trigger component ClassLoader. That is, the entry method ClassDefOpt::OptClassLoader of the target class object is triggered by the class loading component ClassLoader, and the cookie variable (which stores the address of the Native DexFile) held in the Java DexFile in the loaded class loading component ClassLoader is read, as well as the parameter cache_dir of the storage directory where various object parameters are cached.

[0111] Step S4042: Acquire the native class object corresponding to the target class object.

[0112] When the triggering time is reached, the cookie variable of the target class object is converted into the class object file set dex_files corresponding to the native class object Native DexFile through the class conversion method ConvertJavaArrayToDexFiles.

[0113] Step S4043 : Load the parameter information of the target class object into the native class object according to the triggering timing, run the native class object, and generate the target compilation product.

[0114] The parameter information of the target class object represents the main information required to load the target class object. The class object file set dex_files corresponding to the native class object Native DexFile is traversed to search for the class definition information ClassDef. If the class definition information corresponding to the class exists, it indicates that the class exists in the current class object DexFile. At this time, the class loading process is executed, calling the class compilation method InitAndSetTypeLookupTable to complete data generation, data caching, and data loading for the class object DexFile, and obtain the corresponding parameter information.

[0115] Specifically, in the class compilation method InitAndSetTypeLookupTable, first determine whether the setting from the dex file to the oat file is non-empty to prevent repeated settings; then, load the target data from the cache through the cache generation method ReadTypeLookupTableFromDisk. If the load is successful, continue; otherwise, load the target data through the memory generation method ReadTypeLookupTableFromMemory, and load the parameter information of the target class object into the corresponding native class object through the class setting method SetTypeLookupTable. Then, run the native class object with the loaded parameter information, and control the effectiveness of the target class object by running the native class object to generate the corresponding target compilation product.

[0116] The class generation method for an application provided in this embodiment detects whether the target data corresponding to the product information exists in the cache. If so, it is directly loaded from the cache, reducing the time required to generate the target data and facilitating improved operational efficiency. If not, the target data is generated in memory and the class mapping structure of the target data is stored in the target cache, facilitating subsequent direct reading and loading, thereby reducing the time required to generate the same target data. By creating a triggering opportunity for the target class object, the acquisition of the parameter information of the target class object is automatically triggered when the triggering opportunity is reached, thereby completing the class loading of the target compilation product using the parameter information of the target class object. For Android system application optimization, this achieves an effect similar to the existence of a compilation product, thereby greatly improving the optimized operational efficiency of the application.

[0117] As a specific application embodiment of an embodiment of the present invention, in the process of developing an application for the Android system, when compilation fails, compilation products are unavailable, or there are no compilation products, the following method can be used to achieve a class search optimization effect similar to that with compilation products. Specifically, the class object is first initialized, including obtaining the class object size (used to apply for memory for the relevant data memory structure and reset it to zero), obtaining the relevant class object constructor and skipping the environment check (used to generate an object instance of the relevant memory data structure), obtaining the function for generating and loading memory data, and obtaining the relevant function loaded from the original data in the memory. Then load the target data required for the class object index information. If there is no cache, generate and load the relevant data from the memory; if there is a cache, read the cached data into the memory to obtain the original data, and then call the relevant function loaded from the original data in the memory for loading. Set the generated data to the corresponding class object to make the class object effective. Thus, when searching for the compilation product, the class search optimization effect of the compilation product can be achieved based on the currently effective class object.

[0118] Specifically, for class search, it is necessary to follow the parent delegation principle and select the ClassLoader to start the class search according to the ClassLoader link; then, convert the Java DexFile of the current ClassLoader to the Native DexFile; traverse the DexFile and search for the ClassDef corresponding to the class at the same time. This is similar to the index of the class, which can indicate whether the class exists in the current DexFile and can also be used as an index to provide key information for loading the class. If the ClassDef of the corresponding class is found, it means that the class exists in the current DexFile, and the class loading process will begin. Otherwise, continue to the next DexFile. If the corresponding ClassDef is still not found after traversing all DexFiles, exit the current search and continue to select the next class to be searched according to the parent delegation principle.

[0119] The main impact of the above-mentioned validation process lies in the process of finding the ClassDef corresponding to the class based on the class object DexFile. Before the class object takes effect, the corresponding TypeId is obtained according to the class name (descriptor) by using the DexFile#FindTypeId method (DexFile obtains an array of all loaded TypeIds, and then obtains the corresponding TypeId through binary search). Then, the corresponding TypeIndex is obtained through DexFile#GetIndexForTypeId (the index in the array is obtained by subtracting the difference between the address of the value in the array and the first address of the array, and then the TypeIndex is constructed (the input parameter is the index) and returned). Finally, the corresponding ClassDef is obtained through DexFile#FindClassDef (DexFile obtains an array of all loaded ClassDefs, and then traverses and compares ClassDef#class_idx to the return value of the current TypeIndex). The time complexity of this search process is: the former is a binary search with a time complexity of O(logn), and the latter is a traversal search, so its time complexity is O(n).

[0120] After the creation of the class object takes effect, the OatDexFile is obtained through the class object DexFile, and then the TypeLookupTable is obtained through the OatDexFile. The class name (descriptor) and the hash of the class name are passed in through the TypeLookupTable#lookup method to obtain the corresponding class_def_idx (the relationship between the class name (descriptor) and the class_def_idx is stored in the TypeLookupTable in a hash manner, and the corresponding value can be found through hash search). Then, the corresponding ClassDef is obtained through DexFile#GetClassDef (class_def_idx is the index value of the corresponding ClassDef in the array of all ClassDefs loaded in the class object DexFile, so the corresponding ClassDef can be obtained directly by reading the value of the array). The time complexity of this search process is: the former is a hash search, and its time complexity is O(1), and the latter is a random access when the index array is known, and its time complexity is also O(1).

[0121] This embodiment also provides a device for generating a class for an application program, which is used to implement the above-mentioned embodiments and preferred implementations. Details already described will not be repeated here. As used below, the term "module" may refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation using hardware, or a combination of software and hardware, is also possible and contemplated.

[0122] This embodiment provides a class generation device for an application program, such as Figure 5 Shown, including:

[0123] The compilation information acquisition module 501 is used to obtain compilation information generated for the application.

[0124] The class object parameter acquisition module 502 is configured to create class object index information and product information corresponding to the class object index information if the target compilation product is missing from the compilation information.

[0125] The loading module 503 is used to load the target data corresponding to the product information, associate the target data with the class object index information, and obtain the target class object.

[0126] The validation control module 504 is used to control the validation of the target class object and generate a target compilation product corresponding to the target class object.

[0127] In some optional implementations, the class object parameter acquisition module 502 includes:

[0128] The memory acquisition unit is used to obtain the memory space corresponding to the class object index information.

[0129] The parameter determination unit is used to trigger a creation operation for the class object index information and determine product construction parameters and data loading parameters corresponding to the creation operation.

[0130] In some optional implementations, the memory acquisition unit includes:

[0131] The anchor point acquisition subunit is used to obtain memory space in an anchor point manner when the creation of index information for a class object is triggered.

[0132] The instruction analysis subunit is used to analyze the key instructions corresponding to the class object index information and determine the target location of the key instructions.

[0133] The memory determination subunit is used to determine the parameter value corresponding to the target position as a memory space.

[0134] In some optional implementations, the parameter determination unit includes:

[0135] The method acquisition subunit is used to obtain the class generation method, class opening method, data length acquisition method and class compilation method corresponding to the creation operation.

[0136] The first initialization subunit is used to initialize the class object generation method and obtain product construction parameters corresponding to the class object index information.

[0137] The second initialization subunit is used to initialize the class opening method, the data length acquisition method and the class compilation method to obtain the data loading parameters corresponding to the class object index information.

[0138] In some optional embodiments, the above device further includes:

[0139] The creation start unit is used to obtain the creation start position of the creation operation for the class object index information.

[0140] The traversal unit is used to traverse the creation instructions corresponding to the component operation from the creation starting position, and determine whether the currently traversed creation instruction is an environment verification instruction.

[0141] The instruction adjustment unit is used to adjust the environment check instruction to a target instruction if it is determined that the currently traversed creation instruction is an environment check instruction, and the target instruction is used to instruct to skip the environment check.

[0142] In some optional implementations, the loading module 503 includes:

[0143] The detection unit is used to detect whether target data corresponding to the product information exists in the cache.

[0144] The parameter parsing unit is used to parse the product information and determine the class identifier and class definition information of the class object if the target data corresponding to the product information does not exist in the cache.

[0145] The mapping unit is used to map the class identifier and the class definition information to generate a class mapping structure.

[0146] The memory loading unit is used to load the target data required by the class mapping structure from the memory.

[0147] The association unit is used to associate the target data with the class object index information to obtain the target class object.

[0148] In some optional implementations, the loading module 503 further includes:

[0149] The cache loading unit is used to directly read the target data corresponding to the product information from the cache if the target data corresponding to the product information exists in the cache.

[0150] In some optional embodiments, the above device further includes:

[0151] The data writing module is used to write the object compilation parameters and their corresponding target data into the target cache.

[0152] In some optional implementations, the validation control module 504 includes:

[0153] The trigger timing determination unit is used to determine the trigger timing for the target class object based on the object parameters of the target class object.

[0154] The native class object determining unit is used to obtain the native class object corresponding to the target class object.

[0155] The compilation unit is used to load the parameter information of the target class object into the native class object according to the trigger timing, run the native class object, and generate the target compilation product.

[0156] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.

[0157] The class generation device for an application provided by the embodiment of the present disclosure can execute the class generation method for an application provided by any embodiment of the present disclosure, and has functional modules and beneficial effects corresponding to the execution method. In the case where the target compilation product is missing in the compilation information, by creating corresponding class object index information and its corresponding product information, and loading corresponding target data according to the product information, the target data is associated with the class object index information to obtain the target class object. Then, by controlling the target class object to take effect, the corresponding target compilation product can be generated according to the target class object. Thus, the target class object can be used to quickly find the target compilation product, achieving an effect similar to the existence of the compilation product. Then, the operation of the Android system application can be accelerated according to the generated target compilation product, thereby improving the operation efficiency of the Android system application.

[0158] Figure 6 A schematic structural diagram of an electronic device provided in an embodiment of the present disclosure.

[0159] The following specific reference Figure 6 , which shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present disclosure. The electronic device may include a processor (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a memory 608 into a random access memory (RAM) 603. Various programs and data required for the operation of the electronic device are also stored in the RAM 603. The processor 601, ROM 602, and RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0160] Typically, the following devices may be connected to the I / O interface 605: an input device 606 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a memory 608 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 609. The communication device 609 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although Figure 6 An electronic device having various devices is shown, but it should be understood that it is not required to implement or possess all of the devices shown, and more or fewer devices may be implemented or possessed instead.

[0161] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 609, or installed from the memory 608, or installed from the ROM 602. When the computer program is executed by the processor 601, the above-mentioned functions defined in the class generation method of the application of the embodiment of the present disclosure are executed.

[0162] Figure 6 The electronic device shown is only an example and should not limit the functions and scope of use of the embodiments of the present disclosure.

[0163] The embodiment of the present invention also provides a computer-readable storage medium. The above-mentioned method according to the embodiment of the present invention can be implemented in hardware, firmware, or implemented as a computer code that can be recorded in a storage medium, or implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and downloaded through a network and will be stored in a local storage medium, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state drive, etc.; further, the storage medium can also include a combination of the above-mentioned types of memory. It can be understood that a computer, a processor, a microprocessor controller or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor or hardware, the class generation method of the application shown in the above embodiment is implemented.

[0164] A portion of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the form in which the computer program instruction exists in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc. Accordingly, the way in which the computer program instruction is executed by the computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable storage medium or communication medium that can be accessed by the computer.

[0165] Although the embodiments of the present invention have been described with reference to the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention. Such modifications and variations are all within the scope defined by the appended claims.

Claims

1. A method for generating a class of an application, characterized in that: The method comprises: Get the compilation information generated for the application; If the target compilation product is missing from the compilation information, creating class object index information and product information corresponding to the class object index information; Loading target data corresponding to the product information, associating the target data with the class object index information to obtain a target class object; The target class object is controlled to take effect, and a target compilation product corresponding to the target class object is generated.

2. The method according to claim 1, characterized in that Create product information corresponding to the class object index information, including: Obtaining the memory space corresponding to the class object index information; Triggering a creation operation for the class object index information, and determining product construction parameters and data loading parameters corresponding to the creation operation; The product information includes the memory space, the product construction parameters and the data loading parameters.

3. The method according to claim 2, characterized in that The triggering of the creation operation for the class object index information and determining the product construction parameters and data loading parameters corresponding to the creation operation include: Obtain the class generation method, class opening method, data length acquisition method, and class compilation method corresponding to the creation operation; Initialize the class generation method to obtain product construction parameters corresponding to the class object index information; The class opening method, the data length obtaining method and the class compiling method are initialized to obtain data loading parameters corresponding to the class object index information.

4. The method according to claim 2 or 3, characterized in that Also includes: Obtaining a starting position of the creation operation for the class object index information; Traversing the creation instruction corresponding to the creation operation from the starting position, and determining whether the creation instruction currently traversed is an environment verification instruction; If it is determined that the creation instruction currently traversed is the environment check instruction, the environment check instruction is adjusted to a target instruction, and the target instruction is used to instruct to skip the environment check.

5. The method according to claim 2, characterized in that The obtaining of the memory space corresponding to the class object index information includes: When the creation of the index information for the class object is triggered, the memory space is obtained by using an anchor point method; and / or, Analyze the key instructions corresponding to the class object index information to determine the target location of the key instructions; The parameter value corresponding to the target position is determined as the memory space.

6. The method according to claim 1, characterized in that The loading of target data corresponding to the product information includes: Detecting whether target data corresponding to the product information exists in the cache; If the target data corresponding to the product information does not exist in the cache, parsing the product information to determine the class identifier and class definition information; Mapping the class identifier and the class definition information to generate a class mapping structure; The target data required by the class map structure is loaded from memory.

7. The method according to claim 6, characterized in that After loading the target data required by the class mapping structure from the memory, it also includes: The product information and the corresponding target data are written into the target cache.

8. The method according to claim 6, characterized in that The loading of target data corresponding to the product information further includes: If the target data corresponding to the product information exists in the cache, the target data corresponding to the product information is directly read from the cache.

9. The method according to claim 1, characterized in that The controlling the target class object to take effect and generating a target compilation product corresponding to the target class object includes: Determining a triggering timing for the target class object based on the object parameters of the target class object; Obtain the native class object corresponding to the target class object; The parameter information of the target class object is loaded into the native class object according to the triggering timing, and the native class object is run to generate the target compilation product.

10. A class generation device for an application, characterized in that: The device comprises: A compilation information acquisition module is used to obtain compilation information generated for an application; a class object parameter acquisition module, configured to create class object index information and product information corresponding to the class object index information if the target compilation product is missing from the compilation information; A loading module, configured to load target data corresponding to the product information, associate the target data with the class object index information, and obtain a target class object; The validation control module is used to control the validation of the target class object and generate a target compilation product corresponding to the target class object.

11. An electronic device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the class generation method of the application according to any one of claims 1 to 9 by executing the computer instructions.

12. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the application class generation method according to any one of claims 1 to 9.

13. A computer program product, characterized in that The invention comprises computer instructions for causing a computer to execute the class generation method for an application program according to any one of claims 1 to 9.