Object allocation and positioning method, device, storage medium and electronic device

By collecting and analyzing the memory usage of objects in Java applications, generating class sorting instructions and embedding monitoring embedding, the cumbersome positioning problem of high-speed allocation of objects is solved, and convenient and efficient object allocation positioning and code-level automatic positioning is achieved.

CN117453182BActive Publication Date: 2025-04-29NETWORKBENCH SYST
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311319573.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-10-12
Publication Date
2025-04-29
Estimated Expiration
2043-10-12

AI Technical Summary

Technical Problem

The positioning process of high-speed allocation of objects in Java applications is complicated, insufficient information and data, and untimely manual intervention, resulting in misjudgment and inefficient positioning.

Method used

By obtaining the collection indication information, the objects in M ​​classes are collected N times of memory usage, and weighted sum to generate class sorting indication information. The target class is selected and the object is embedded to create monitoring embed codes, and the object allocation indication data is generated to facilitate the positioning of object allocation problems.

Benefits of technology

It realizes the convenience of object allocation positioning, reduces manual intervention, improves positioning efficiency and accuracy, and can automatically locate the root causes of code-level problems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117453182B_ABST
    Figure CN117453182B_ABST
Patent Text Reader

Abstract

The present invention provides an object allocation and positioning method, device, storage medium and electronic device, wherein the method comprises: based on the collection indication information, respectively collecting the memory usage of the objects corresponding to each class in M ​​classes N times to obtain the N memory usage corresponding to each class; respectively performing weighted summation on the N memory usage corresponding to each class to obtain the class sorting indication information of each class, and selecting at least one target class from the M classes based on the class sorting indication information of each class; respectively embedding the object creation monitoring embedded code into each target class included in at least one target class to obtain each embedded target class; respectively generating the object allocation indication data corresponding to each embedded target class based on the call stack set corresponding to each embedded target class, and one object allocation indication data is used to realize the object allocation and positioning under the corresponding embedded target class. The embodiment of the present invention can conveniently perform object allocation and positioning.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to an object allocation and positioning method, device, storage medium and electronic equipment. Background Art

[0002] At present, the high-rate allocation problem of JVM (Java Virtual Machine, Java (an object-oriented programming language) virtual machine) objects has received widespread attention. The high-rate allocation problem of JVM objects refers to the situation where objects are frequently created and destroyed in Java applications, resulting in high memory management overhead; this situation may cause the performance of the application to deteriorate, because frequent object allocation and garbage collection (GC) operations will take up a lot of CPU (Central Processing Unit, central processing unit) time, and will stop the word (STW, pause), increase application response time, reduce application throughput, and increase unnecessary memory overhead. Based on this, the prior art usually takes a memory dump (dump file) when a large amount of data is observed to indicate that there may be a high-rate memory allocation problem of objects, and when the problem continues to occur, the stack allocation information and surviving object information of the memory dump are analyzed to locate the problem, and there are problems such as insufficient information data or untimely manual intervention (such as taking a memory dump file after garbage collection), and it is necessary to take a memory dump file and check it multiple times to reduce the misjudgment of the root cause of the problem, resulting in a cumbersome object allocation location process. Based on this, how to conveniently perform object allocation and positioning has become a research hotspot. Summary of the invention

[0003] In view of this, an embodiment of the present invention provides an object allocation and positioning method, device, storage medium and electronic device to solve the problem that the object allocation and positioning process is relatively cumbersome; that is, an embodiment of the present invention can conveniently perform object allocation and positioning, that is, it can conveniently generate object allocation indication data, thereby realizing object allocation and positioning under the corresponding embedded target class through any object allocation indication data.

[0004] According to one aspect of the present invention, a method for allocating and locating an object is provided, the method comprising:

[0005] Acquire collection indication information, and based on the collection indication information, respectively collect N memory usages of objects corresponding to each class in the M classes to obtain N memory usages corresponding to each class, where M and N are both positive integers;

[0006] Performing weighted summation on the N memory usages corresponding to the various classes to obtain class ranking indication information of the various classes, and selecting at least one target class from the M classes based on the class ranking indication information of the various classes, wherein the class ranking indication information of the target class is greater than the ranking indication threshold;

[0007] Determine an object creation monitoring embedded code, and embed the object creation monitoring embedded code into each target class included in the at least one target class, respectively, to obtain each embedded target class, wherein when an embedded target class is called to create an object, it supports generating a corresponding call stack, and a call stack is used to indicate a call link of a corresponding object;

[0008] Determine the call stack sets of each embedded target class within the target time range, and generate object allocation indication data corresponding to each embedded target class based on the call stack sets corresponding to each embedded target class, and one object allocation indication data is used to realize object allocation positioning under the corresponding embedded target class.

[0009] According to another aspect of the present invention, there is provided an object allocation and positioning device, the device comprising:

[0010] An acquisition unit, used for acquiring collection indication information;

[0011] A processing unit, configured to collect N memory usages of objects corresponding to each of the M classes based on the collection indication information, to obtain N memory usages corresponding to each of the M classes, where M and N are both positive integers;

[0012] The processing unit is further configured to perform weighted summation on the N memory usages corresponding to the respective classes to obtain class ranking indication information of the respective classes, and select at least one target class from the M classes based on the class ranking indication information of the respective classes, wherein the class ranking indication information of the target class is greater than a ranking indication threshold;

[0013] The processing unit is further used to determine the object creation monitoring embedded code, and respectively embed the object creation monitoring embedded code into each target class included in the at least one target class to obtain each embedded target class, and when an embedded target class is called to create an object, it supports generating a corresponding call stack, and a call stack is used to indicate a call link of the corresponding object;

[0014] The processing unit is also used to determine the call stack sets of each embedded target class within the target time range, and generate object allocation indication data corresponding to each embedded target class based on the call stack sets corresponding to each embedded target class. One object allocation indication data is used to realize object allocation positioning under the corresponding embedded target class.

[0015] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising a processor and a memory storing a program, wherein the program comprises instructions, and when the instructions are executed by the processor, the processor executes the above-mentioned method.

[0016] According to another aspect of the present invention, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable a computer to execute the above-mentioned method.

[0017] The embodiment of the present invention can obtain the collection indication information, and based on the collection indication information, respectively collect the memory usage of the objects corresponding to each class in the M classes N times, and obtain the N memory usage corresponding to each class, where M and N are both positive integers. Then, the N memory usage corresponding to each class can be weighted and summed to obtain the class sorting indication information of each class, and based on the class sorting indication information of each class, at least one target class can be selected from the M classes, and the class sorting indication information of a target class is greater than the sorting indication threshold; further, the object creation monitoring embedding code can be determined, and the object creation monitoring embedding code can be respectively embedded into each target class included in at least one target class to obtain each embedded target class, and when an embedded target class is called to create an object, it supports the generation of a corresponding call stack, and a call stack is used to indicate the call link of the corresponding object. Based on this, the call stack set of each embedded target class within the target time range can be determined, and based on the call stack set corresponding to each embedded target class, the object allocation indication data corresponding to each embedded target class is generated, and the object allocation indication data is used to realize the object allocation positioning under the corresponding embedded target class. It can be seen that the embodiment of the present invention can conveniently generate object allocation indication data, thereby conveniently realizing object allocation positioning through any object allocation indication data. That is to say, the embodiment of the present invention can conveniently perform object allocation positioning, that is, it can realize automatic positioning of the root cause of the problem at the code level. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Further details, features and advantages of the invention are disclosed in the following description of exemplary embodiments in conjunction with the accompanying drawings, in which:

