Detailed Description
The following description of the embodiments of the present application will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present application, but not all embodiments. All other embodiments, which are derived by a person skilled in the art based on the embodiments of the application, fall within the scope of protection of the application.
Fig. 1 is a schematic diagram of the core concept of the present application. One of the core ideas of the present application as shown in fig. 1 is to propose an optimization method, apparatus, terminal device and machine readable medium for garbage collection, wherein after a source program 20 is loaded into a designated area 10 of a memory management unit 100, before the source program is finished running and memory needs to be collected, objects that do not need to be collected may be marked, where the designated area includes, for example, a plurality of first objects 11, 12, 13 stored in the designated area 10 of a compiled file in advance, and a second object 21 other than the designated area 10 referred to by the first object. According to the method and the device, the characteristics that the garbage collection is not needed in the area stored by the pre-compiled file are utilized, the objects in the pre-compiled area and the related area are directly marked, the time for judging whether the objects in the area need to be collected one by one is saved, and therefore garbage collection efficiency is improved.
First embodiment
The first embodiment of the invention provides an optimization method for garbage collection. Fig. 2 is a flowchart showing steps of an optimization method for garbage collection according to a first embodiment of the present invention. As shown in fig. 2, the method for optimizing garbage collection according to the embodiment of the invention includes the following steps:
S101, before recovering a memory management unit, judging whether a plurality of first objects contained in a file refer to a second object outside a designated area where the file is located, wherein the designated area is located in the memory management unit;
The file may be, for example, a pre-compiled file, or may be another type of file. For dynamic programming languages, the precompiled files are stored in a designated area of the memory management unit after being compiled by the source program. Before the memory management unit retrieves, for example, during the process of loading the pre-compiled file corresponding to the source program into the specified area of the memory management unit and/or during the process of running the source program, it may be determined whether the first object references a second object outside the specified area. Wherein the first object may have a pointer therein that points to the address of the referenced second object. When the address of the second object is judged to be located outside the designated area, it is judged that the first object references the external second object.
Specifically, the execution subject, for example, various electronic devices such as a server and a client, may first call a source program handler in an existing compiler of the system, compile the source program to generate compiled data, and then the system may link the compiled data to a memory management unit to be managed by the memory management unit. The system may then generate a pre-compiled file from the compiled data linked into the memory management unit. The memory management unit is a part of a memory area, is a memory area which is managed by the virtual machine system and is used for meeting the allocation of the dynamic memory of the program, and is a specific area defined by the virtual machine and used for managing the generated script language object compared with a common memory area which is used for storing codes and objects.
After the pre-compiled file is generated, the pre-compiled file may be loaded into a designated region of the memory management unit. Mapping the pre-compiled file to a system memory space of a dynamic programming language system; and loading the advanced compiled file mapped to the memory space to the memory management unit.
In the mapping process, a designated area may be marked in the memory management unit as a memory space of the pre-compiled file, and this designated area may also be referred to as a pre-compiled area. As described above, in the process of pre-compiling the file load, the execution body may determine whether each object in the pre-compiling file references an area other than the specified area.
The above-described "object" is a combination of code and data that can be regarded as one unit. An object may be a piece of an application, such as a control or a form. The entire application may also be an object. As described above, a pointer is an address in an object that points to a piece of memory. And when the address area pointed by the pointer of a certain object is judged to be an area outside the specified area, the second object referenced by the first object is considered to be an address area outside the specified area.
After performing step S101, step S102 may be performed as follows:
s102, in the case that one or more first objects are determined to reference a second object outside the specified area, recording the address of the second object;
In this step, when it is determined that the pointer of the first object points to an area outside the specified area, it is determined that the first object references a second object outside the specified area, and in order to prevent the address of the second object from being recovered by mistake later, in this step, the address of the second object may be recorded and stored in a storage area, for example, in a storage structure such as an existing RememberSet, storeBuffer, cardtable, array, list, or the like.
After performing step S102, step S103 may be performed as follows:
s103, determining the designated area and the address where the second object is located as a non-recycling area.
In the previous step, after the addresses of the second objects are determined, the addresses where the objects are located may be recorded in the storage space, and the second object in the addresses may be marked. In this step, it may be determined that the areas corresponding to the objects are non-reclaimed areas based on the objects marked in step S103.
For the designated area, each first object in the designated area may be marked as a non-reclaimed object, or the whole area may be marked, which is not described herein.
In addition, in the reclaimed memory management unit, since the designated area storing the advanced compilation file itself is an unrecoverable area, the designated area, that is, the entire advanced compilation area, may be regarded as the unrecoverable area. In some embodiments, all the areas except the specified area and the area where the second object is located may be reclaimed, in other embodiments, the execution subject may mark other non-reclaimed areas according to other principles besides the specified area and the area where the second object is located, and skip the areas together during the reclaiming, and reclaim the areas except the marked areas.
From the above, the method for optimizing garbage collection according to the first embodiment of the present invention has at least the following technical effects:
According to the scheme provided by the application, according to the characteristic that the object storing the appointed area of the pre-compiled file is not required to be recycled by garbage, the appointed area of the pre-compiled file and the area related to the pre-compiled file are not required to be traversed during garbage recycling, so that the whole object in the memory management unit is not required to be marked like the prior art, and a great part of marking time is saved.
Second embodiment
The second embodiment of the invention provides an optimization method for garbage collection. Fig. 3 is a flowchart showing steps of an optimization method for garbage collection according to a second embodiment of the present invention. As shown in fig. 3, the method for optimizing garbage collection according to the embodiment of the invention comprises the following steps:
S204, before recovering the memory management unit, judging whether a plurality of first objects contained in a file refer to a second object outside a designated area where the file is located, wherein the designated area is located in the memory management unit;
S205, in the case that one or more first objects are determined to reference a second object outside the specified area, recording the address of the second object;
s207, determining the designated area and the address where the second object is located as a non-recycling area.
The steps S204, S205 and S207 are the same as or similar to the steps S101 to S104 of the previous embodiment, and will not be described again here. This embodiment focuses on the differences from the previous embodiment.
In one embodiment, after step S205, step S206 may be performed as follows:
S206, determining a sub-object of the second object according to the address of the second object under the condition of recovering the memory management unit;
In this step, when the source program corresponding to the pre-compiled file runs, in order to prevent the objects that are not active any more from occupying too much space of the memory management unit, the memory management unit can be recycled, the unreachable objects that are not active any more are cleaned, and the space is recycled. In the recycling process, starting from the address of the second object recorded in step S205, the child nodes of the second object may be traversed, and a plurality of child objects included in the second object may be determined. In one embodiment, the second object and each of its sub-objects may be marked as non-reclaimed objects to avoid that the area where the second object is located is later erroneously reclaimed.
In an embodiment of the present invention, the step of determining the sub-object of the second object according to the address of the second object in step S206 may be:
And traversing to obtain a sub-object of the second object by taking a pointer pointing to the second object in the first object as a root node.
S208, determining the address of the sub-object of the second object as a non-recycling area.
In an embodiment, before step S204, the method may further include the steps of:
s201, compiling data is generated according to a source program;
s202, linking the compiled data to a memory management unit;
s203, generating an advanced compiling file according to compiling data linked to the memory management unit.
In the step S201, that is, the step of generating compiled data according to the source program, the executing body, for example, various electronic devices such as a server and a client, may call the source program processing program in the existing compiler of the system, for example, lexical analysis, syntax analysis, and a byte code generating component, perform the lexical analysis and syntax analysis on the source program, generate the byte code and/or the native code that can be directly run by the dynamic language system, and the relevant constant pool and symbol table, where the byte code, the constant pool and the symbol table may be referred to as "compiled data" generated by compiling the source program, that is, the compiled data may include the byte code, the constant pool and the symbol table.
In the above compiled data, a Byte code (Byte-code) is a binary file that is preprocessed by a compiler, contains an execution program, and is composed of a sequence of operation code/data pairs. A symbol table is a data structure that creates a record entry for each variable name, the fields of the record being the respective attributes of the name, and allows a compiler to quickly find the record entry for each variable name, and to quickly store compiled data for the attributes, storage locations, etc. of the variable in the record entry, and to obtain the compiled data in the record. Constant values of various basic types (such as int, long, etc.) and object types (such as String and array) defined in codes are contained in the constant pool, and symbol references in text form are also contained, such as: fully qualified names of classes and interfaces, names and descriptors of fields, names and descriptors of methods, etc.
In the step S202, that is, the step of linking the compiled data to the memory management unit, the system may link the compiled data to the memory management unit and manage the compiled data by the memory management unit. Where "linking" may refer to the process of combining one or more object files (object files) generated by a compiler into one executable file, library file, or another object file.
When the compiled data are stored in the memory space, step S202 may specifically include linking the memory space in which the compiled data such as the byte code, the symbol table, the constant pool, and the like are stored to the memory management unit.
The memory space is "linked" to the memory management unit, for example, a virtual address corresponding to the created memory space is added to the memory management unit, and the memory management unit manages the memory space. In implementation, compiled data may be moved into the memory space of the dynamic programming language system and linked to the memory management unit.
The unit of memory space of the dynamic programming language system is, for example, a "memory page", and in this step, the compiled data may be moved into the memory page, and the compiled data in the memory page may be linked to the memory management unit as a whole. In an alternative embodiment, the memory pages may be consecutive memory pages, such as temporarily created memory pages, which are formatted to match, such as be consistent with, the memory page format of the dynamic programming language system. Moving compiled data to successive memory pages may save space to save memory space when writing compiled data to a pre-compiled file.
In this step, the compiled data may be linked to the memory management unit, and the continuous or discontinuous page addresses of the memory pages where the compiled data is located may be linked to the memory management unit. When the page addresses containing the compiled data are linked to the memory management unit, the page addresses can be managed by the memory management unit, including performing operations such as reading and traversing, so as to successfully execute the subsequent loading process.
In step S203, that is, the step of generating the pre-compiled file according to the compiled data linked to the memory management unit, the system may generate the pre-compiled file according to the compiled data linked to the memory management unit. Specifically, if the compiled data is stored in the memory space, and the address of the memory space is already linked to the memory management unit in step S202, then in step S203, the compiled data may be managed by the dynamic programming language system. In this step, the dynamic programming language system may scan the storage space of the programming data to obtain the specified content written into the pre-compiled file.
In a specific embodiment, according to a specified format, for example, a format of a pre-compiled file, item contents corresponding to each item in the specified format are extracted from compiled data in a storage space, and each item content is written into the pre-compiled file, so that a pre-compiled file meeting the specified format is generated.
The above specified format may be originally defined by the system or defined by a developer. In an embodiment of the present application, the items included in the specified format may include, for example: at least one of a file header, a program byte code address table, a public object address table, an early compiling object page table and the like; the header may include, for example: the number of source programs, the number of common objects, and the memory space information occupied by compiled data, such as the number of occupied pages. The program byte code address table is used for storing byte code addresses in compiled data; the public object address table is used for storing addresses of public objects corresponding to the compiled data; the pre-compiled file address table is used for storing the address of the pre-compiled file; and the pre-compiled object page table is used for storing the address of the object corresponding to the pre-compiled file.
In this step, the execution body may traverse the storage space of the compiled data, construct a header structure according to the header format of the compiled header in advance, and write the file. Then, the program byte code address table, the public object address table, the pre-compiled file address table and the pre-compiled object address table are written in sequence. And finally, writing all page contents in the storage space, so as to generate an advanced compiling file according to the compiling data.
In the step S204, during the process of loading the file into the memory management unit, the file header may be read and mapped to the system space; mapping the advanced compiling file to a system storage space of a dynamic programming language system according to the corresponding number of source programs, the number of public objects and the storage space information occupied by compiling data in the file header; and loading the advanced compiled file mapped to the memory space to the memory management unit.
In the step of reading in the file header and mapping the file header to the system space, the file header can be read and mapped to the process space of the system memory; thus, the dynamic programming language system can quickly access the content of the item corresponding to the item of the file header. And then, the structure of the file header can be utilized to map the storage contents in the storage pages in the pre-compiled file to the process space of the system memory in sequence and link the storage contents to the memory management unit, namely, the addresses corresponding to the pages are added into the memory management unit, so that when the dynamic language system accesses the addresses in the pages, the dynamic language system can access the contents generated by the dynamic language system as normal.
In an embodiment, the method may further comprise the steps of:
s209, traversing other objects in the memory management unit, and judging whether the other objects comprise non-reclaimed objects.
In this step, the "other object" may be an object other than the object that has been marked. As can be seen from the foregoing steps, the marked object includes a first object in the designated area, a second object referenced by the first object, and a sub-object of the second object in an alternative embodiment, in addition to these, there may be a plurality of other objects in the memory management unit, and it may be determined whether the other objects include non-reclaimed objects, such as live objects, according to a determination rule set by the developer. When non-reclaimed objects are present, these non-reclaimed objects can be marked according to the same marking method.
In an embodiment, the method may further comprise the steps of:
s210, reclaiming other areas except the area where the non-reclaiming object is located in the memory management unit.
In this step, the other areas than the area where the non-reclaimed object is determined to be obtained in step S209 may be reclaimed, so as to realize the reuse of the system memory space.
In an embodiment of the present invention, the "before recovery of the memory management unit" in step S204 includes loading the pre-compiled file corresponding to the source program into the designated area of the memory management unit and/or running the source program. The step of loading the pre-compiled file corresponding to the source program into the designated area of the memory management unit may be implemented by the sub-steps of:
S2041, loading an advanced compiling file to a designated area of the memory management unit;
S2042, marking the designated area as an advanced compiling area;
And S2043, initializing the advanced compiling region.
The loading of the advanced compilation file into the designated area of the memory management unit may be achieved by:
Reading in a file header and mapping the file header to a system space; mapping the advanced compiling file to a system storage space of a dynamic programming language system according to the corresponding number of source programs, the number of public objects and the storage space information occupied by compiling data in the file header; and loading the advanced compiled file mapped to the memory space to the memory management unit.
In the step of reading in the file header and mapping the file header to the system space, the file header can be read and mapped to the process space of the system memory; thus, the dynamic programming language system can quickly access the content of the item corresponding to the item of the file header. And then, the structure of the file header can be utilized to map the storage contents in the storage pages in the pre-compiled file to the process space of the system memory in sequence and link the storage contents to the memory management unit, namely, the addresses corresponding to the pages are added into the memory management unit, so that when the dynamic language system accesses the addresses in the pages, the dynamic language system can access the contents generated by the dynamic language system as normal.
In the step of marking the specified area as the pre-compiled area in the substep S2042, after the pre-compiled file is loaded into the specified area of the memory management unit, the specified area may be marked as the pre-compiled area, that is, the area storing the pre-compiled file.
In substep S2043, the early compile region may be initialized.
Initializing the system to initialize the system environment to the extent that the source program can be run, such as releasing unnecessary variables, allocating system space for the dynamic programming system, etc.; the source program may be run after initialization.
In the above step S204, the process of running the source program may be implemented as follows: because the advanced compiling file corresponding to the compiling data generated by the source program is already existing in the memory management unit, the source program can directly run in the step of running the source program after initialization, the steps of reading in byte codes, decoding, reverse serialization and reconstructing objects are not required to be executed, and the occupied amount of the system memory is reduced. The dynamic language program can perform dynamic actions such as introducing new functions, deleting existing functions and the like when running, and can dynamically generate codes such as byte codes or local codes, so that during running, whether the modified address area points to an area outside a specified area can be checked, and whether a first object in the specified area references a second object outside the specified area can be determined.
In an embodiment, the step S204 of determining whether the first object included in the file references the second object outside the specified area where the file is located may include the following sub-steps:
S2041, respectively judging whether pointers of a plurality of first objects included in the advanced compiling file point to areas outside the designated area;
s2042, when it is determined that the pointer points to an area other than the specified area, determining that the first object references a second object other than the specified area.
In sub-steps S2041 and S2042, for example, during the loading of the pre-compiled file into the specified region of the memory management unit, it may be determined whether the referenced second object is within the specified region by the region pointed to by the pointer of the first object. For example, the address information of the specified area may be acquired in advance, and the address of the second object may be compared with the address information of the specified area to determine whether the second object is within the specified area.
In one embodiment, the step S204 of determining whether the first object included in the file references the second object outside the specified area where the file is located includes:
S2043, when the address of the first object in the advanced compiling file is modified, judging whether the modified address of the first object is located in an area outside the designated area;
S2044, when the address of the modified object is judged to be located in the area outside the designated area, determining that the first object references a second object outside the designated area.
In sub-steps S2043 to S2044, for example, during running of the source program, after detecting that the address of the first object is modified, for example, by a developer, it is determined whether the modified address of the first object is still within the specified area. For example, the address information of the designated area may be obtained in advance, and the modified address of the first object may be compared with the address information of the designated area to determine whether the modified address of the first object is within the designated area.
Fig. 4 is a schematic flow chart of a garbage collection method according to a first embodiment of the present invention. In fig. 4, the execution to reclamation of the precompiled file is divided into three stages, load, run and reclamation, respectively.
As shown in fig. 4, in the loading stage, in step S11, the pre-compiled file may be read and stored in the designated area of the memory management unit. The designated area may be initialized in step S12, e.g., releasing unwanted variables, allocating system space for the dynamic programming system, etc., and in step S13, when a first object of the designated area references a second object outside the designated area, the address of the second object may be recorded.
In the running phase, the source program of the pre-compiled file is run in step S21, and when it is confirmed that the address of the first object is modified and the modified address is located outside the designated area in step S22, the address where the first object is modified in the running is recorded.
In the garbage collection stage, first, a first object in a designated area is marked as a non-collection object in step S31, and in optional step S32, a depth traversal is performed from an address of a second object, a plurality of sub-objects of the second object are obtained, and the second object and the plurality of sub-objects are marked. Other objects may be traversed and non-reclaimed objects marked in step S33. In step S34, the memory is purged and recovered for the unlabeled object.
In summary, the method for optimizing garbage collection provided in the embodiment has at least the following advantages:
According to the scheme provided by the application, according to the characteristic that the object storing the appointed area of the pre-compiled file is not required to be recycled by garbage, the appointed area of the pre-compiled file and the area related to the pre-compiled file are not required to be traversed during garbage recycling, so that the whole object in the memory management unit is not required to be marked like the prior art, and a great part of marking time is saved.
In addition, the method for optimizing garbage collection provided by the embodiment at least further comprises the following advantages:
In an alternative embodiment of the invention, addresses of all objects pointing to a non-designated area from the object storing the pre-compiled file are recorded in the loading process of the storing the pre-compiled file and in the running process of the pre-compiled file, the recorded objects are taken as root nodes in the garbage collection process, all child nodes are deeply traversed and marked as active objects, and therefore the non-designated area objects referenced by the objects storing the designated area of the pre-compiled file are prevented from being cleared by errors in the garbage collection process.
Third embodiment
In a third embodiment of the present invention, a garbage recycling method is provided, and fig. 5 is a flowchart of a garbage recycling method according to an embodiment. As shown in fig. 5, the method includes:
S301, judging whether a plurality of first objects contained in a file refer to a second object outside a designated area where the file is located;
in this step, the file may be loaded into a designated area of the memory management unit. Mapping the file to a system memory space of a dynamic programming language system, for example; and loading the file mapped to the memory space to the memory management unit.
In the mapping process, the designated area may be marked in the memory management unit. As described above, in the process of file loading, the execution body may determine whether each object in the file references an area other than the specified area.
The above-described "object" is a combination of code and data that can be regarded as one unit. An object may be a piece of an application, such as a control or a form. The entire application may also be an object. As described above, a pointer is an address in an object that points to a piece of memory. And when the address area pointed by the pointer of a certain object is judged to be an area outside the specified area, the second object referenced by the first object is considered to be an address area outside the specified area.
S302, in the case that one or more first objects are determined to reference a second object outside the specified area, recording the address of the second object;
In this step, when it is determined that the pointer of the first object points to an area outside the specified area, it is determined that the first object references a second object outside the specified area, and in order to prevent the address of the second object from being recovered by mistake later, in this step, the address of the second object may be recorded and stored in a storage area, for example, in a storage structure such as an existing RememberSet, storeBuffer, cardtable, array, list, or the like.
S304, determining the designated area and the area where the second object is located as a non-recycling area.
In the previous step, after the second objects are determined, addresses where the objects are located may be recorded in the storage space, and the second objects in the addresses may be marked. In this step, it may be determined that the areas corresponding to the objects are non-reclaimed areas based on the objects marked in step S302.
In addition, in the reclaimed memory management unit, since the designated area itself is a non-reclaimed area, the designated area as a whole may be regarded as a non-reclaimed area. In some embodiments, all the areas except the specified area and the area where the second object is located may be reclaimed, in other embodiments, the execution subject may mark other non-reclaimed areas according to other principles besides the specified area and the area where the second object is located, and skip the areas together during the reclaiming, and reclaim the areas except the marked areas.
In an alternative embodiment, the method may further include the steps of:
S303, determining a sub-object of the second object according to the address of the second object under the condition of recovering the memory management unit;
in this step, in order to prevent the memory management unit from occupying too much space of the memory management unit, the memory management unit may be reclaimed, the inactive object is cleaned, and the space is reclaimed. In the recycling process, starting from the address of the second object recorded in step S302, the child nodes of the second object may be traversed, and a plurality of child objects included in the second object may be determined. In one embodiment, the second object and each of its sub-objects may be marked as non-reclaimed objects to avoid that the area where the second object is located is later erroneously reclaimed.
S305, determining the address of the sub-object of the second object as a non-recycling area.
In this step, it may be determined that the child object of the second object is also a non-reclaimed object.
In an embodiment, the file may be a pre-compiled file, and the specified region may be a pre-compiled region. In other embodiments, the specified region may be a non-advance compiled region, and the specified region may incorporate other objects or regions, or may be a specific region specified by a developer. For example, the called frequency of the plurality of first objects in the file stored in the particular region is above a first threshold; the plurality of first objects references a second object outside the specified region less frequently than a second threshold. The first threshold may be, for example, an average value of the number of times all objects in the memory management unit are called; the second threshold is for example an average of the frequencies at which all objects in the memory management unit refer to external objects.
In summary, the garbage collection optimizing device provided in this embodiment has at least the following advantages:
According to the scheme provided by the application, according to the characteristic that the object in the designated area for storing the specific file is not required to be recycled by garbage, the designated area and the related area of the specific file are not required to be traversed during garbage recycling, so that the marking of all the objects in the memory management unit is not required like the prior art, and a great part of marking time is saved.
Fourth embodiment
A fourth embodiment of the present invention provides an optimizing apparatus for garbage collection, as shown in fig. 6, the apparatus includes:
a first object determining module 401, configured to determine, before reclaiming the memory management unit, whether a plurality of first objects included in the pre-compiled file reference a second object outside a specified area where the file is located;
A first recording module 402, configured to record an address of a second object outside the specified area if it is determined that one or more first objects reference the second object;
the first marking module 403 is configured to determine that the specified area and the area where the second object is located are non-reclaimed areas.
In summary, the garbage collection optimizing device provided in this embodiment has at least the following advantages:
According to the scheme provided by the application, according to the characteristic that the object storing the appointed area of the pre-compiled file is not required to be recycled by garbage, the appointed area of the pre-compiled file and the area related to the pre-compiled file are not required to be traversed during garbage recycling, so that the whole object in the memory management unit is not required to be marked like the prior art, and a great part of marking time is saved.
Fifth embodiment
A fifth embodiment of the present invention provides an optimizing apparatus for garbage collection, as shown in fig. 7, the apparatus includes:
A first object determining module 501, configured to determine, before reclaiming the memory management unit, whether a plurality of first objects included in the advanced compiled file reference a second object outside a specified area where the file is located;
A first recording module 502, configured to record an address of a second object, where it is determined that one or more first objects reference the second object outside the specified area;
the first marking module 504 is configured to determine that the specified area and the area where the second object is located are non-reclaimed areas.
In an alternative embodiment, the apparatus further comprises:
the first address determining module 503 is configured to determine, in the case of reclaiming the memory management unit, a child object of the second object according to the address of the second object.
In an alternative embodiment, the first marking module 504 may be further configured to determine an area where the child object of the second object is located as a non-reclaimed area.
In an alternative embodiment, the first sub-object determining module 503 is configured to:
and traversing all reachable nodes of the root node by taking the address of the second object as the root node, and taking the object of the reachable nodes as a child object of the second object.
In an alternative embodiment, the apparatus further comprises:
The first determining module 505 is configured to traverse other objects in the memory management unit and determine whether the other objects are non-reclaimed objects.
In an alternative embodiment, the apparatus further comprises:
The first reclamation module 506 is configured to reclaim the other area of the memory management unit except the area where the non-reclaimed object is located.
In an alternative embodiment, the first object determining module 501 includes:
The first judging submodule is used for judging whether pointers of a plurality of first objects included in the file point to areas outside the designated area or not respectively;
and the first determining submodule is used for determining that the first object references a second object outside the specified area when the pointer points to the area outside the specified area.
In an alternative embodiment, the first object determining module 501 includes:
the second judging submodule is used for judging whether the address of the object after modification is positioned in an area outside the appointed area or not when the address of the object in the file is modified;
And the second determining submodule is used for determining that the first object references a second object outside the designated area when the address of the modified object is judged to be located in the area outside the designated area.
In an alternative embodiment, the apparatus further comprises:
A compiled data generation module 507 for generating compiled data according to the source program;
A linking module 508, configured to link the compiled data to a memory management unit;
The advanced compilation file generating module 509 is configured to generate an advanced compilation file according to compilation data linked to the memory management unit.
In an alternative embodiment, before the memory management unit is recycled, the method includes:
In the process of loading the pre-compiled file corresponding to the source program into the designated area of the memory management unit, and/or,
During the running of the source program.
In summary, the garbage collection optimizing device provided in this embodiment has at least the following advantages:
According to the scheme provided by the application, according to the characteristic that the object storing the appointed area of the pre-compiled file is not required to be recycled by garbage, the appointed area of the pre-compiled file and the area related to the pre-compiled file are not required to be traversed during garbage recycling, so that the whole object in the memory management unit is not required to be marked like the prior art, and a great part of marking time is saved.
In addition, the optimizing device for garbage collection provided by the embodiment at least further comprises the following advantages:
In an alternative embodiment of the invention, addresses of all objects pointing to a non-designated area from the object storing the pre-compiled file are recorded in the loading process of the storing the pre-compiled file and in the running process of the pre-compiled file, the recorded objects are taken as root nodes in the garbage collection process, all child nodes are deeply traversed and marked as active objects, and therefore the non-designated area objects referenced by the objects storing the designated area of the pre-compiled file are prevented from being cleared by errors in the garbage collection process.
Sixth embodiment
A sixth embodiment of the present invention provides an optimizing apparatus for garbage collection, as shown in fig. 8, the apparatus comprising:
A second object determining module 601, configured to determine whether a plurality of first objects included in a file refer to a second object outside a specified area where the file is located;
a second recording module 602, configured to record an address of a second object, where it is determined that one or more first objects reference the second object outside the specified area;
And a second marking module 604, configured to determine that the specified area and the address where the second object is located are non-reclaimed areas.
Optionally, the apparatus may further comprise a second sub-object determining module 603 configured to determine a sub-object of the second object according to an address of the second object.
The second marking module 604 may be further configured to determine an address where a child object of the second object is located as a non-reclaimed area
In summary, the garbage collection optimizing device provided in this embodiment has at least the following advantages:
According to the scheme provided by the application, according to the characteristic that the object storing the appointed area of the pre-compiled file is not required to be recycled by garbage, the appointed area of the pre-compiled file and the area related to the pre-compiled file are not required to be traversed during garbage recycling, so that the whole object in the memory management unit is not required to be marked like the prior art, and a great part of marking time is saved.
In addition, the optimizing device for garbage collection provided by the embodiment at least further comprises the following advantages:
In an alternative embodiment of the invention, addresses of all objects pointing to a non-designated area from the object storing the pre-compiled file are recorded in the loading process of the storing the pre-compiled file and in the running process of the pre-compiled file, the recorded objects are taken as root nodes in the garbage collection process, all child nodes are deeply traversed and marked as active objects, and therefore the non-designated area objects referenced by the objects storing the designated area of the pre-compiled file are prevented from being cleared by errors in the garbage collection process.
For the device embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and reference is made to the description of the method embodiments for relevant points.
Fig. 9 is a schematic hardware structure of a terminal device according to an embodiment of the present application. As shown in fig. 9, the terminal device may include an input device 90, a processor 91, an output device 92, a memory 93, and at least one communication bus 94. The communication bus 94 is used to enable communication connections between the elements. The memory 93 may comprise a high-speed RAM memory or may further comprise a non-volatile memory NVM, such as at least one magnetic disk memory, in which various programs may be stored for performing various processing functions and implementing the method steps of the present embodiment.
Alternatively, the processor 91 may be implemented as, for example, a central processing unit (Central Processing Unit, abbreviated as CPU), an Application Specific Integrated Circuit (ASIC), a Digital Signal Processor (DSP), a Digital Signal Processing Device (DSPD), a Programmable Logic Device (PLD), a Field Programmable Gate Array (FPGA), a controller, a microcontroller, a microprocessor, or other electronic components, and the processor 91 is coupled to the input device 90 and the output device 92 through wired or wireless connection.
Alternatively, the input device 90 may include a variety of input devices, for example, may include at least one of a user-oriented user interface, a device-oriented device interface, a programmable interface to software, a camera, and a sensor. Optionally, the device interface facing the device may be a wired interface for data transmission between devices, or may be a hardware insertion interface (such as a USB interface, a serial port, etc.) for data transmission between devices; alternatively, the user-oriented user interface may be, for example, a user-oriented control key, a voice input device for receiving voice input, and a touch-sensitive device (e.g., a touch screen, a touch pad, etc. having touch-sensitive functionality) for receiving user touch input by a user; optionally, the programmable interface of the software may be, for example, an entry for a user to edit or modify a program, for example, an input pin interface or an input interface of a chip, etc.; optionally, the transceiver may be a radio frequency transceiver chip, a baseband processing chip, a transceiver antenna, etc. with a communication function. An audio input device such as a microphone may receive voice data. The output device 92 may include a display, audio, etc.
In this embodiment, the processor of the terminal device may include functions for executing each module of the data processing apparatus in each device, and specific functions and technical effects may be referred to the above embodiments and are not described herein again.
Fig. 10 is a schematic hardware structure of a terminal device according to another embodiment of the present application. Fig. 10 is a diagram of one particular embodiment of the implementation of fig. 9. As shown in fig. 10, the terminal device of the present embodiment includes a processor 101 and a memory 102.
The processor 101 executes computer program code stored in the memory 102 to implement the garbage collection optimization method of fig. 1 to 5 in the above-described embodiment.
The memory 102 is configured to store various types of data to support operations at the terminal device. Examples of such data include instructions for any application or method operating on the terminal device, such as messages, pictures, video, etc. The memory 102 may include random access memory (random access memory, abbreviated as RAM) and may also include non-volatile memory (non-volatile memory), such as at least one disk memory.
Optionally, a processor 101 is provided in the processing assembly 100. The terminal device may further include: a communication component 103, a power supply component 104, a multimedia component 105, an audio component 106, an input/output interface 107 and/or a sensor component 108. The components and the like specifically included in the terminal device are set according to actual requirements, which are not limited in this embodiment.
The processing component 100 generally controls the overall operation of the terminal device. The processing assembly 100 may include one or more processors 101 to execute instructions to perform all or part of the steps of the methods of fig. 1-7 described above. Further, the processing component 100 may include one or more modules that facilitate interactions between the processing component 100 and other components. For example, the processing component 100 may include a multimedia module to facilitate interaction between the multimedia component 105 and the processing component 100.
The power supply assembly 104 provides power to the various components of the terminal device. The power components 104 can include a power management system, one or more power sources, and other components associated with generating, managing, and distributing power for the terminal devices.
The multimedia component 105 comprises a display screen between the terminal device and the user providing an output interface. In some embodiments, the display screen may include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the display screen includes a touch panel, the display screen may be implemented as a touch screen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensor may sense not only the boundary of a touch or slide action, but also the duration and pressure associated with the touch or slide operation.
The audio component 106 is configured to output and/or input audio signals. For example, the audio component 106 includes a Microphone (MIC) configured to receive external audio signals when the terminal device is in an operational mode, such as a speech recognition mode. The received audio signals may be further stored in the memory 102 or transmitted via the communication component 103. In some embodiments, the audio component 106 further comprises a speaker for outputting audio signals.
The input/output interface 107 provides an interface between the processing assembly 100 and peripheral interface modules, which may be click wheels, buttons, etc. These buttons may include, but are not limited to: volume button, start button and lock button.
The sensor assembly 108 includes one or more sensors for providing status assessment of various aspects for the terminal device. For example, the sensor assembly 108 may detect the open/closed state of the terminal device, the relative positioning of the assembly, the presence or absence of user contact with the terminal device. The sensor assembly 108 may include a proximity sensor configured to detect the presence of nearby objects in the absence of any physical contact, including detecting the distance between the user and the terminal device. In some embodiments, the sensor assembly 108 may also include a camera or the like.
The communication component 103 is configured to facilitate communication between the terminal device and other devices in a wired or wireless manner. The terminal device may access a wireless network based on a communication standard, such as WiFi,2G or 3G, or a combination thereof. In one embodiment, the terminal device may include a SIM card slot, where the SIM card slot is used to insert a SIM card, so that the terminal device may log into a GPRS network, and establish communication with a server through the internet.
From the above, the communication component 103, the audio component 106, the input/output interface 107, and the sensor component 108 in the embodiment of fig. 10 can be implemented as the input device in the embodiment of fig. 9.
The embodiment of the application provides terminal equipment, which comprises: one or more processors; and one or more machine-readable media having instructions stored thereon, which when executed by the one or more processors, cause the terminal device to perform a method as described in one or more of the embodiments of the application.
In this specification, each embodiment is described in a progressive manner, and each embodiment is mainly described by differences from other embodiments, and identical and similar parts between the embodiments are all enough to be referred to each other.
While preferred embodiments of the present application have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. It is therefore intended that the following claims be interpreted as including the preferred embodiment and all such alterations and modifications as fall within the scope of the embodiments of the application.
Finally, it is further noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or terminal that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or terminal. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or terminal device that comprises the element.
The above description of the method, the device, the terminal equipment and the machine-readable medium for optimizing garbage collection provided by the application applies specific examples to illustrate the principles and the implementation of the application, and the above examples are only used for helping to understand the method and the core idea of the application; meanwhile, as those skilled in the art will have variations in the specific embodiments and application scope in accordance with the ideas of the present application, the present description should not be construed as limiting the present application in view of the above.