Compilation running method and electronic equipment
By obtaining the layout information of each object during the historical operation of dynamic language code and optimizing it at compile time, the problem of low object attribute access in dynamic language programs is solved, and more efficient attribute access and performance improvement is achieved.
Patent Information
- Application Number
- CN202311626457.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-28
- Publication Date
- 2025-05-30
AI Technical Summary
Dynamic language programs have low attribute access efficiency due to flexibility when accessing object properties.
By obtaining the layout information of each object during the dynamic language code history, determining the offset of the attributes used by the attribute usage point, and optimizing it at compile time to generate assembly code, and directly obtaining the attribute value in memory.
It improves the access efficiency of object attributes during the run of a dynamic language program, and optimizes it before compiling and generating assembly code, avoiding the impact of runtime compilation on performance.
Smart Images

Figure CN120066514A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular, to a compilation and execution method and an electronic device. Background Art
[0002] Dynamic languages do not have very strict requirements for the types of variables. The code is concise and flexible, and has obvious advantages in rapid development and deployment. Therefore, developers have started to use dynamic languages in more fields.
[0003] When running a dynamic language program, it is often necessary to access the attributes of objects in the code. However, due to the flexibility of dynamic languages, it is usually difficult to directly obtain the attribute information of objects when accessing the attributes of objects, resulting in low access efficiency of the attributes of objects when the dynamic language program is running. Summary of the Invention
[0004] In view of this, this application provides a compilation and execution method and an electronic device to improve the access efficiency of the attributes of objects during the running of a dynamic language program.
[0005] To achieve the above object, in a first aspect, an embodiment of this application provides a compilation and execution method, including:
[0006] Obtain the layout information of each object during the historical execution of the dynamic language code;
[0007] Determine the offset of the attribute used at the attribute usage point of each object in the dynamic language code according to the layout information;
[0008] Compile and optimize the dynamic language code according to the layout information and each offset to generate corresponding assembly code;
[0009] Run the assembly code.
[0010] For the compilation and execution method provided by the embodiment of this application, first, obtain the layout information of each object during the historical execution of the dynamic language code, and use the historical layout information of each object as the current layout information of each object. In this way, according to the historical layout information of each object, the offset of the attribute used at the attribute usage point of each object in the current dynamic language code can be determined. Therefore, when compiling the dynamic language code to generate assembly code, the attributes used at the attribute usage points of each object in the assembly code can be replaced with the corresponding offsets. In this way, when running the assembly code, the values of the corresponding attributes can be directly obtained from the memory according to each offset, without an intermediate search link, thereby improving the access efficiency of the attributes of objects during the running of the dynamic language program; moreover, since the process of compiling and generating assembly code is performed before the dynamic language program runs, compared with just-in-time compilation, it does not occupy runtime resources, thereby improving the running performance of the dynamic language program.
[0011] In a possible implementation of the first aspect, before running the assembly code, the method further includes:
[0012] Serializing the layout information of each object to obtain a byte stream;
[0013] The running of the assembly code includes:
[0014] Deserializing the byte stream to obtain the layout information of each object;
[0015] Running the assembly code, and when the first attribute in the assembly code is a newly added attribute during the historical running of the assembly code, determining the layout information of the first attribute according to the position information of the first attribute in the assembly code and the layout information of each object.
[0016] Through the above implementation, the layout information of each object during the historical running of the dynamic language code can be stored in a serialized manner, and during the running period, the layout information of each object can be obtained through deserialization. In this way, if there are newly added attributes during the historical running of the dynamic language code, the layout information of the newly added attributes can be directly obtained through the stored layout information of each object during the subsequent running of the dynamic language code, thereby reducing the overhead of creating the layout of the newly added attributes during the subsequent running period.
[0017] In a possible implementation of the first aspect, the serializing the layout information of each object includes:
[0018] Based on the snapshot function, serializing the layout information of each object. In this way, when the serialized layout information of each object is damaged or lost, it can be quickly restored through the snapshot, improving the stability of the dynamic language program during runtime.
[0019] In a possible implementation of the first aspect, the serializing the layout information of each object to obtain a byte stream includes:
[0020] Determining a first map according to the layout information of each object and first position information, where the first position information includes the position information of the creation points of the attributes of each object, and the first map records the first position information and the layout information of the attributes corresponding to the first information;
[0021] Serializing the first map to obtain the byte stream.
[0022] Through the first map, the layout information of each attribute is associated with the position information of its creation point. In this way, during runtime, first, based on the position information of the usage point of each attribute, the position information of the creation point of this attribute can be determined. Then, based on the position information of the creation point of this attribute, the layout information of this attribute can be obtained from the first map. Naturally, it is also possible to directly obtain the layout information of the newly added attribute during runtime.
[0023] In a possible implementation manner of the first aspect, for any object, the layout information indicates: the first hidden class generated when creating the object, the second hidden class generated each time an attribute is added to the object, the conversion tree, and the target second hidden class. The target second hidden class is the second hidden class corresponding to the attribute used when using the attribute of the object. The conversion tree is used to indicate the reference relationships between the first hidden class and each of the second hidden classes, and between each of the second hidden classes.
[0024] Through the above implementation manner, it is possible to achieve fast access and storage of layout information in the form of hidden classes and conversion trees.
[0025] In a possible implementation manner of the first aspect, determining the offsets of the attributes used at the attribute usage points of each object in the dynamic language code according to the layout information includes:
[0026] Obtain the position information of the creation points of each object in the dynamic language code;
[0027] According to the position information corresponding to each object, the first hidden class, the second hidden class, and the conversion tree, determine object mapping information, where the object mapping information indicates the position information of the creation point of each object and the offsets of the corresponding attributes;
[0028] According to the object mapping information and the target second hidden classes corresponding to each object, determine the offsets of the attributes used at the attribute usage points of each object in the dynamic language code.
[0029] Through the above implementation manner, the position information of the creation point of each object is associated with the offsets of the corresponding attributes. In this way, after determining the position information of the creation point of the object to which the attribute belongs according to the target second hidden class corresponding to the attribute used at the attribute usage point of each object in the dynamic language code, the offset of this attribute can be further determined in the object mapping information for subsequent use during compilation.
[0030] In a possible implementation of the first aspect, the object mapping information includes a second map and a third map. The position information of the creation point of each object and the corresponding third map are recorded in the second map. The attribute name of each attribute of the object and the corresponding offset are recorded in the third map corresponding to the position information of the creation point of each object.
[0031] Through the above implementation, the double map is used to associate the position information of the creation point of each object with the attribute information of the object, so as to ensure the uniqueness of the attribute information of each object.
[0032] In a possible implementation of the first aspect, for the second attribute in the dynamic language code, if the position information of the creation point of the object to which the second attribute belongs is the same as the position information of the creation point of the object corresponding to the target third map, and the attribute name of the second attribute is the same as the attribute name of the third attribute in the target third map, then the offset of the second attribute is the same as the offset of the third attribute in the target third map. The second attribute is any attribute in the dynamic language code, and the attribute name of the second attribute and the position information of the creation point of the object to which it belongs are determined according to the target second hidden class corresponding to the second attribute.
[0033] Through the above implementation, the unique corresponding offset can be determined in the double map according to the attribute name of each attribute in the dynamic language code and the position information of the creation point of the object to which it belongs.
[0034] In a possible implementation of the first aspect, for any object, the layout information includes: the first hidden class, the difference information of each second hidden class relative to the referenced hidden class, the conversion tree, and the target second hidden class.
[0035] Through the above implementation, the layout information only saves the difference information of each second hidden class relative to the referenced hidden class, so as to avoid repeated acquisition and saving of the same information in each second hidden class, and reduce the overhead when saving the layout information.
[0036] In a possible implementation of the first aspect, each node in the conversion tree only records the difference information of the corresponding second hidden class relative to the referenced hidden class. Thus, when obtaining the information recorded in each second hidden class, the information recorded in each node in the conversion tree can be directly obtained. This can not only reduce the overhead when saving the conversion tree, but also avoid repeated acquisition and saving of the same information in each second hidden class, and reduce the overhead when saving the layout information.
[0037] In a possible implementation of the first aspect, for the target information in the dynamic language code, the location information of the creation point of the target information includes: the creation instruction of the target information, the function where the creation instruction is located, and the storage path and file name of the file to which the function belongs, where the target information is any object or any attribute in the dynamic language code.
[0038] Through the above implementation, the location information of the creation point of any object or any attribute in the dynamic language code can be made unique.
[0039] In a possible implementation of the first aspect, for any object in the dynamic language code, the location information of the creation point of the object includes: the storage path and file name of the file that creates the object, and the offset of the object relative to the file.
[0040] Through the above implementation, the location information of the creation point of any object in the dynamic language code can be made unique.
[0041] In a possible implementation of the first aspect, the historical running period is the most recent running period of the dynamic language code.
[0042] Through the above implementation, the layout information of each object in the dynamic language code during the most recent running period is used as the current layout information of each object, so as to reduce the probability that the current layout of each object in the dynamic language code changes relative to the layout of each object during the historical running period.
[0043] In a possible implementation of the first aspect, the obtaining of the layout information of each object during the running of the dynamic language code includes:
[0044] Based on the PGO sampling method, obtain the layout information of each object during the running of the dynamic language code.
[0045] In a possible implementation of the first aspect, the dynamic language is one of Php, Asp, JavaScript, Python, Perl.
[0046] Through the above implementation, this solution can be applied to multiple dynamic language programs, expanding the application scope of this solution.
[0047] In a second aspect, an embodiment of the present application provides a compilation and running device, and the compilation and running device includes:
[0048] An acquisition module: used to acquire the layout information of each object during the historical running period of the dynamic language code;
[0049] Determination module: used to determine the offset of the attributes used at the attribute usage points of each object in the dynamic language code according to the layout information;
[0050] Compilation optimization module: used to perform compilation optimization on the dynamic language code according to the layout information and each offset, and generate corresponding assembly code;
[0051] Running module: used to run the assembly code.
[0052] In a possible implementation manner of the second aspect, before running the assembly code, the compilation and running device further includes a serialization module: used to serialize the layout information of each object to obtain a byte stream;
[0053] The compilation and running device further includes a deserialization module: used to deserialize the byte stream to obtain the layout information of each object;
[0054] The running module is specifically used for: running the assembly code, and when the first attribute in the assembly code is a newly added attribute during the historical running of the assembly code, determining the layout information of the first attribute according to the position information of the first attribute in the assembly code and the layout information of each object.
[0055] In a possible implementation manner of the second aspect, the serialization module is specifically used for:
[0056] Based on the snapshot function, serialize the layout information of each object.
[0057] In a possible implementation manner of the second aspect, the serialization module is specifically used for:
[0058] According to the layout information of each object and the first position information, determine a first map, where the first position information includes the position information of the creation points of the attributes of each object, and the first map records the first position information and the layout information of the attributes corresponding to the first information;
[0059] Serialize the first map to obtain the byte stream.
[0060] In a possible implementation manner of the second aspect, for any object, the layout information indicates: a first hidden class generated when creating the object, a second hidden class generated each time an attribute is added to the object, a conversion tree, and a target second hidden class, where the target second hidden class is the second hidden class corresponding to the attribute used when using the attribute of the object, and the conversion tree is used to indicate the reference relationship between the first hidden class and each second hidden class, and between each second hidden class.
[0061] In a possible implementation of the second aspect, the determining module is specifically configured to:
[0062] Obtain the position information of the creation points of each object in the dynamic language code;
[0063] Determine object mapping information according to the position information corresponding to each object, the first hidden class, the second hidden class, and the conversion tree, where the object mapping information indicates the position information of the creation point of each object and the offset of each corresponding attribute;
[0064] Determine the offset of the attribute used at each attribute usage point in the dynamic language code according to the object mapping information and the target second hidden class corresponding to each object.
[0065] In a possible implementation of the second aspect, the object mapping information includes a second map and a third map. The second map records the position information of the creation point of each object and the corresponding third map. The third map corresponding to the position information of the creation point of each object records the attribute name of each attribute of the object and the corresponding offset.
[0066] In a possible implementation of the second aspect, for the second attribute in the dynamic language code, if the position information of the creation point of the object to which the second attribute belongs is the same as the position information of the creation point of the object corresponding to the target third map, and the attribute name of the second attribute is the same as the attribute name of the third attribute in the target third map, then the offset of the second attribute is the same as the offset of the third attribute in the target third map. The second attribute is any attribute in the dynamic language code, and the attribute name of the second attribute and the position information of the creation point of the object to which it belongs are determined according to the target second hidden class corresponding to the second attribute.
[0067] In a possible implementation of the second aspect, for any object, the layout information includes: the first hidden class, the difference information of each second hidden class relative to the referenced hidden class, the conversion tree, and the target second hidden class.
[0068] In a possible implementation of the second aspect, each node in the conversion tree only records the difference information of the corresponding second hidden class relative to the referenced hidden class.
[0069] In a possible implementation of the second aspect, for the target information in the dynamic language code, the position information of the creation point of the target information includes: the creation instruction of the target information, the function where the creation instruction is located, and the storage path and file name of the file to which the function belongs. The target information is any object or any attribute in the dynamic language code.
[0070] In a possible implementation of the second aspect, for any object in the dynamic language code, the location information of the creation point of the object includes: the storage path and file name of the file where the object is created, and the offset of the object relative to the file.
[0071] In a possible implementation of the second aspect, the historical running period is the most recent running period of the dynamic language code.
[0072] In a possible implementation of the second aspect, the obtaining module is specifically configured to:
[0073] Based on the PGO sampling method, obtain the layout information of each object during the running of the dynamic language code.
[0074] In a possible implementation of the second aspect, the dynamic language is one of Php, Asp, JavaScript, Python, Perl.
[0075] In a third aspect, an embodiment of the present application provides an electronic device, including: a memory and a processor, the memory is used to store a computer program; the processor is used to execute the method described in the above first aspect or any implementation manner of the first aspect when calling the computer program.
[0076] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the method described in the above first aspect or any implementation manner of the first aspect is implemented.
[0077] In a fifth aspect, an embodiment of the present application provides a computer program product, when the computer program product runs on an electronic device, the electronic device is enabled to execute the method described in the above first aspect or any implementation manner of the first aspect.
[0078] In a sixth aspect, an embodiment of the present application provides a chip system, including a processor, the processor is coupled to a memory, and the processor executes a computer program stored in the memory to implement the method described in the above first aspect or any implementation manner of the first aspect. Wherein, the chip system can be a single chip or a chip module composed of multiple chips.
[0079] It can be understood that the beneficial effects of the above second aspect to sixth aspect can refer to the relevant descriptions in the above first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0080] Figure 1 It is a schematic flowchart of the compilation and running method provided by the embodiment of the present application;
[0081] Figure 2 Schematic diagram of any object and its attributes provided by the embodiments of the present application and the corresponding hidden class and transition tree;
[0082] Figure 3 Schematic diagram of another transition tree provided by the embodiments of the present application;
[0083] Figure 4 Schematic diagram of yet another transition tree provided by the embodiments of the present application;
[0084] Figure 5 Schematic diagram of the relationship between the object layout information and the double map structure provided by the embodiments of the present application;
[0085] Figure 6 Schematic diagram of the inner map in the double map structure provided by the embodiments of the present application;
[0086] Figure 7 Schematic diagram of the software architecture of the electronic device provided by the embodiments of the present application;
[0087] Figure 8 Schematic diagram of the structure of the compilation and running device provided by the embodiments of the present application;
[0088] Figure 9 Schematic diagram of the structure of the electronic device provided by the embodiments of the present application. Detailed implementation manners
[0089] The embodiments of the present application will be described below with reference to the accompanying drawings in the embodiments of the present application. The terms used in the implementation manner part of the embodiments of the present application are only used to explain the specific embodiments of the present application, rather than aiming to limit the present application. These several specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments.
[0090] The code of dynamic languages is concise and flexible, and the attributes of objects in the code can be added and deleted dynamically, which means that the attributes of objects in dynamic languages are variable.
[0091] When running a dynamic language program, it is often necessary to access the object attributes of the dynamic language code in the program. However, due to the flexibility of dynamic languages, when accessing the attributes of an object, it is usually necessary to determine its type through cumbersome type judgments and search for relevant attributes in the corresponding object layout, resulting in low efficiency of accessing object attributes during the running of dynamic language programs.
[0092] To improve the efficiency of accessing object properties during the execution of a dynamic language program, the Just-in-time compilation (JIT) technique can be used to optimize property access operations during the execution of the dynamic language program. Specifically, during the execution of the dynamic language program, the type information of the properties of each object in the dynamic language code can be obtained first, and then, based on the obtained type information, the hot functions can be optimized and the corresponding assembly code can be generated. Finally, the generated assembly code is executed.
[0093] Although the above method can improve the efficiency of accessing object properties during the execution of a dynamic language program, since the compilation process of the dynamic language code exists during the program execution, this will also affect the running performance of the dynamic language program.
[0094] Therefore, this application provides a compilation and execution method to improve the efficiency of accessing object properties and the running performance of the dynamic language program during the execution of the dynamic language program.
[0095] The compilation and execution method provided in this application can be applied to electronic devices including dynamic language programs, such as personal computers (PCs), smartphones, netbooks, tablet computers, personal digital assistants, etc. In the embodiments of this application, a mobile phone is taken as an example of the electronic device for illustrative purposes.
[0096] Dynamic languages can be Php, Asp, JavaScript, Python, Perl, etc. For the convenience of description, in the embodiments of this application, JavaScript is taken as an example of the dynamic language for illustrative purposes.
[0097] Figure 1 As shown in Figure 1 the following steps can be included in the compilation and execution method provided in the embodiments of this application:
[0098] S110. Obtain the layout information of each object during the historical execution of the dynamic language code.
[0099] The dynamic language code usually includes multiple objects. In some embodiments, the profile guided optimization (PGO) technique can be used to obtain the layout information of each object during the historical execution of the dynamic language code. In other embodiments, according to the specific architecture of the dynamic language code, other methods can also be used to obtain the layout information of each object during the historical execution of the dynamic language code. In the following embodiments of this application, the PGO technique is taken as an example to obtain the layout information of each object for illustrative purposes.
[0100] All data collected through the PGO technology (including the layout information of each object during the historical operation period) can be saved in the corresponding pgo file. During compilation, a PGO type management object can be stored on the virtual machine. The life cycle of the PGO type management object can span the entire compilation period. The PGO type management object can generate the layout information of each object during the historical operation period of the dynamic language code by reading the corresponding pgo file and use it as the current layout information of each object in the dynamic language code.
[0101] The PGO type management object can obtain the layout information of each object during any historical operation period of the dynamic language code and use it as the current layout information of each object in the dynamic language code.
[0102] Due to the flexibility of the dynamic language, the layout of each object may change during the historical operation period of the dynamic language code. To reduce the current layout of each object in the dynamic language code relative to the probability of change in the layout of each object during the historical operation period of the dynamic language code, the layout information of each object during the most recent operation period of the dynamic language code can also be used as the current layout information of each object in the dynamic language code.
[0103] In some embodiments, a data structure similar to a dictionary can be used to record the layout information of each generated object. In other embodiments, to achieve fast access to the layout information, the layout information of each object can also be recorded in the form of a hidden class. The following embodiments of the present application will take the form of using a hidden class to record the layout information of each object as an example for exemplary illustration.
[0104] For any object in the dynamic language code, its layout information can indicate the first hidden class generated when creating the object, the second hidden class generated each time an attribute is added to the object, the transition tree generated based on the first hidden class and the second hidden class, and the target second hidden class corresponding to the attribute (i.e., the second hidden class generated when adding the attribute) when any attribute of the object is used.
[0105] The first hidden class can be empty. For any object, each time a new property is added to the object, a corresponding second hidden class is generated. Each second hidden class can record all the properties of the object and the offset of each property relative to the object at the current position in the dynamic language code. The transition tree is used to indicate the reference relationships between the first hidden class, the second hidden classes, and between the second hidden classes.
[0106] Exemplarily, as Figure 2 shown, when the dynamic language code is run for the first time, an object a is created by the instruction let a={}, and the corresponding hclass0 is generated. Then, the property x is added to the object a by the instruction a.x=1 to generate hclassx, and the property y is added to the object a by the instruction a.y=2 to generate hclassxy. The corresponding transition tree indicates that hclassxy references hclassx, and hclassx references hclass0. hclass0 can be empty, hclassx can record the offset of x, and hclassxy can record the offsets of x and y.
[0107] For any object in the dynamic language code, the transition tree corresponding to the object will save the reference relationships between the hidden classes corresponding to the object and the properties of the object during each run of the dynamic language code. If the reference relationships between the hidden classes corresponding to the object and the properties of the object change during the run of the dynamic language code, the transition tree corresponding to the object will also change.
[0108] Exemplarily, as Figure 3 shown, when the dynamic language code is run for the second time, an object a is created by the instruction let a={} at the same position in the code. At this time, hclass0 generated when the object a was created in the first run of the dynamic language code is reused. Then, the property y is added to the object a by the instruction a.y=1, and hclassy is correspondingly generated. Then, the property x is added to the object a by the instruction a.x=2, and hclassyx is correspondingly generated. Then, the transition tree corresponding to the object a will generate a new reference branch to indicate that hclassyx references hclassy, and hclassy references hclass0. Among them, hclassy can record the offset of the property y, and hclassyx can record the offsets of the property y and the property x.
[0109] In some embodiments, for any object in dynamic language code, the obtained layout information of the object may include: all the information recorded in the first hidden class and the second hidden class corresponding to the object, the corresponding transition tree, and the target second hidden class corresponding to any attribute when using the attribute of the object.
[0110] In some other embodiments, for any object in dynamic language code, when obtaining the information recorded in each second hidden class corresponding to the object, it is also possible to only obtain the differential information of each second hidden class relative to the referenced first hidden class or second hidden class, so as to avoid repeated acquisition and storage of the same information in each second hidden class and reduce the overhead when storing layout information. For any second hidden class, the corresponding differential information may be the information of the newly added attributes that generate the second hidden class.
[0111] Exemplarily, as Figure 3 shown, in the transition tree corresponding to object a, hclass0 is the first hidden class, and hclassx, hclassxy, hclassy, and hclassyx are all second hidden classes. The differential information of hclassx relative to the referenced hclass0 is the information of attribute x, the differential information of hclassxy relative to the referenced hclassx is the information of attribute y, the differential information of hclassy relative to the referenced hclass0 is the information of attribute y, and the differential information of hclassyx relative to the referenced hclassy is the information of attribute x.
[0112] When obtaining the information recorded in hclassx, the information obtained is the information of attribute x. When obtaining the information recorded in hclassxy, only the information of attribute y is obtained; when obtaining the information recorded in hclassy, the information obtained is the information of attribute y. When obtaining the information recorded in hclassxy, only the information of attribute y is obtained.
[0113] In some embodiments, the transition tree corresponding to each object can be further optimized so that each node in each transition tree only records the difference information of the corresponding second hidden class relative to the referenced hidden class and the indication information of the node referenced by this node (for example, the name of the hidden class corresponding to the referenced node). Thus, when obtaining the information recorded in each second hidden class, the difference information recorded by each node in the transition tree can be directly obtained. This can not only reduce the overhead when saving the transition tree, but also avoid repeated acquisition and saving of the same information in each second hidden class, reducing the overhead when saving the layout information.
[0114] Exemplarily, as Figure 4 shown, in the transition tree corresponding to object a, the node corresponding to hclassx records the information of attribute x and the name of hclass0 referenced by hclassx. The node corresponding to hclassxy only records the information of attribute y and the name of hclassx referenced by hclassxy. The node corresponding to hclassy records the information of attribute y and the name of hclass0 referenced by hclassy. The node corresponding to hclassyx records the information of attribute x and the name of hclassy referenced by hclassyx. When obtaining the information recorded in each second hidden class, the difference information recorded by each node in this transition tree can be directly obtained.
[0115] S120. Determine the offset of the attribute used at the attribute usage point of each object in the dynamic language code according to the layout information.
[0116] Since there may be duplicate names for each object in the dynamic language code, the position information of the creation point of each object in the code can be used to identify each object.
[0117] Specifically, the dynamic language code can be traversed to obtain the position information of the creation point of each object in the dynamic language code.
[0118] In some embodiments, for any object in the dynamic language code, the position information of the creation point of this object can be the concatenation of the file name of the file where this object is created, the storage path of the file, and the offset of this object relative to the file it belongs to. Since file names under the same storage path usually do not repeat, and the offsets of different objects in the same file relative to this file are also different, the uniqueness of the position information of the creation point of each object can be ensured.
[0119] In some other embodiments, for any object in dynamic language code, the location information of the creation point of the object can also be the concatenation of the creation instruction of the object, the function where the creation instruction is located, and the storage path and file name of the file to which the function belongs. Since the creation instructions of each object are different in the same method of the same file, the location information of the creation point of each object can be ensured to be unique.
[0120] After obtaining the location information of the creation point of each object, the object mapping information can be determined according to the location information corresponding to each object, and the first hidden class, the second hidden class, and the transition tree corresponding to the layout information of each object. The object mapping information can indicate the location information of the creation point of each object and the offsets of each attribute relative to the object to which it belongs. Through the object mapping information, the location information of the creation point of each object can be associated with the offsets of the corresponding attributes, so as to facilitate the subsequent determination of the offsets of the attributes used at the attribute usage points of each object.
[0121] In some embodiments, the object mapping information can be two nested maps. Among them, the outer map can record the location information of the creation point of each object and the corresponding inner map, and each inner map can record the information of each attribute of each object (such as the attribute name, the offset corresponding to the attribute, the attribute description, etc.). Through the nested double-map structure, the location information of the creation point of each object can be associated with the attribute information of the object to ensure the uniqueness of the attribute information of each object.
[0122] Exemplarily, the transition tree corresponding to object a is as Figure 5 shown in (a) therein, and the transition tree corresponding to object b is as Figure 5 shown in (b) therein. Then, the double-map structure generated based on the layout information of object a and object b, and the location information of the creation point of object a and object b can be as Figure 5 shown in (c) therein.
[0123] Among them, mapA is the outer map. The position 0 in mapA is the location information of the creation point of object a, and the position 1 in mapA is the location information of the creation point of object b. The inner map includes map0 corresponding to position 0 and map1 corresponding to position 1. Map0 includes the attributes x, xy, y, and yx of object a, where the offset corresponding to x is a1, the offset corresponding to xy is a2, the offset corresponding to y is a3, and the offset corresponding to yx is a4; map1 includes the attributes x, xy, y, and yx of object b, where the offset corresponding to x is b1, the offset corresponding to xy is b2, the offset corresponding to y is b3, and the offset corresponding to yx is b4.
[0124] In some embodiments, the key in the inner map of the double map structure can also be the concatenation of the attribute name and the attribute description (such as attribute permissions, etc.). Exemplarily, as Figure 6 shown, the inner map corresponding to position 0 is map2, and map2 includes 4 keys: x7, x7y6, y6, y6x7. Among them, "7" is the permission of attribute x, indicating that attribute x is readable, writable, and executable, and "6" is the permission of attribute y, indicating that attribute y is readable and writable.
[0125] In some embodiments, the object mapping information can also be a single map structure. The key of the map can be the location information of the creation point of each object, and the value of the map can be the name of the attribute of each object + the offset corresponding to the attribute. In the following embodiments of the present application, an example will be given with the object mapping information being a double map structure.
[0126] To ensure the compatibility between the layout information of each object during the running of the dynamic language program obtained each time, the keys of the double map generated each time can be kept in the same format. For example, the key of the outer map of the double map structure generated each time can be the concatenation of the creation instruction of the object, the function where the creation instruction is located, and the storage path and file name of the file to which the function belongs; the key of the inner map of the double map structure generated each time can be the concatenation of the attribute name and the attribute permission.
[0127] After determining the object mapping information, when using each object's attribute according to the object mapping information, the offset of the attribute used at each attribute usage point in the dynamic language code can be determined based on the target second hidden class corresponding to each object's attribute.
[0128] For example, in a certain line of the dynamic language code, the attribute x of object a is used, and the target second hidden class corresponding to attribute x is hclassx. Then, the location information of the creation point of object a to which x belongs and the attribute name of x can be determined according to hclassx first. Then, the corresponding inner map (i.e., map0 corresponding to position 0) can be determined in mapA according to the location information of the creation point of object a. Then, the corresponding offset (i.e., a1) can be determined in map0 according to the attribute name of x. a1 is the corresponding offset when using the attribute x of object a in the dynamic language code.
[0129] For any property, the second hidden class corresponding to the property, the name of the property, and the location information of the creation point of the object to which the property belongs can be pre-associated and stored (e.g., stored in a corresponding table in the database). In this way, the name of the property and the location information of the creation point of the object to which the property belongs can be queried in this table according to the second hidden class corresponding to any property.
[0130] S130. Compile and optimize the dynamic language code according to the layout information and each offset to generate the corresponding assembly code.
[0131] Specifically, first, according to the layout information of each object, the dynamic language code can be optimized through ahead-of-time compilation (abbreviated as "AOT"). Then, the properties used at each property usage point in the optimized dynamic language code are replaced with the corresponding offsets. Next, the replaced dynamic language code is compiled to generate the corresponding assembly code. Since the process of compiling and generating the assembly code is executed before running, compared with compiling during running, it can improve the running performance of the dynamic language program.
[0132] The generated assembly code can be stored in a file (such as App.an) for subsequent loading during running.
[0133] S140. Serialize the layout information of each object.
[0134] After obtaining the layout information of each object, the layout information of the properties of each object (such as the second hidden class corresponding to each property) can also be stored first for subsequent use during running. Exemplarily, the second hidden class corresponding to each property can be stored in a tagged array, and the subscript of the second hidden class of each property in the array is recorded through a dictionary structure during the storage process.
[0135] The dictionary structure can be a map. The key of the map can indicate the properties of each object, and the value of the map can be the subscript of the second hidden class corresponding to each property in the array.
[0136] Since there may be duplicate cases in the property names of each object in the dynamic language code, the location information of the creation point of the properties of each object in the code can be used to identify the properties of each object in the map.
[0137] For the attributes of any object in dynamic language code, the location information of the creation point of the attribute can be the concatenation of the creation instruction of the attribute, the function where the creation instruction is located, and the storage path and file name of the file to which the function belongs. Since the creation instructions of each attribute are different in the same method of the same file, the location information of the creation point of each attribute can be ensured to be unique.
[0138] Next, the above array and dictionary structures can be placed into a constant pool object, and the constant pool object can be serialized based on the snapshot function to generate a corresponding byte stream. In this way, when the layout information of each serialized object is damaged or lost, it can be quickly restored through the snapshot, improving the stability of the dynamic language program during runtime.
[0139] S150: Run the assembly code.
[0140] First, the byte stream can be deserialized to obtain the constant pool object, and then the assembly code can be run. During the running process, when accessing the attribute of an object, since the attribute has been replaced with the corresponding offset during compilation, the position of the value of the attribute in memory can be directly obtained according to the offset, so as to obtain the value of the attribute. The entire access process is simple and efficient, eliminating the complex process of searching for object attributes.
[0141] During the running process of the assembly code, if the attribute of an object in the assembly code is an attribute newly added during the historical running period of the dynamic language code, the corresponding subscript can be obtained from the dictionary structure of the constant pool object first through the location information of the creation point of the attribute in the code, and then the layout information of the corresponding attribute can be obtained from the array of the constant pool object according to the obtained subscript. In this way, there is no need to create a new layout for this attribute, thus reducing the layout overhead of creating newly added attributes.
[0142] The compilation and running method provided by the embodiments of the present application first obtains the layout information of each object during the historical running period of the dynamic language code, and uses the historical layout information of each object as the current layout information of each object. In this way, the offset of the attribute used at the attribute usage point of each object in the current dynamic language code can be determined according to the historical layout information of each object, so that when compiling the dynamic language code to generate assembly code, the attribute used at the attribute usage point of each object in the assembly code can be replaced with the corresponding offset. In this way, when running the assembly code, the value of the corresponding attribute can be directly obtained from memory according to each offset without an intermediate search link, thereby improving the access efficiency of the attributes of objects during the running period of the dynamic language program; and, since the process of compiling and generating assembly code is carried out before the dynamic language program runs, compared with runtime compilation, it does not occupy runtime resources, thereby improving the running performance of the dynamic language program.
[0143] Those skilled in the art can understand that the above embodiments are exemplary and not intended to limit the present application. Where possible, the execution order of one or several of the above steps can be adjusted, or selective combination can be made to obtain one or more other embodiments. For example, in some embodiments, step S130 can be executed after step S120, and in other embodiments, step S130 can also be executed before step S120; in some embodiments, step S130 can be not executed. Those skilled in the art can make arbitrary selection and combination from the above steps, and all those that do not depart from the essence of the present application solution fall within the protection scope of the present application.
[0144] Based on the same concept, the embodiments of the present application further provide an electronic device. The software system of the electronic device can adopt a layered architecture, an event-driven architecture, a microkernel architecture, a microservices architecture or a cloud architecture. Taking the Android system with a layered architecture as an example in the embodiments of the present invention, the software structure of the electronic device is exemplarily described.
[0145] Figure 7 It is a schematic diagram of the software architecture of the electronic device provided by the embodiments of the present application. As Figure 7 shown, the software system of the electronic device can be divided into several layers. In some embodiments, the Android system can be divided into an application layer, an application framework layer, an Android runtime, a system library, and a kernel layer from top to bottom.
[0146] The application layer may include applications such as a camera, a gallery, a calendar, a call, a map, a WLAN, a Bluetooth, music, a video, a short message, and multitask management.
[0147] The application framework layer provides application programming interfaces (APIs) and programming frameworks for the applications in the application layer. The application framework layer includes some predefined functions.
[0148] As Figure 7 shown, the application framework layer may include a window manager, a content provider, a view system, a telephone manager, a resource manager, a notification manager, etc.
[0149] 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.
[0150] The content provider is used to store and obtain data, and make these data accessible to applications.
[0151] 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.
[0152] The telephony manager is used to provide the communication functions of the electronic device. For example, the management of call states (including answering, hanging up, etc.).
[0153] The resource manager provides various resources for applications, such as localized strings, icons, pictures, layout files, video files, and so on.
[0154] The notification manager enables applications to display notification information in the status bar. It can be used to convey informational messages, which can automatically disappear after a short stay without user interaction. For example, the notification manager is used to inform that the download is complete, 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 the notification of a background-running application, or a notification that appears in the form of a dialog window on the screen. For example, prompt text information in the status bar, emit a prompt tone, the electronic device vibrates, the indicator light flashes, etc.
[0155] Android runtime includes a core library and a virtual machine. Android runtime is responsible for the scheduling and management of the system.
[0156] The core library consists of two parts: one part is the functional functions that need to be called by the Java language, and the other part is the core library of
[0157] The application layer and the application framework layer run in the virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as the management of object life cycles, stack management, thread management, security and exception management, and garbage collection.
[0158] The system library can include multiple functional modules. For example: surface manager, media libraries, 3D graphics processing library (e.g., OpenGL ES), 2D graphics engine (e.g., SGL), etc.
[0159] The surface manager is used to manage the display subsystem and provides the fusion of 2D and 3D layers for multiple applications.
[0160] The media library supports the playback and recording of multiple common audio and video formats, as well as static image files, etc. The media library can support multiple audio and video coding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0161] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, synthesis, and layer processing, etc.
[0162] The 2D graphics engine is a drawing engine for 2D drawing.
[0163] The kernel layer is the layer between hardware and software. The kernel layer at least includes a display driver, a camera driver, an audio driver, and a sensor driver.
[0164] After the user inputs a touch operation, the touch sensor in the hardware device can generate a corresponding hardware interrupt and send it to the kernel layer. The kernel layer can encapsulate the touch operation into touch events (for example, touch down (action down) event, touch move (action move) event, and touch up (action up) event, etc.), and can report the touch events to the upper-layer APP through the input module in the system library.
[0165] Based on the same concept, as an implementation of the above method, the embodiment of the present application provides a compilation and running device. The device embodiment corresponds to the foregoing method embodiment. For the convenience of reading, the details in the foregoing method embodiment will not be described one by one in this device embodiment. However, it should be clear that the device in this embodiment can correspondingly implement all the contents in the foregoing method embodiment.
[0166] Figure 8 It is a schematic structural diagram of the compilation and running device provided by the embodiment of the present application, as Figure 8 shown, the compilation and running device provided by this embodiment may include:
[0167] The acquisition module 210: is used to acquire the layout information of each object during the historical running of the dynamic language code;
[0168] The determination module 220: is used to determine the offset of the attribute used at the attribute usage point of each object in the dynamic language code according to the layout information;
[0169] The compilation optimization module 230: is used to compile and optimize the dynamic language code according to the layout information and each offset to generate the corresponding assembly code;
[0170] The running module 240: is used to run the assembly code.
[0171] In a possible implementation of the second aspect, before running the assembly code, the compilation and running device further includes a serialization module 250: used to serialize the layout information of each object to obtain a byte stream;
[0172] The compilation and running device further includes a deserialization module 260: used to deserialize the byte stream to obtain the layout information of each object;
[0173] The running module 240 is specifically configured to: run the assembly code, and when the first attribute in the assembly code is an attribute newly added during the historical running of the assembly code, determine the layout information of the first attribute according to the position information of the first attribute in the assembly code and the layout information of each object.
[0174] In a possible implementation of the second aspect, the serialization module 250 is specifically configured to:
[0175] Based on the snapshot function, serialize the layout information of each object.
[0176] In a possible implementation of the second aspect, the serialization module 250 is specifically configured to:
[0177] According to the layout information of each object and the first position information, determine a first map, where the first position information includes the position information of the creation points of the attributes of each object, and the first map records the first position information and the layout information of the attributes corresponding to the first information;
[0178] Serialize the first map to obtain the byte stream.
[0179] In a possible implementation of the second aspect, for any object, the layout information indicates: a first hidden class generated when creating the object, a second hidden class generated each time an attribute is added to the object, a conversion tree, and a target second hidden class, where the target second hidden class is the second hidden class corresponding to the attribute used when using the attribute of the object, and the conversion tree is used to indicate the reference relationship between the first hidden class and each of the second hidden classes, and between each of the second hidden classes.
[0180] In a possible implementation of the second aspect, the determination module 220 is specifically configured to:
[0181] Obtain the position information of the creation points of each object in the dynamic language code;
[0182] Determine object mapping information according to the position information corresponding to each object, the first hidden class, the second hidden class, and the conversion tree, where the object mapping information indicates the position information of the creation point of each object and the offset of each corresponding attribute;
[0183] Determine the offset of the attribute used at each attribute usage point in the dynamic language code according to the object mapping information and the target second hidden class corresponding to each object.
[0184] In a possible implementation manner of the second aspect, the object mapping information includes a second map and a third map. The second map records the position information of the creation point of each object and the corresponding third map. The third map corresponding to the position information of the creation point of each object records the attribute name of each attribute of the object and the corresponding offset.
[0185] In a possible implementation manner of the second aspect, for the second attribute in the dynamic language code, if the position information of the creation point of the object to which the second attribute belongs is the same as the position information of the creation point of the object corresponding to the target third map, and the attribute name of the second attribute is the same as the attribute name of the third attribute in the target third map, then the offset of the second attribute is the same as the offset of the third attribute in the target third map. The second attribute is any attribute in the dynamic language code, and the attribute name of the second attribute and the position information of the creation point of the object to which it belongs are determined according to the target second hidden class corresponding to the second attribute.
[0186] In a possible implementation manner of the second aspect, for any object, the layout information includes: the first hidden class, the difference information of each second hidden class relative to the referenced hidden class, the conversion tree, and the target second hidden class.
[0187] In a possible implementation manner of the second aspect, each node in the conversion tree only records the difference information of the second hidden class corresponding to the node relative to the referenced hidden class.
[0188] In a possible implementation manner of the second aspect, for the target information in the dynamic language code, the position information of the creation point of the target information includes: the creation instruction of the target information, the function where the creation instruction is located, and the storage path and file name of the file to which the function belongs. The target information is any object or any attribute in the dynamic language code.
[0189] In a possible implementation of the second aspect, for any object in the dynamic language code, the location information of the creation point of the object includes: the storage path and file name of the file where the object is created, and the offset of the object relative to the file.
[0190] In a possible implementation of the second aspect, the historical running period is the most recent running period of the dynamic language code.
[0191] In a possible implementation of the second aspect, the obtaining module 210 is specifically configured to:
[0192] Based on the PGO sampling method, obtain the layout information of each object during the running of the dynamic language code.
[0193] In a possible implementation of the second aspect, the dynamic language is one of Php, Asp, JavaScript, Python, Perl.
[0194] The device provided in this embodiment can execute the above method embodiment, and its implementation principle and technical effect are similar, which will not be elaborated here.
[0195] Those skilled in the art can clearly understand that, for the convenience and conciseness of description, only the above-mentioned division of each functional unit and module is used as an example. In actual applications, the above functions can be allocated to different functional units and modules according to needs, that is, the internal structure of the device is divided into different functional units or modules to complete all or part of the functions described above. Each functional unit and module in the embodiment can be integrated into a processing unit, or each unit exists physically alone, or two or more units are integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of a software functional unit. In addition, the specific names of each functional unit and module are only for the convenience of mutual distinction and do not limit the protection scope of this application. The specific working processes of the units and modules in the above system can refer to the corresponding processes in the foregoing method embodiments, which will not be elaborated here.
[0196] Based on the same concept, an embodiment of the present application also provides an electronic device. Figure 9 This is a schematic structural diagram of the electronic device provided in the embodiment of the present application. As Figure 9 shown, the electronic device provided in the embodiment of the present application may include: a memory 310 and a processor 320. The memory 310 is used to store a computer program; the processor 320 is used to implement the method described in the above method embodiment when calling the computer program.
[0197] The electronic device provided in this embodiment can execute the above method embodiment, and its implementation principle and technical effects are similar, which will not be elaborated here.
[0198] An embodiment of this application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the method described in the above method embodiment is implemented.
[0199] An embodiment of this application also provides a computer program product. When the computer program product runs on an electronic device, the electronic device is caused to execute the method described in the above method embodiment.
[0200] An embodiment of this application also provides a chip system, including a processor. The processor is coupled to a memory, and the processor executes a computer program stored in the memory to implement the method described in the above method embodiment. Wherein, the chip system can be a single chip or a chip module composed of multiple chips.
[0201] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions described in the embodiments of this specification are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transmitted through the computer-readable storage medium. The computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center in a wired manner (such as coaxial cable, optical fiber, digital subscriber line) or a wireless manner (such as infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that the computer can access or a data storage device such as a server or data center that includes one or more integrated available media. The available medium can be a magnetic medium (such as a floppy disk, hard disk, or magnetic tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid state disk (SSD)), etc.
[0202] Those of ordinary skill in the art can understand all or part of the processes in the above method embodiments. These processes can be completed by relevant hardware instructed by a computer program. The program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the above method embodiments. The aforementioned storage medium can include various media that can store program codes, such as ROM or random access memory RAM, magnetic disks, or optical discs.
[0203] The naming or numbering of steps appearing in this specification does not mean that the steps in the method flow must be executed in the chronological / logical order indicated by the naming or numbering. The already named or numbered process steps can be changed in the order of execution according to the technical purpose to be achieved, as long as the same or similar technical effects can be achieved.
[0204] In the above embodiments, the descriptions of the respective embodiments have their own emphases. For parts not detailed or recorded in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0205] In the embodiments provided in this specification, it should be understood that the disclosed devices / equipment and methods can be implemented in other ways. For example, the device / equipment embodiments described above are only illustrative. For example, the division of the modules or units is only a logical function division. In actual implementation, there can be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection to each other can be through some interfaces. The indirect coupling or communication connection of the devices or units can be in electrical, mechanical or other forms.
[0206] It should be understood that in the description of this application specification and the appended claims, the terms "include", "comprise", "have" and any variations thereof are intended to cover non-exclusive inclusion, all meaning "including but not limited to", unless otherwise specifically emphasized in other ways. For example, a process, method, system, product or equipment that includes a series of steps or modules does not have to be limited to those steps or modules clearly listed, but may include other steps or modules not clearly listed or inherent to these processes, methods, products or equipment.
[0207] In the description of this specification, unless otherwise specified, " / " indicates that the objects associated before and after are in an "or" relationship. For example, A / B can represent A or B; the "and / or" in this specification is used to describe the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. Among them, A and B can be singular or plural.
[0208] Moreover, in the description of this specification, unless otherwise specified, "a plurality of" means two or more than two. "At least one of the following" or its similar expressions refer to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b, or c can represent: a, b, c, a - b, a - c, b - c, or a - b - c, where a, b, c can be single or multiple.
[0209] As used in the specification of this application and the appended claims, the term "if" may be construed, depending on the context, as "when", "once", "in response to determining", or "in response to detecting". Similarly, the phrase "if determined" or "if [the described condition or event] is detected" may be construed, depending on the context, to mean "once determined", "in response to determining", "once [the described condition or event] is detected", or "in response to detecting [the described condition or event]".
[0210] In addition, in the description of the specification of this application and the appended claims, the terms "first", "second", etc. are used to distinguish similar objects, and do not necessarily have to be used to describe a specific order or sequence, nor can they be understood as indicating or implying relative importance or implicitly indicating the quantity of the indicated technical features. It should be understood that such data may be interchanged under appropriate circumstances so that the embodiments described herein can be implemented in an order other than that illustrated or described herein; the features defined with "first" and "second" may explicitly or implicitly include at least one of such features.
[0211] In the embodiments of this specification, words such as "exemplarily" or "for example" are used to represent examples, illustrations, or explanations. Any embodiment or design described as "exemplarily" or "for example" in the embodiments of this specification should not be construed as being more preferred or having more advantages than other embodiments or designs. Rather, the use of words such as "exemplarily" or "for example" is intended to present relevant concepts in a specific manner.
[0212] The reference to "one embodiment" or "some embodiments" etc. described in the specification of this application means that a specific feature, structure, or characteristic described in connection with that embodiment is included in one or more embodiments of this specification. Thus, statements such as "in one embodiment", "in some embodiments", "in other some embodiments", "in still other embodiments", etc. that appear in different places in this specification do not necessarily all refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways.
[0213] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this specification and are not intended to limit them; although this specification has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements for some or all of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this specification.
Claims
1. A compilation and execution method, characterized in that, it includes: Obtain the layout information of each object during the historical execution of the dynamic language code; According to the layout information, determine the offset of the attribute used at each attribute usage point in the dynamic language code; Compile and optimize the dynamic language code according to the layout information and each offset, and generate corresponding assembly code; Execute the assembly code.
2. The method according to claim 1, characterized in that, Before executing the assembly code, the method further includes: Serialize the layout information of each object to obtain a byte stream; The execution of the assembly code includes: Deserialize the byte stream to obtain the layout information of each object; Execute the assembly code, and when the first attribute in the assembly code is an attribute newly added during the historical execution of the assembly code, determine the layout information of the first attribute according to the position information of the first attribute in the assembly code and the layout information of each object.
3. The method according to claim 2, characterized in that, The serialization of the layout information of each object includes: Based on the snapshot function, serialize the layout information of each object.
4. The method according to claim 2 or 3, characterized in that, The serialization of the layout information of each object to obtain a byte stream includes: According to the layout information of each object and the first position information, determine a first map, the first position information includes the position information of the creation point of the attributes of each object, and the first map records the first position information and the layout information of the attributes corresponding to the first information; Serialize the first map to obtain the byte stream.
5. The method according to any one of claims 1-4, characterized in that, For any object, the layout information indicates: a first hidden class generated when creating the object, a second hidden class generated each time an attribute is added to the object, a conversion tree, and a target second hidden class, the target second hidden class is the second hidden class corresponding to the attribute used when using the attribute of the object, and the conversion tree is used to indicate the reference relationship between the first hidden class and each second hidden class, and between each second hidden class.
6. The method according to claim 5, characterized in that, The determination of the offset of the attribute used at each attribute usage point in the dynamic language code according to the layout information includes: Obtain the position information of the creation point of each object in the dynamic language code; According to the position information corresponding to each object, the first hidden class, the second hidden class, and the conversion tree, determine object mapping information, the object mapping information indicates the position information of the creation point of each object and the offset of each corresponding attribute; According to the object mapping information and the target second hidden class corresponding to each object, determine the offset of the attribute used at each attribute usage point in the dynamic language code.
7. The method according to claim 6, characterized in that, The object mapping information includes a second map and a third map. The second map records the location information of the creation point of each object and the corresponding third map. In the third map corresponding to the location information of the creation point of each object, the attribute names of each attribute of the object and the corresponding offsets are recorded.
8. The method according to claim 7, wherein, for the second attribute in the dynamic language code, if the location information of the creation point of the object to which the second attribute belongs is the same as the location information of the creation point of the object corresponding to the target third map, and the attribute name of the second attribute is the same as the attribute name of the third attribute in the target third map, then the offset of the second attribute is the same as the offset of the third attribute in the target third map. The second attribute is any attribute in the dynamic language code, and the attribute name of the second attribute and the location information of the creation point of the object to which it belongs are determined according to the target second hidden class corresponding to the second attribute.
9. The method according to any one of claims 1-8, wherein, for any object, the layout information includes: the first hidden class, the difference information of each second hidden class relative to the referenced hidden class, the conversion tree, and the target second hidden class.
10. The method according to any one of claims 1-9, wherein, for the target information in the dynamic language code, the location information of the creation point of the target information includes: the creation instruction of the target information, the function where the creation instruction is located, and the storage path and file name of the file to which the function belongs. The target information is any object or any attribute in the dynamic language code.
11. The method according to any one of claims 1-10, wherein, for any object in the dynamic language code, the location information of the creation point of the object includes: the storage path and file name of the file that creates the object, and the offset of the object relative to the file.
12. The method according to any one of claims 1-11, wherein, The historical running period is the most recent running period of the dynamic language code.
13. The method according to any one of claims 1-12, wherein, The obtaining of the layout information of each object during the running of the dynamic language code includes: Based on the PGO sampling method, obtaining the layout information of each object during the running of the dynamic language code.
14. The method according to any one of claims 1-13, wherein, The dynamic language is one of Php, Asp, JavaScript, Python, Perl.
15. An electronic device, wherein, comprising: A memory and a processor, the memory is used to store a computer program; the processor is used to execute the method according to any one of claims 1-14 when calling the computer program.
16. A computer-readable storage medium, on which a computer program is stored, wherein, The computer program, when executed by a processor, implements the method according to any one of claims 1-14.
17. A computer program product, characterized in that, when the computer program product runs on an electronic device, the electronic device is caused to execute the method according to any one of claims 1-14.
18. A chip system, characterized in that, the chip system includes a processor, the processor is coupled to a memory, and the processor executes a computer program stored in the memory to implement the method according to any one of claims 1-14.