[0019] Figure 1 A schematic flow chart of an object allocation and positioning method according to an exemplary embodiment of the present invention is shown;

[0020] Figure 2 A schematic flow chart of another object allocation and positioning method according to an exemplary embodiment of the present invention is shown;

[0021] Figure 3A schematic diagram of a timing task according to an exemplary embodiment of the present invention is shown;

[0022] Figure 4 A schematic diagram of obtaining object histogram data according to an exemplary embodiment of the present invention is shown;

[0023] Figure 5 A schematic diagram of creating object monitoring according to an exemplary embodiment of the present invention is shown;

[0024] Figure 6 A schematic block diagram of an object allocation and positioning device according to an exemplary embodiment of the present invention is shown;

[0025] Figure 7 A block diagram of an exemplary electronic device that can be used to implement an embodiment of the present invention is shown. DETAILED DESCRIPTION

[0026] Embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present invention. It should be understood that the drawings and embodiments of the present invention are only for exemplary purposes and are not intended to limit the scope of protection of the present invention.

[0027] It should be understood that the various steps described in the method embodiments of the present invention may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present invention is not limited in this respect.

[0028] The term "including" and its variations used in this document are open inclusions, that is, "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one other embodiment"; the term "some embodiments" means "at least some embodiments". Relevant definitions of other terms will be given in the following description. It should be noted that the concepts of "first", "second", etc. mentioned in the present invention are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.

[0029] It should be noted that the modifications of "one" and "plurality" mentioned in the present invention are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise clearly indicated in the context, it should be understood as "one or more".

[0030] The names of the messages or information exchanged between multiple devices in the embodiments of the present invention are only used for illustrative purposes, and are not used to limit the scope of these messages or information.

[0031] It should be noted that the execution subject of the object allocation and positioning method provided in the embodiment of the present invention may be one or more electronic devices, and the present invention does not limit this; wherein, the electronic device may be a terminal (i.e., a client) or a server, then when the execution subject includes multiple electronic devices, and the multiple electronic devices include at least one terminal and at least one server, the object allocation and positioning method provided in the embodiment of the present invention may be jointly executed by the terminal and the server. Accordingly, the terminal mentioned here may include but is not limited to: smart phones, tablet computers, laptop computers, desktop computers, smart watches, smart voice interaction devices, smart home appliances, vehicle terminals, aircraft, and the like. The server mentioned here may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing (cloud computing), cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and basic cloud computing services such as big data and artificial intelligence platforms, and the like.

[0032] Based on the above description, an embodiment of the present invention proposes an object allocation and positioning method, which can be executed by the electronic device (terminal or server) mentioned above; or, the object allocation and positioning method can be executed by the terminal and the server together. For the convenience of explanation, the following description is taken as an example of an electronic device executing the object allocation and positioning method; Figure 1 As shown, the object allocation and positioning method may include the following steps S101-S104:

[0033] S101, obtaining collection indication information, and based on the collection indication information, collecting memory usage N times for objects corresponding to each class in M ​​classes, to obtain N memory usage corresponding to each class, where M and N are both positive integers.

[0034] The collection indication information may be used to indicate the collection rules for N memory usage collections, and one memory usage is used to indicate the memory usage of an object corresponding to a corresponding class at a collection moment (i.e., used to indicate the memory usage of all unrecycled objects (i.e., undestroyed objects) created by calling the corresponding class). Collecting N memory usages of objects corresponding to each class may refer to: collecting N memory usages of objects corresponding to each class.

[0035] In one embodiment, the collection indication information may include a collection frequency and a collection number (i.e., the value of N). In this case, the electronic device may collect memory usage for objects corresponding to each class N times according to the collection frequency and the collection number; in this case, the collection duration may be calculated by the collection frequency and the collection number. For example, assuming that the collection frequency and the collection number in the collection indication information are 2 and 10 respectively, and assuming that the unit of the collection frequency is: times / minute, and the unit of the collection number is: times, that is, at this time, the collection frequency can be used to indicate 2 collections per minute (i.e., 1 minute may include 2 collection moments), and the collection number can be used to indicate a total of 10 collections (i.e., the value of N is 10). In this case, the electronic device may collect memory usage for objects corresponding to each class twice per minute, until 10 memory usage collections are completed for objects corresponding to each class. Optionally, the collection frequency and the collection number may be set according to experience or according to actual needs, and the present invention is not limited to this.

[0036] In another embodiment, the collection indication information may include a collection frequency and a collection duration. In this case, the electronic device may collect memory usage for each object corresponding to each class N times according to the collection frequency and the collection duration. It should be understood that the collection frequency and the collection duration may be used to reflect the number of collections, that is, may be used to indicate the value of N. For example, assuming that the collection frequency and the collection duration in the collection indication information are 2 and 5 respectively, and assuming that the unit of the collection frequency is: times / minute, and the unit of the collection duration is: minute, that is, at this time, the collection frequency may be used to indicate 2 collections per minute, and the collection duration may be used to indicate a total collection of 5 minutes; in this case, the electronic device may collect memory usage for each object corresponding to each class twice per minute, until the memory usage collection for each object corresponding to each class is completed for 5 minutes, at which time it can be known that the number of collections is 10. Optionally, the collection duration may be set according to experience or according to actual needs, and the present invention is not limited thereto.

[0037] In another embodiment, the collection indication information may only include the number of collections, and the electronic device may randomly select N collection moments within a collection time range with a collection time of a preset collection time based on the number of collections, so as to collect memory usage N times for objects corresponding to each class at the N collection moments, and so on. Optionally, the preset collection time may be set based on experience or actual needs, and the present invention does not limit this. Among them, the collection time range may refer to the time range from the start time of memory usage collection to the collection time.

[0038] In summary, the collection indication information can be used to indicate N collection moments, that is, the electronic device can determine N collection moments based on the collection indication information (i.e., determine N collection moments from the collection time range), such as 10 collection moments within 5 minutes (i.e., 10 collection moments within the collection time range with a collection duration of 5 minutes). Based on this, the memory usage of the objects corresponding to each class can be collected at each of the N collection moments, thereby realizing N memory usage collections for the objects corresponding to each class.

[0039] In the embodiment of the present invention, the acquisition method of the collection indication information may include but is not limited to the following:

[0040] In the first acquisition method, the electronic device can obtain the collection instruction information download link, and then use the collection instruction information downloaded based on the collection instruction information download link as the acquired collection instruction information. Alternatively, the electronic device can receive the collection instruction information sent by other devices.

[0041] In the second acquisition method, the electronic device itself stores at least one collection indication information, then the electronic device can select one collection indication information from the at least one collection indication information, and use the selected collection indication information as the above-mentioned acquired collection indication information. Optionally, the electronic device may include a monitoring module and an allocation and positioning module, and the collection indication information is stored in the monitoring module. In this case, the allocation and positioning module can receive the collection indication information issued by the monitoring module, thereby obtaining the collection indication information, etc.; based on this, the electronic device can perform operations such as memory usage collection and embedding of embedded codes through the allocation and positioning module; optionally, all operations of the execution module not described in the embodiment of the present invention can be performed through the allocation and positioning module. Optionally, the monitoring module can be an APM Server module (a memory that collects and displays data, processes and stores data); wherein APM is the abbreviation of Application Performance Management & Monitoring, which refers to application performance management.

[0042] In other embodiments, the monitoring module may also be located on other devices, which is not limited in the present invention; in this case, the monitoring module may also be called a backend, or the device where the monitoring module is located may be called a backend, and so on.

[0043] S102, performing weighted summation on the N memory usages corresponding to each class to obtain class ranking indication information of each class, and based on the class ranking indication information of each class, selecting at least one target class from the M classes, wherein the class ranking indication information of one target class is greater than the ranking indication threshold.

[0044] The memory usage may refer to the number of bytes of the occupied memory. Optionally, the weight of each memory usage in the N memory usages corresponding to any class may be the same or different, and the present invention does not limit this.

[0045] Optionally, for any of the M classes, the electronic device may perform an average operation on the N memory usages corresponding to any class, or may perform a sum operation on the N memory usages corresponding to any class to achieve a weighted summation (i.e., aggregation) of the N memory usages corresponding to any class; in this case, the weight of each of the N memory usages corresponding to any class is the same.

[0046] Optionally, the electronic device may determine the object allocation speed (i.e., rate) of the time period of each of the N collection moments, and determine the weight of each collection moment according to the object allocation speed of the time period of each collection moment, so that the weight of each collection moment increases with the increase of the object allocation speed, and perform weighted summation of the N memory usages corresponding to any class according to the weight at each collection moment; in this case, the weight of each memory usage may be different. The duration indicated by a time period may be a unit collection duration (such as one minute or two minutes, etc.); optionally, the above-mentioned collection frequency may be the number of collections required within the unit collection duration, that is, it may be used to indicate the number of collection moments within the unit collection duration. Alternatively, the electronic device may also randomly generate the weight of each of the N collection moments, and so on.

[0047] S103, determine the object creation monitoring embedded code, and embed the object creation monitoring embedded code into each target class included in at least one target class, to obtain each embedded target class. When an embedded target class is called to create an object, it supports generating a corresponding call stack, and a call stack is used to indicate the call link of the corresponding object.

[0048] Among them, the object creation monitoring embedding may refer to an embedding of a call stack for creating an object, so that when the embedded target class (i.e., the class in which the object creation monitoring embedding is embedded) is called to create an object, the electronic device may generate a corresponding call stack (i.e., the call stack of the corresponding object); that is, the object creation monitoring embedding may be used to monitor the creation of objects for each embedded target class. In an embodiment of the present invention, a call stack of an object may include a call link of the corresponding object, and a call link may include at least one call node, and a call node may be used to indicate that a section of code calls the construction method of an object of the corresponding class, that is, it may be used to indicate that a section of code calls the corresponding class to create an object.

[0049] Exemplarily, assume that the call link indicated by a call stack includes call node A, call node B and call node C, and call node A is the parent node of call node B, and call node B is the parent node of call node C. In this case, the call stack can be used to indicate that the code indicated by call node A called the code indicated by call node B, and then the code indicated by call node B called the code indicated by call node C, and the code indicated by call node C called the corresponding embedded target class to create the corresponding object.

[0050] S104, determine the call stack sets of each embedded target class within the target time range, and generate object allocation indication data corresponding to each embedded target class based on the call stack sets corresponding to each embedded target class, and one object allocation indication data is used to realize object allocation positioning under the corresponding embedded target class.

[0051] Optionally, the target time range can be a time range with a preset monitoring time; or, a target time range can be the time range it takes for the number of call stacks in a call stack set to reach a target threshold, that is, the time range it takes for an embedded target class to be called to create an object the number of times it reaches a target threshold, and so on; the present invention is not limited to this. Optionally, the preset monitoring time can be set according to experience or according to actual needs, and the present invention is not limited to this; accordingly, the target threshold can be set according to experience or according to actual needs, and the present invention is not limited to this. Optionally, the preset monitoring time can be less than or equal to the following monitoring time threshold, and the target threshold can be less than or equal to the following monitoring object creation count threshold.

[0052] Optionally, the target time ranges corresponding to any two embedded target classes may be the same or different, and the present invention is not limited to this; for example, when a target time range refers to a time range with a preset monitoring time, the start time and duration of the target time ranges corresponding to any two embedded target classes are the same, then the target time ranges corresponding to any two embedded target classes are the same; for example, when a target time range refers to the time range when the number of times the corresponding embedded target class is called to create an object reaches a target threshold, the target time ranges corresponding to any two embedded target classes may be different.

[0053] The embodiment of the present invention can obtain the collection indication information, and based on the collection indication information, respectively collect the memory usage of the objects corresponding to each class in the M classes N times, and obtain the N memory usage corresponding to each class, where M and N are both positive integers. Then, the N memory usage corresponding to each class can be weighted and summed to obtain the class sorting indication information of each class, and based on the class sorting indication information of each class, at least one target class can be selected from the M classes, and the class sorting indication information of a target class is greater than the sorting indication threshold; further, the object creation monitoring embedding code can be determined, and the object creation monitoring embedding code can be respectively embedded into each target class included in at least one target class to obtain each embedded target class, and when an embedded target class is called to create an object, it supports the generation of a corresponding call stack, and a call stack is used to indicate the call link of the corresponding object. Based on this, the call stack set of each embedded target class within the target time range can be determined, and based on the call stack set corresponding to each embedded target class, the object allocation indication data corresponding to each embedded target class is generated, and the object allocation indication data is used to realize the object allocation positioning under the corresponding embedded target class. It can be seen that the embodiment of the present invention can conveniently generate object allocation indication data, thereby conveniently realizing object allocation positioning through any object allocation indication data. That is to say, the embodiment of the present invention can conveniently perform object allocation positioning, that is, it can realize automatic positioning of the root cause of the problem at the code level.

[0054] Based on the above description, the embodiment of the present invention also proposes a more specific object allocation and positioning method. Accordingly, the object allocation and positioning method can be executed by the electronic device (terminal or server) mentioned above; or, the object allocation and positioning method can be executed by the terminal and the server together. For the convenience of explanation, the following description is taken as an example of an electronic device executing the object allocation and positioning method; please refer to Figure 2 The object allocation and positioning method may include the following steps S201-S206:

[0055] S201, obtaining collection indication information, and based on the collection indication information, collecting memory usage N times for objects corresponding to each class in M ​​classes, to obtain N memory usage corresponding to each class, where M and N are both positive integers.

[0056] In an embodiment of the present invention, the electronic device can obtain the object allocation speed within a time period every unit collection time (also referred to as a preset time), the time corresponding to a time period is equal to the unit collection time (that is, a time period refers to a time range with a time length of the unit collection time), and an object allocation speed is determined based on the amount of memory allocated within the corresponding time period, and the amount of memory allocated within a time period is the amount of allocated memory within the corresponding time period. When it is detected that the object allocation speed within the current time period is greater than the preset speed threshold, the above acquisition of the collection indication information is triggered; wherein, the current time period may refer to the time period corresponding to the object allocation speed obtained under the current system time, that is, it may refer to the time period closest to the current system time, that is, the distance between the current time period and the current system time is less than the distance between other time periods and the current system time, and the current time period and other time periods are both time periods before the current system time. Optionally, the preset speed threshold may be set according to experience or according to actual needs, and the present invention does not limit this.

[0057] It can be seen that the acquisition of object allocation speed can be a timed task, which is triggered once for each unit of collection time (such as once per minute). Specifically, for the object allocation speed within any time period, the electronic device can initialize the allocated memory amount (that is, initialize the allocated memory amount at the start time of any time period), and starting from the start time of any time period, when monitoring the occurrence of the current garbage collection event (GCEvent), determine the initial usage of the storage area before the start of the current garbage collection event (that is, the storage area usage before the start of the current garbage collection event); and determine the historical usage of the storage area, the historical usage of the storage area is the storage area usage after the last garbage collection event (that is, the storage area usage at the end of the last event). Among them, the storage area can refer to the young area (that is, the young generation or the new generation). This is because when the heap area is allocated, the new object (that is, the newly created object) will be stored in the young area, so the storage area usage can refer to the size of the young area. It should be understood that since the end time of a time period is the start time of the next time period of the time period, after obtaining the allocated memory amount in a time period, the allocated memory amount can be initialized to obtain the allocated memory amount in the next time period; optionally, at the start time of any time period, the electronic device can initialize the allocated memory amount to 0 (i.e. reset to 0), that is, after obtaining the allocated memory amount in the previous time period, the allocated memory amount can be initialized to 0. Optionally, the electronic device can monitor garbage collection events in the JVM through a JMX (Java Management Extensions) listener.

[0058] Based on this, the electronic device can add the difference between the initial usage of the current event of the storage area and the historical usage of the storage area (i.e. the total amount of memory allocated between the two garbage collection events) to the allocated memory, where the allocated memory can also be called Allocated Bytes. Then, the usage of the storage area at the end of the current event after the current garbage collection event ends can be used to update the historical usage of the storage area until the end time of any time period is reached, so as to obtain the object allocation speed within any time period based on the allocated memory (i.e. the allocated memory when the end time of any time period is reached). Among them, the allocated memory within any time period can refer to the allocated memory when the end time of any time period is reached.

[0059] Optionally, when obtaining the object allocation speed within any time period based on the allocated memory amount, the electronic device may use the allocated memory amount as the object allocation speed within any time period; or, the electronic device may perform a mean operation on the allocated memory amount based on the unit collection duration to obtain the object allocation speed within any time period, such as converting the allocated memory amount within any time period into the object allocation speed with seconds as the unit duration. At this time, the object allocation speed within any time period may refer to the amount of memory allocated per second in any time period, and so on; the present invention is not limited to this.

[0060] Optionally, the electronic device may report the object allocation speed in each time period to the monitoring module through the allocation positioning module; or, the electronic device may report the allocated memory amount in any time period to the monitoring module through the allocation positioning module, such as Figure 3 As shown, at this time, the object allocation speed in any time period can be determined by the monitoring module based on the amount of allocated memory in any time period. Correspondingly, the electronic device can determine whether the object allocation speed in the current time period is greater than the preset speed threshold through the monitoring module, so that when it is detected that the object allocation speed in the current time period is greater than the preset speed threshold, the collection indication information can be sent to the allocation positioning module, so that the allocation positioning module can obtain the collection indication information, and then based on the collection indication information, the memory usage of the objects corresponding to each class can be collected N times. It should be understood that Figure 3 The execution process of the scheduled task is only exemplarily shown, and the present invention is not limited to this; for example, the electronic device may not include a monitoring module and / or an allocation and positioning module, and may directly detect whether the object allocation speed in any time period is greater than a preset speed threshold, or detect whether the object allocation speed in any time period is greater than a preset speed threshold through the allocation and positioning module. In this case, the electronic device may not report the allocated memory amount or object allocation speed in any time period, and so on.

[0061] In other embodiments, when the monitoring module is located in other devices, the device where the monitoring module is located may also be referred to as the back end. That is, the electronic device may report the amount of allocated memory or the object allocation speed in each time period to the back end so that the back end can determine whether the object allocation speed in the current time period is greater than a preset speed threshold. Optionally, the device where the monitoring module is located may be a terminal or a server, and the present invention is not limited to this.

[0062] Further, the collection indication information can be used to indicate the collection rules of the object histogram, that is, a memory usage can be collected through the corresponding object histogram data. Based on this, when the memory usage of the objects corresponding to each class in the M classes is collected N times based on the collection indication information, and the N memory usage corresponding to each class is obtained, the electronic device can determine N histogram collection moments (that is, the above-mentioned collection moments) based on the collection indication information, and obtain the object histogram data at each of the N histogram collection moments, and obtain N object histogram data. One object histogram data includes the memory usage of each class in the M classes at the corresponding histogram collection moment; based on this, the N memory usage corresponding to each class can be determined from the N object histogram data (that is, the memory usage of each class at each histogram collection moment is determined separately) to realize N memory usage collection for the objects corresponding to each class.

[0063] The horizontal axis of an object histogram data may be a class identifier (such as a class name or a class number, etc.) of each class, and the vertical axis may be a memory usage of each class at the corresponding histogram collection time.

[0064] Optionally, the electronic device can obtain the object histogram data through the APM Java Agent (a probe) according to the collection instruction information, and can use JMX to obtain the object histogram data, thereby returning N object histogram data to the monitoring module, such as Figure 4 As shown. Java Agent is a mechanism provided by the Java virtual machine that allows the bytecode of an application to be modified or enhanced through an agent when the application is started. This mechanism is often used to implement various types of code injection, performance monitoring, logging, AOP (Aspect Oriented Programming) and other functions. It should be noted that Figure 4 The implementation method of acquiring the object histogram data is only exemplified; for example, the collection instruction information may not be issued through the monitoring module; for another example, the object histogram data may not be reported, and so on.

[0065] S202, respectively perform weighted summation on the N memory usages corresponding to each class to obtain class ranking indication information of each class, and select at least one target class from the M classes based on the class ranking indication information of each class, wherein the class ranking indication information of one target class is greater than the ranking indication threshold.

[0066] In one embodiment, the sorting indication threshold may be determined based on the class sorting indication information of the reference class, and the reference class may refer to the class with the largest class sorting indication information among all classes except at least one target class in the M classes. In this case, the electronic device may determine the number of target classes (i.e., the number of target classes in at least one target class), and may sort each class in descending order according to the class sorting indication information to obtain a first sorting result; then, the first target class number classes may be selected from the first sorting result to obtain at least one target class, thereby realizing the selection of at least one target class from the M classes. Alternatively, the electronic device may sort each class in descending order according to the class sorting indication information to obtain a second sorting result; then, the second target class number classes may be selected from the second sorting result to obtain at least one target class, and so on. Optionally, the number of target classes may be set according to experience or according to actual needs, and the present invention is not limited to this.

[0067] Optionally, the electronic device may use the class sorting indication information of the baseline class as the sorting indication threshold; or, the electronic device may use the mean operation result between the class sorting indication information of the baseline class and the class sorting indication information of the critical class as the sorting indication threshold, where the critical class may refer to a target class with the smallest class sorting indication information in at least one target class, and so on; the present invention is not limited to this.

[0068] In another implementation, the sorting indication threshold may be set based on experience or actual needs, etc. In this case, the electronic device may select at least one target class from the M classes based on the sorting indication threshold and the class sorting indication information of each class; specifically, a class whose class sorting indication information is greater than the sorting indication threshold may be selected from the M classes, and each selected class may be used as a target class to obtain at least one target class; that is, for any class in the M classes, if the class sorting indication information of any class is greater than the sorting indication threshold, any class may be used as a target class to select at least one target class from the M classes.

[0069] From the above, it can be seen that the embodiment of the present invention can regard each target class as a class that may currently be allocated in a large amount of memory, that is, each target class may currently be allocated in a large amount of memory.

[0070] In the embodiment of the present invention, the N memory usages corresponding to each class correspond to P time periods, where P is a positive integer; wherein P time periods can constitute a collection cycle. For example, assuming that the value of N is 10, the collection frequency is 2, and the unit collection duration is 1 minute, then the memory usage of the object corresponding to any class can be collected twice per minute, so that 5 unit collection durations are required to complete 10 memory usage collections, and the value of P can be 5.

[0071] Based on this, the electronic device can obtain the object allocation speed in each of the P time periods, and based on the object allocation speed in each time period, determine whether the N memory usage corresponding to each class is credible (i.e., whether it is trustworthy); if the N memory usage corresponding to each class is credible, then trigger the execution of the above-mentioned weighted summation of the N memory usage corresponding to each class, obtain the class ranking indication information of each class, and then execute step S202 and subsequent other steps. It should be understood that if the N memory usage corresponding to each class is not credible, steps S202-S206, etc. may not be executed.

[0072] In a specific implementation, the electronic device may perform a mean operation on the object allocation speed in each time period to obtain speed judgment indication information. If the speed judgment indication information is greater than the speed judgment threshold, the N memory usage confidences corresponding to each class are determined; optionally, the speed judgment threshold may be set according to experience or according to actual needs, which is not limited in the present invention. Optionally, the speed judgment threshold may be the same as or different from the preset speed threshold, which is not limited in the present invention.

[0073] In another specific implementation, the electronic device may determine Q time periods from P time periods, and if the value of Q is greater than a preset quantity threshold, then N memory usage confidences corresponding to each class are determined, and the object allocation speed in each of the Q time periods is greater than the speed judgment threshold, and Q is a positive integer; that is, if the number of time periods in which the object allocation speed is greater than the speed judgment threshold in the P time periods is greater than the preset quantity threshold, then N memory usage confidences corresponding to each class may be determined, and so on. Optionally, the preset quantity threshold may be set according to experience or according to actual needs, and the present invention is not limited thereto.

[0074] S203, determine the object creation monitoring embedded code, and embed the object creation monitoring embedded code into each target class included in at least one target class, to obtain each embedded target class. When an embedded target class is called to create an object, it supports generating a corresponding call stack, and a call stack is used to indicate the call link of the corresponding object.

[0075] Optionally, the electronic device may embed the object creation monitoring code into the construction method of any target class to embed the object creation monitoring code into any target class.

[0076] Optionally, the electronic device may report the N memory usages corresponding to each class and / or the object allocation speed in each time period to the monitoring module through the allocation and positioning module, so that the monitoring module can determine whether the N memory usages corresponding to each class are credible, and then when the N memory usages corresponding to each class are credible, the monitoring rules and / or the object creation monitoring embedded code class are sent to the allocation and positioning module, so that the allocation and positioning module can execute the following determination of the object creation monitoring embedded code, and embed the object creation monitoring embedded code into each target class included in at least one target class, so as to realize the creation object monitoring of each embedded target class, such as Figure 5 As shown. Optionally, the monitoring rule can be used to indicate the monitoring indication threshold, and the object creation monitoring embedded code class can include the class identifier (such as class name or class number, etc.) of each target class. It should be understood that when the monitoring module can issue the object creation monitoring embedded code class, at least one target class can be selected by the monitoring module.

[0077] It should be noted that Figure 5 The implementation method of creating object monitoring is only shown by way of example, and the present invention is not limited to this; for example, the monitoring module may only issue monitoring rules, and the electronic device may select at least one target class through the allocation and positioning module; for another example, the object allocation indication data corresponding to each embedded target class may not be reported, and so on.

[0078] S204, determine the call stack sets of each embedded target class within the target time range, and generate object allocation indication data corresponding to each embedded target class based on the call stack sets corresponding to each embedded target class, and one object allocation indication data is used to realize object allocation positioning under the corresponding embedded target class.

[0079] Specifically, for any embedded target class, the electronic device can merge the call stacks in the call stack set corresponding to any embedded target class to obtain the object allocation indication data corresponding to any embedded target class. In other words, the electronic device can merge the call stacks of the same class to obtain the object allocation indication data corresponding to each embedded target class.

[0080] In one embodiment, one object allocation indication data may be flame graph data corresponding to the corresponding embedded target class, and one flame graph data is used to reflect the number of times each code segment in at least one code segment calls the corresponding embedded target class to create an object. In this case, each flame graph data can be used to troubleshoot the root cause of code that allocates a large amount of memory, that is, the flame graph data can be used to display which line of code (i.e., which section of code) calls the object more frequently, that is, which line of code calls the corresponding class more frequently to create an object, thereby realizing object allocation positioning.

[0081] In another implementation, an object allocation indication data may be a call count set corresponding to a corresponding embedded target class, and a call count set may include the number of times each code segment in at least one code segment calls the corresponding embedded target class to create an object, and so on.

[0082] In an embodiment of the present invention, the electronic device can display the object allocation indication data corresponding to each embedded target class; when an object allocation indication data is the flame graph data corresponding to the corresponding embedded target class, the electronic device can display each flame graph data. Optionally, the electronic device can also display the object allocation speed in each time period; and / or, display N object histogram data, etc. It can be seen that the embodiment of the present invention can intuitively show the customer (i.e., the user) which section of code creates a large number of objects, so that the user can optimize the code.

[0083] In other embodiments, when the monitoring module is located in other devices, the electronic device may report the object allocation indication data corresponding to each embedded target class to the device where the monitoring module is located, that is, report it to the monitoring module, so that the device where the monitoring module is located can display the object allocation indication data corresponding to each embedded target class through the monitoring module, and so on.

[0084] Furthermore, the electronic device may also update the object allocation indication data corresponding to each embedded target class; specifically, the electronic device may update the target time range corresponding to each embedded target class to update the call stack set of each embedded target class within the target time range, thereby updating the object allocation indication data corresponding to each embedded target class. Optionally, the electronic device may update the object allocation indication data corresponding to each embedded target class at a preset update time; wherein the preset update time may be set according to experience or according to actual needs, and the present invention does not limit this.

[0085] S205, determining monitoring indication information, where the monitoring indication information includes: monitoring duration and / or number of monitoring object creation times.

[0086] The monitoring indication information may be set according to experience or according to actual needs, and the present invention does not limit this.

[0087] S206: If the monitoring indication information reaches the monitoring indication threshold, each embedded target class is restored to a corresponding target class, thereby stopping the monitoring of each target class being called to create an object.

[0088] Optionally, the monitoring indication threshold may be set based on experience or actual needs, which is not limited in the present invention.

[0089] In one embodiment, when the monitoring indication information includes the monitoring duration, the monitoring indication threshold may include a monitoring duration threshold; in this case, if the monitoring duration reaches the monitoring duration threshold, it can be determined that the monitoring indication information reaches the monitoring indication threshold.

[0090] In another embodiment, when the monitoring indication information includes the number of monitoring object creation times, the monitoring indication threshold may include a monitoring object creation times threshold; in this case, if the monitoring object creation times reaches the monitoring object creation times threshold, it can be determined that the monitoring indication information reaches the monitoring indication threshold. Optionally, when the number of monitoring object creation times of each class in the W embedded target classes reaches the monitoring object creation times threshold, it can be determined that the monitoring object creation times reaches the monitoring object creation times threshold, where W is a positive integer. Optionally, the value of W can be 1 or 2, etc. Among them, the monitoring object creation times threshold can also be called the upper limit of monitoring times.

[0091] In another embodiment, when the monitoring indication information includes monitoring duration and the number of monitoring object creation times, the monitoring indication threshold may include a monitoring duration threshold and a monitoring object creation times threshold; in this case, if the monitoring duration reaches the monitoring duration threshold, and / or the number of monitoring object creation times reaches the monitoring object creation times threshold, then it can be determined that the monitoring indication information reaches the monitoring indication threshold, and so on.

[0092] It can be seen that when the embedded object creation monitoring embedding reaches a certain time (i.e., reaches the monitoring time threshold), and / or meets certain rules (such as the number of monitored object creation times reaches the monitoring object creation times threshold), the object monitoring will be stopped (i.e., the monitoring of each target class being called to create the object will be stopped), and the embedded target class can be restored. In summary, it can be seen that electronic devices can use Java Agent technology to first locate the existence of high-rate allocation problems through the object allocation speed in the current time period, and then obtain the memory usage occupied by objects under each class multiple times to select at least one target class and embed its construction method; further, the call stack can be obtained when creating an object, and multiple call stacks can be merged to obtain object allocation indication data, thereby helping to locate the root cause of the application's high-rate allocation problem.

[0093] After obtaining the collection indication information, the embodiment of the present invention can collect N memory usages of the objects corresponding to each class in the M classes based on the collection indication information to obtain N memory usages corresponding to each class, where M and N are both positive integers; then, the N memory usages corresponding to each class can be weighted and summed to obtain the class sorting indication information of each class, and at least one target class can be selected from the M classes based on the class sorting indication information of each class, and the class sorting indication information of a target class is greater than the sorting indication threshold; determine the object creation monitoring embedding, and embed the object creation monitoring embedding into each target class included in at least one target class to obtain each embedded target class, and when an embedded target class is called to create an object, it supports the generation of a corresponding call stack, and a call stack is used to indicate the call link of the corresponding object. Based on this, the call stack set of each embedded target class within the target time range can be determined, and based on the call stack set corresponding to each embedded target class, the object allocation indication data corresponding to each embedded target class is generated, and the object allocation indication data is used to realize the object allocation positioning under the corresponding embedded target class. Further, monitoring indication information can be determined, and the monitoring indication information includes: monitoring duration and / or the number of monitoring object creation times; if the monitoring indication information reaches the monitoring indication threshold, each embedded target class is restored to the corresponding target class, thereby stopping the monitoring of each target class being called to create an object, so as to end this monitoring and effectively save operating resources, and prevent the embedding from affecting the application performance. It can be seen that the embodiment of the present invention can conveniently perform object allocation positioning, thereby conveniently determining a large number of codes for creating objects, so that users can optimize the corresponding code. In addition, when it is detected that the object allocation speed in the current time period is greater than the preset speed threshold, the acquisition of collection indication information can be triggered, and when the N memory usage confidences corresponding to each class are determined, the weighted sum of the N memory usages corresponding to each class can be triggered to obtain the class sorting indication information of each class, so as to achieve automatic location of the root cause of the problem at the code level when the application has a high rate of memory allocation.

[0094] Based on the description of the above-mentioned related embodiments of the object allocation and positioning method, the embodiment of the present invention further proposes an object allocation and positioning device, which can be a computer program (including program code) running in an electronic device; Figure 6 As shown, the object allocation and positioning device may include an acquisition unit 601 and a processing unit 602. The object allocation and positioning device may execute Figure 1 or Figure 2 The object allocation and positioning method shown, that is, the object allocation and positioning device can run the above-mentioned units:

[0095] An acquisition unit 601 is used to acquire collection instruction information;

[0096] The processing unit 602 is configured to collect N memory usages of objects corresponding to each of the M classes based on the collection indication information, to obtain N memory usages corresponding to each of the M classes, where M and N are both positive integers.

[0097] The processing unit 602 is further configured to perform weighted summation on the N memory usages corresponding to the respective classes to obtain class ranking indication information of the respective classes, and select at least one target class from the M classes based on the class ranking indication information of the respective classes, wherein the class ranking indication information of the target class is greater than the ranking indication threshold;

[0098] The processing unit 602 is further used to determine an object creation monitoring embedded code, and respectively embed the object creation monitoring embedded code into each target class included in the at least one target class to obtain each embedded target class, and when an embedded target class is called to create an object, it supports generating a corresponding call stack, and a call stack is used to indicate a call link of the corresponding object;

[0099] The processing unit 602 is also used to determine the call stack sets of each embedded target class within the target time range, and generate object allocation indication data corresponding to each embedded target class based on the call stack sets corresponding to each embedded target class. One object allocation indication data is used to realize object allocation positioning under the corresponding embedded target class.

[0100] In one implementation, the N memory usages corresponding to each class correspond to P time periods, where P is a positive integer; the acquisition unit 601 may also be used to:

[0101] Obtaining the object allocation speed in each of the P time periods;

[0102] The processing unit 602 may also be used to:

[0103] Based on the object allocation speed in each time period, determining whether the N memory usages corresponding to each class are credible;

[0104] If the N memory usages corresponding to the various classes are reliable, the weighted summing of the N memory usages corresponding to the various classes is triggered to obtain class ranking indication information of the various classes.

[0105] In another implementation, when the processing unit 602 determines whether the N memory usages corresponding to each class are credible based on the object allocation speed in each time period, it can be specifically used to:

[0106] Performing a mean operation on the object allocation speeds in each time period to obtain speed judgment indication information, and if the speed judgment indication information is greater than a speed judgment threshold, determining N memory usage confidences corresponding to each class; or,

[0107] Q time periods are determined from the P time periods. If the value of Q is greater than a preset quantity threshold, N memory usage confidences corresponding to the various classes are determined. The object allocation speed in each of the Q time periods is greater than the speed judgment threshold, and Q is a positive integer.

[0108] In another implementation manner, the acquisition unit 601 may also be used to:

[0109] Obtaining an object allocation speed within a time period every unit collection time, wherein a time period corresponds to the unit collection time period, and an object allocation speed is determined based on an amount of memory allocated within the corresponding time period;

[0110] When it is detected that the object allocation speed in the current time period is greater than a preset speed threshold, the acquisition of the collection indication information is triggered.

[0111] In another implementation manner, when acquiring the object allocation speed in any time period, the acquisition unit 601 may be specifically used to:

[0112] Initialize the amount of allocated memory, and starting from the start time of any time period, when monitoring the occurrence of a current garbage collection event, determine the initial usage of the storage area before the start of the current garbage collection event;

[0113] Determine a historical usage of a storage area, where the historical usage of the storage area is the usage of the storage area after the last garbage collection event ends;

[0114] The difference between the initial usage of the storage area in the current event and the historical usage of the storage area is added to the allocated memory amount, and the end usage of the storage area in the current event after the current garbage collection event ends is used to update the historical usage of the storage area until the end time of any time period is reached, so as to obtain the object allocation speed within any time period based on the allocated memory amount.

[0115] In another implementation manner, the collection indication information is used to indicate the collection rule of the object histogram. When the processing unit 602 collects N memory usages of the objects corresponding to each class in the M classes based on the collection indication information and obtains the N memory usages corresponding to each class, it can be specifically used to:

[0116] Based on the collection indication information, determine N histogram collection moments;

[0117] Respectively acquiring object histogram data at each of the N histogram collection moments to obtain N object histogram data, wherein one object histogram data includes memory usage of each class in the M classes at the corresponding histogram collection moment;

[0118] From the N object histogram data, N memory usages corresponding to the respective classes are determined respectively, so as to collect N memory usages of the objects corresponding to the respective classes respectively.

[0119] In another implementation, an object allocation indication data is flame graph data corresponding to a corresponding embedded target class, and a flame graph data is used to reflect the number of times each code segment in at least one code segment calls the corresponding embedded target class to create an object.

[0120] In another implementation, the processing unit 602 may also be used to:

[0121] Determine monitoring indication information, wherein the monitoring indication information includes: monitoring duration and / or number of monitoring object creation times;

[0122] If the monitoring indication information reaches the monitoring indication threshold, the respective embedded target classes are restored to corresponding target classes, thereby stopping the monitoring of the target classes being called to create objects.

[0123] According to one embodiment of the present invention, Figure 1 or Figure 2 Each step involved in the method shown can be Figure 6 The object allocation and positioning device shown is executed by various units. For example, Figure 1 The step S101 shown in FIG. 1 can be performed by Figure 6 The acquisition unit 601 and the processing unit 602 shown in FIG. 6 are executed together, and steps S102-S104 can be performed by Figure 6 The processing unit 602 shown in is executed. For example, Figure 2 The step S201 shown in FIG. 1 can be performed by Figure 6 The acquisition unit 601 and the processing unit 602 shown in FIG. 6 are executed together, and steps S202-S206 can be performed by Figure 6 The processing unit 602 shown in executes, and so on.

[0124] According to another embodiment of the present invention, Figure 6Each unit in the object allocation and positioning device shown can be separately or completely merged into one or several other units to form, or one (some) of the units can also be split into multiple smaller units in function to form, which can achieve the same operation without affecting the realization of the technical effects of the embodiments of the present invention. The above-mentioned units are divided based on logical functions. In practical applications, the function of one unit can also be realized by multiple units, or the functions of multiple units can be realized by one unit. In other embodiments of the present invention, any object allocation and positioning device can also include other units. In practical applications, these functions can also be implemented with the assistance of other units, and can be implemented by the collaboration of multiple units.

[0125] According to another embodiment of the present invention, the program can be executed by running a program on a general electronic device such as a computer including a central processing unit (CPU), a random access memory medium (RAM), a read-only memory medium (ROM), and other processing elements and storage elements. Figure 1 or Figure 2 A computer program (including program code) for each step involved in the corresponding method shown in Figure 6 The object allocation and positioning device shown in the embodiment of the present invention is used to implement the object allocation and positioning method of the embodiment of the present invention. The computer program can be recorded on a computer storage medium, for example, and loaded into the above electronic device through the computer storage medium and run therein.

[0126] The embodiment of the present invention can obtain the collection indication information, and based on the collection indication information, respectively collect the memory usage of the objects corresponding to each class in the M classes N times, and obtain the N memory usage corresponding to each class, where M and N are both positive integers. Then, the N memory usage corresponding to each class can be weighted and summed to obtain the class sorting indication information of each class, and based on the class sorting indication information of each class, at least one target class can be selected from the M classes, and the class sorting indication information of a target class is greater than the sorting indication threshold; further, the object creation monitoring embedding code can be determined, and the object creation monitoring embedding code can be respectively embedded into each target class included in at least one target class to obtain each embedded target class, and when an embedded target class is called to create an object, it supports the generation of a corresponding call stack, and a call stack is used to indicate the call link of the corresponding object. Based on this, the call stack set of each embedded target class within the target time range can be determined, and based on the call stack set corresponding to each embedded target class, the object allocation indication data corresponding to each embedded target class is generated, and the object allocation indication data is used to realize the object allocation positioning under the corresponding embedded target class. It can be seen that the embodiment of the present invention can conveniently generate object allocation indication data, thereby conveniently realizing object allocation positioning through any object allocation indication data. That is to say, the embodiment of the present invention can conveniently perform object allocation positioning, that is, it can realize automatic positioning of the root cause of the problem at the code level.

[0127] Based on the description of the above method embodiment and device embodiment, the exemplary embodiment of the present invention further provides an electronic device, including: at least one processor; and a memory connected to the at least one processor in communication. The memory stores a computer program that can be executed by the at least one processor, and the computer program is used to enable the electronic device to perform the method according to the embodiment of the present invention when executed by the at least one processor.

[0128] Exemplary embodiments of the present invention also provide a non-transitory computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor of a computer, is used to cause the computer to perform a method according to an embodiment of the present invention.

[0129] An exemplary embodiment of the present invention further provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor of a computer, the computer is used to enable the computer to perform a method according to an embodiment of the present invention.

[0130] refer to Figure 7, a block diagram of an electronic device 700 that can be used as a server or client of the present invention will now be described, which is an example of a hardware device that can be applied to various aspects of the present invention. The electronic device is intended to represent various forms of digital electronic computer devices, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.

[0131] like Figure 7 As shown, the electronic device 700 includes a computing unit 701, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 702 or a computer program loaded from a storage unit 708 into a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the device 700 can also be stored. The computing unit 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.

[0132] A plurality of components in the electronic device 700 are connected to the I / O interface 705, including: an input unit 706, an output unit 707, a storage unit 708, and a communication unit 709. The input unit 706 may be any type of device capable of inputting information to the electronic device 700, and the input unit 706 may receive input digital or character information, and generate key signal inputs related to user settings and / or function control of the electronic device. The output unit 707 may be any type of device capable of presenting information, and may include but is not limited to a display, a speaker, a video / audio output terminal, a vibrator, and / or a printer. The storage unit 708 may include but is not limited to a disk, an optical disk. The communication unit 709 allows the electronic device 700 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks, and may include but is not limited to a modem, a network card, an infrared communication device, a wireless communication transceiver, and / or a chipset, such as a Bluetooth™ device, a WiFi device, a WiMax device, a cellular communication device, and / or the like.

[0133] The computing unit 701 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 701 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 701 performs the various methods and processes described above. For example, in some embodiments, the object allocation and positioning method may be implemented as a computer software program, which is tangibly included in a machine-readable medium, such as a storage unit 708. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 700 via the ROM 702 and / or the communication unit 709. In some embodiments, the computing unit 701 may be configured to perform the object allocation and positioning method in any other appropriate manner (e.g., by means of firmware).

[0134] The program code for implementing the method of the present invention can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer or other programmable object allocation positioning device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code can be executed entirely on the machine, partially on the machine, partially on the machine as a stand-alone software package and partially on a remote machine, or entirely on a remote machine or server.

[0135] In the context of the present invention, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0136] As used herein, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, apparatus, and / or device (e.g., disk, optical disk, memory, programmable logic device (PLD)) for providing machine instructions and / or data to a programmable processor, including a machine-readable medium that receives machine instructions as a machine-readable signal. The term "machine-readable signal" refers to any signal for providing machine instructions and / or data to a programmable processor.

[0137] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0138] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.

[0139] A computer system may include clients and servers. Clients and servers are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship to each other.

[0140] Furthermore, it should be understood that what is disclosed above is only a preferred embodiment of the present invention, and certainly cannot be used to limit the scope of rights of the present invention. Therefore, equivalent changes made according to the claims of the present invention are still within the scope of the present invention.

Claims

1. An object allocation and positioning method, characterized in that: include: Acquire collection indication information, and based on the collection indication information, respectively collect N memory usages of objects corresponding to each class in the M classes to obtain N memory usages corresponding to each class, where M and N are both positive integers; Performing weighted summation on the N memory usages corresponding to the various classes to obtain class ranking indication information of the various classes, and selecting at least one target class from the M classes based on the class ranking indication information of the various classes, wherein the class ranking indication information of the target class is greater than the ranking indication threshold; Determine an object creation monitoring embedded code, and embed the object creation monitoring embedded code into each target class included in the at least one target class, respectively, to obtain each embedded target class, wherein when an embedded target class is called to create an object, it supports generating a corresponding call stack, and a call stack is used to indicate a call link of a corresponding object; Determine the call stack sets of each embedded target class within the target time range, and generate object allocation indication data corresponding to each embedded target class based on the call stack sets corresponding to each embedded target class, and one object allocation indication data is used to realize object allocation positioning under the corresponding embedded target class.

2. The method according to claim 1, characterized in that The N memory usages corresponding to the various classes correspond to P time periods, where P is a positive integer; the method further includes: Obtaining the object allocation speed in each of the P time periods; Based on the object allocation speed in each time period, determining whether the N memory usages corresponding to each class are credible; If the N memory usages corresponding to the various classes are reliable, the weighted summing of the N memory usages corresponding to the various classes is triggered to obtain class ranking indication information of the various classes.

3. The method according to claim 2, characterized in that The determining whether the N memory usages corresponding to the respective classes are credible based on the object allocation speeds in the respective time periods includes: Performing a mean operation on the object allocation speeds in each time period to obtain speed judgment indication information, and if the speed judgment indication information is greater than a speed judgment threshold, determining N memory usage confidences corresponding to each class; or, Q time periods are determined from the P time periods. If the value of Q is greater than a preset quantity threshold, N memory usage confidences corresponding to the various classes are determined. The object allocation speed in each of the Q time periods is greater than the speed judgment threshold, and Q is a positive integer.

4. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: Obtaining an object allocation speed within a time period every unit collection time, wherein a time period corresponds to the unit collection time period, and an object allocation speed is determined based on an amount of memory allocated within the corresponding time period; When it is detected that the object allocation speed in the current time period is greater than a preset speed threshold, the acquisition of the collection indication information is triggered.

5. The method according to claim 4, characterized in that The object allocation speed in any period is obtained by: Initialize the amount of allocated memory, and starting from the start time of any time period, when monitoring the occurrence of a current garbage collection event, determine the initial usage of the storage area before the start of the current garbage collection event; Determine a historical usage of a storage area, where the historical usage of the storage area is the usage of the storage area after the last garbage collection event ends; The difference between the initial usage of the storage area in the current event and the historical usage of the storage area is added to the allocated memory amount, and the end usage of the storage area in the current event after the current garbage collection event ends is used to update the historical usage of the storage area until the end time of any time period is reached, so as to obtain the object allocation speed within any time period based on the allocated memory amount.

6. The method according to any one of claims 1 to 3, characterized in that: The collection indication information is used to indicate a collection rule of an object histogram. Based on the collection indication information, the memory usage of the objects corresponding to each class in the M classes is collected N times to obtain the N memory usage corresponding to each class, including: Based on the collection indication information, determine N histogram collection moments; Respectively acquiring object histogram data at each of the N histogram collection moments to obtain N object histogram data, wherein one object histogram data includes memory usage of each class in the M classes at the corresponding histogram collection moment; From the N object histogram data, N memory usages corresponding to the respective classes are determined respectively, so as to collect N memory usages of the objects corresponding to the respective classes respectively.

7. The method according to any one of claims 1 to 3, characterized in that: One object allocation indication data is flame graph data corresponding to the corresponding embedded target class, and one flame graph data is used to reflect the number of times each code segment in at least one code segment calls the corresponding embedded target class to create an object.

8. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: Determine monitoring indication information, wherein the monitoring indication information includes: monitoring duration and / or number of monitoring object creation times; If the monitoring indication information reaches the monitoring indication threshold, the respective embedded target classes are restored to corresponding target classes, thereby stopping the monitoring of the target classes being called to create objects.

9. An object allocation and positioning device, characterized in that: The device comprises: An acquisition unit, used for acquiring collection indication information; A processing unit, configured to collect N memory usages of objects corresponding to each of the M classes based on the collection indication information, to obtain N memory usages corresponding to each of the M classes, where M and N are both positive integers; The processing unit is further configured to perform weighted summation on the N memory usages corresponding to the respective classes to obtain class ranking indication information of the respective classes, and select at least one target class from the M classes based on the class ranking indication information of the respective classes, wherein the class ranking indication information of the target class is greater than a ranking indication threshold; The processing unit is further used to determine the object creation monitoring embedded code, and respectively embed the object creation monitoring embedded code into each target class included in the at least one target class to obtain each embedded target class, and when an embedded target class is called to create an object, it supports generating a corresponding call stack, and a call stack is used to indicate a call link of the corresponding object; The processing unit is also used to determine the call stack sets of each embedded target class within the target time range, and generate object allocation indication data corresponding to each embedded target class based on the call stack sets corresponding to each embedded target class. One object allocation indication data is used to realize object allocation positioning under the corresponding embedded target class.

10. An electronic device, characterized in that: include: processor; as well as Memory for storing programs, The program includes instructions, which, when executed by the processor, cause the processor to perform the method according to any one of claims 1 to 8.

11. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to make a computer execute the method according to any one of claims 1-8.

Citation Information

Patent Citations

  • Object management method and device

    CN108132817A

  • Program memory monitoring method and device, computer equipment and storage medium

    CN114153690A