Behavior detection method for container object and information acquisition device

By defining local methods in the target virtual machine of Java applications, intercepting and modifying the bytecode of container objects, and collecting and analyzing operation information, the problem of inefficient behavior detection of container objects in Java applications is solved and efficient performance optimization is achieved.

CN119336444APending Publication Date: 2025-01-21ALIPAY (HANGZHOU) INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411360855.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-26
Publication Date
2025-01-21

AI Technical Summary

Technical Problem

The prior art is difficult to effectively detect and analyze the inefficient behavior of container objects in Java applications, resulting in low memory efficiency.

Method used

By defining local methods in the target virtual machine, intercepting and modifying the bytecode of the container object, collecting the operating information of the container object, and writing it into the file or database to achieve the inspection of the container object.

Benefits of technology

The precise detection and analysis of the inefficient behavior of the container object is achieved, and the error and missed reports are avoided, and the performance of the container object is helping developers optimize the performance of the container object.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119336444A_ABST
    Figure CN119336444A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a behavior detection method for a container object and an information acquisition device. The method relates to an information collection device and a target virtual machine, and the target virtual machine comprises a local method defined by the information collection device. The information acquisition device can intercept a first byte code of a target application program loaded by a target virtual machine, injects a first method into the first byte code for a target container class to obtain a second byte code, and sends the second byte code to the target virtual machine for loading. And when the target virtual machine runs the second byte code, the local method receives first operation information of the target container object collected by the first method, and writes the first operation information into the first file. Wherein the target container object is an instance of the target container class, and the first operation information is used for low-efficiency behavior detection of the target container object.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of this specification relate to the field of computer technology, and in particular, to a behavior detection method and an information collection device for a container object. Background Art

[0002] Java has attracted much attention as a language widely used to develop various cloud-native and microservice applications. Considering that Java applications usually run in large-scale distributed systems, performance is crucial. A container class is a data structure used to store and manage objects. In actual development scenarios, objects are stored and managed by instances of container classes (which can be called container objects). Container objects are widely used to store and process large-scale data sets of various data types, highlighting their key role in Java programming. Therefore, effectively utilizing container objects has become a key aspect of developing high-performance Java applications. In real-world applications, inefficient container objects are very common, which is the main reason for low memory efficiency in Java applications.

[0003] Therefore, there is an urgent need for a reasonable and reliable solution that can help detect inefficient behaviors of container objects. Summary of the invention

[0004] The embodiments of this specification provide a behavior detection solution for container objects, which can help to implement inefficient behavior detection of container objects.

[0005] In a first aspect, an embodiment of the present specification provides a behavior detection method for a container object, involving an information collection device and a target virtual machine, the target virtual machine including a local method defined by the information collection device, and the behavior detection method comprising: the information collection device intercepts a first bytecode of a target application loaded by the target virtual machine; the information collection device injects a first method into the first bytecode for a target container class to obtain a second bytecode, and sends the second bytecode to the target virtual machine for loading; during the process of running the second bytecode on the target virtual machine, the local method receives first operation information of the target container object collected by the first method, and writes the first operation information into a first file; wherein, the target container object is an instance of the target container class, and the first operation information is used for inefficient behavior detection of the target container object.

[0006] In some embodiments, the information collection device includes a predefined first container class model, which includes a container class built into the programming language of the target application and a method for operating the container class; before intercepting the first bytecode of the target application loaded by the target virtual machine, it also includes: the information collection device receives a user's information collection request, which includes the program identifier of the target application and the target container class selected from the first container class model.

[0007] In some embodiments, the information collection request further includes a target method selected from the first container class model for operating the target container class.

[0008] In some embodiments, the information collection device further includes a customized second container class model, which includes a customized container class and methods for operating the container class.

[0009] In some embodiments, injecting the first method into the target container class includes: injecting the first method into an entry and an exit of a target method for operating the target container class.

[0010] In some embodiments, the first file is a private file for a first thread executing the target method.

[0011] In some embodiments, the first file is located on a disk; writing the first operation information to the first file includes: writing the first operation information to a private data structure defined for the first thread in a memory, and moving the first operation information from the private data structure to the first file when a migration condition corresponding to the private data structure is met.

[0012] In some embodiments, the behavior detection method further includes: a data storage device obtains the first file, and writes the operation information in the first file into a target database.

[0013] In some embodiments, the data storage device includes an offline script; obtaining the first file and writing the operation information in the first file into the target database includes: obtaining the first file by running the offline script and writing the operation information in the first file into the target database.

[0014] In some embodiments, the operation information in the first file includes a timestamp; and writing the operation information in the first file into the target database includes: writing the operation information in the first file into the target database in the order of the timestamp from small to large.

[0015] In some embodiments, the target virtual machine also includes a garbage collection component, and the operation information in the first file includes the address of the corresponding container object; the behavior detection method also includes: the information collection device intercepts the garbage collection component's calling behavior of the target function for moving the object, obtains the address information of the object to be moved from the input parameters of the target function, and writes the address information into a second file; wherein the address information includes a source address and a target address; writing the operation information in the first file into the target database includes: determining, based on the address information in the second file, whether there are multiple operation information containing different addresses of the same container object in the first file; if the determination result is yes, generating a virtual address for the same container object, writing the virtual address into the multiple operation information, and writing the updated multiple operation information into the target database.

[0016] In some embodiments, the behavior detection method further includes: the detection device obtains various operation information of the target container object from the target database, and performs inefficient behavior detection on the target container object according to the various operation information.

[0017] In some embodiments, the detecting inefficient behavior of the target container object according to the various operation information includes: searching for second operation information in the various operation information, which shows a second method for accessing the target container object; if the second operation information is not found, determining that the target container object is an unaccessed container object.

[0018] In some embodiments, the performing inefficient behavior detection on the target container object according to the various operation information includes: determining an actual length of the target container object according to the various operation information; if the actual length does not exceed a preset threshold, determining that the target container object is a limited-length container.

[0019] In some embodiments, the detecting of inefficient behavior of the target container object according to the various operation information includes: determining the actual length and initial capacity of the target container object according to the various operation information; if the actual length is less than the initial capacity, determining that the target container object has initial capacity waste behavior.

[0020] In some embodiments, the inefficient behavior detection of the target container object according to the various operation information includes: searching for third operation information in the various operation information, which shows a third method for adding an element to the target container object; in response to finding the third operation information, determining whether the input parameters of the third method in the third operation information include a Null element to be added; if the determination result is yes, determining that the target container object has Null element waste behavior.

[0021] In a second aspect, an embodiment of the present specification provides a behavior detection method for a container object, involving an information collection device and a target virtual machine, the target virtual machine including a local method defined by the information collection device, the behavior detection method being executed by the information collection device, including: intercepting a first bytecode of a target application loaded by the target virtual machine; injecting a first method into the first bytecode for a target container class to obtain a second bytecode; sending the second bytecode to the target virtual machine for loading, so that during the process of running the second bytecode, the target virtual machine receives first operation information of the target container object collected by the first method by the local method, and writes the first operation information into a first file; wherein, the target container object is an instance of the target container class, and the first operation information is used for inefficient behavior detection of the target container object.

[0022] In a third aspect, an embodiment of the present specification provides an information collection device, comprising: a control unit, configured to intercept a first bytecode of a target application loaded by a target virtual machine, wherein the target virtual machine includes a local method defined by the information collection device; a bytecode operation unit, configured to inject a first method into the first bytecode for a target container class to obtain a second bytecode; the control unit is further configured to send the second bytecode to the target virtual machine for loading, so that during the process of the target virtual machine running the second bytecode, the local method receives first operation information of the target container object collected by the first method, and writes the first operation information into a first file; wherein the target container object is an instance of the target container class, and the first operation information is used for inefficient behavior detection of the target container object.

[0023] In a fourth aspect, an embodiment of the present specification provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed in a computer, the computer is caused to execute the method described in the second aspect.

[0024] In a fifth aspect, an embodiment of the present specification provides a computing device, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method described in the second aspect is implemented.

[0025] In a sixth aspect, an embodiment of the present specification provides a computer program product, including a computer program / instruction, which implements the steps of the method described in the second aspect when executed by a processor.

[0026] In the scheme provided in the above-mentioned embodiments of the present specification, the target virtual machine includes a local method defined by an information collection device. The information collection device can intercept the first bytecode of the target application loaded by the target virtual machine, inject the first method into the first bytecode for the target container class, obtain the second bytecode, and send the second bytecode to the target virtual machine for loading. In the process of running the second bytecode on the target virtual machine, the first operation information of the target container object collected by the first method is received by the local method, and the first operation information is written into the first file. Among them, the target container object is an instance of the target container class, and the first operation information is used for inefficient behavior detection of the target container object. Therefore, the scheme can collect accurate container object operation information online for inefficient behavior detection of container objects by bytecode instrumentation of the container class, avoiding the introduction of any false positives or negatives. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] In order to more clearly illustrate the technical solutions of the multiple embodiments disclosed in this specification, the drawings required for the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only the multiple embodiments disclosed in this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0028] Figure 1 It is a schematic diagram of an application scenario in which the embodiments of this specification can be applied;

[0029] Figure 2 is an exemplary schematic diagram of the information configuration interface in the embodiment of this specification;

[0030] Figure 3 is a timing diagram of a behavior detection method for a container object in an embodiment of this specification;

[0031] Figure 4 is a schematic diagram of a mobile object address collection process in an embodiment of this specification;

[0032] Figure 5 is an exemplary structural diagram of an information collection device in an embodiment of this specification;

[0033] Figure 6 is a schematic diagram of a process of writing operation information in file F1 into a target database in an embodiment of this specification;

[0034] Figure 7 It is a structural diagram of the information collection device in the embodiment of this specification. DETAILED DESCRIPTION

[0035] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this specification.

[0036] As mentioned above, in actual development scenarios, objects are stored and managed by instances of container classes (which can be called container objects). Container objects are widely used to store and process large-scale data sets of various data types, highlighting their key role in Java programming. Therefore, effectively using container objects has become a key aspect of developing high-performance Java applications.

[0037] Currently, some programmers have bad programming practices when using container objects, such as arbitrarily choosing container object implementations without considering their underlying implementation details, or arbitrarily calling convenient methods for programmability while ignoring performance issues. As a result, inefficient container objects are very common in real-world applications and are the main reason for low memory efficiency in Java applications.

[0038] In order to facilitate the detection of inefficient behaviors of container objects, the embodiments of this specification provide a behavior detection solution for container objects.

[0039] Figure 1 This is a schematic diagram of an application scenario in which the embodiments of this specification can be applied. The application scenario involves an information collection device, a target application program, and a target virtual machine.

[0040] The target application is a program that needs to detect inefficient container behavior. The programming language of the target application can be any programming language with a container class, such as but not limited to the Java language. When the coding language is the Java language, the target application can be called a Java application. The Java language can include a variety of container classes, such as ArrayList, LinkedList, HashSet, and TreeSet. Among them, ArrayList is implemented based on a dynamic array and supports random access. LinkedList is implemented based on a linked list and is suitable for frequent insertion and deletion operations. HashSet is implemented based on a hash table and has a fast search and insertion speed. TreeSet is implemented based on a red-black tree and provides sorting and ordered operations. In addition, each of the multiple container classes defines several methods. Taking ArrayList as an example, several methods defined for ArrayList include add, remove, and get methods. The add method can be used to add elements. The remove method can be used to remove elements at a specified position. The get method can be used to obtain elements at a specified position.

[0041] In actual development scenarios, objects are stored and managed by instances of container classes, i.e., container objects. Taking ArrayList as an example, in the example program statement "List <string>In "list=new ArrayList<>()", the "list" on the left side of "=" is an instance of ArrayList, which can be called a container object. The methods defined for ArrayList can be used to operate the container object list; for example, the add method can be used to add elements to the list, the remove method can be used to remove elements at a specified position from the list, and the get method can be used to get elements at a specified position from the list.

[0042] The target virtual machine is a virtual machine that can run bytecodes, including but not limited to a Java virtual machine (JVM). The target virtual machine includes a native method NM defined by the information collection device. In one example, when the target virtual machine is a Java virtual machine, the native method NM can be a JNI (Java Native Interface) method implemented in C++ language.

[0043] like Figure 1 As shown, the target virtual machine can load the bytecode C1 of the target application. Among them, the bytecode C1 can be the original class file of the target application. The information collection device can intercept the bytecode C1 loaded by the target virtual machine, inject method M1 into the bytecode C1 for the target container class, obtain bytecode C2, and send the bytecode C2 to the target virtual machine for loading. Method M1 is used to collect operation information of an instance of the target container class (hereinafter referred to as the target container object), and can call the local method NM. It should be noted that the target container class can be selected by the information collection device according to a preset selection strategy, or specified by the user.

[0044] In the case of supporting the user to specify the container class to be instrumented, the information collection device may include a predefined container class model P1, which includes a container class built into the programming language of the target application and a method for operating the container class. Further, the information collection device may also include a custom container class model P2, which includes a custom container class and a method for operating the container class.

[0045] Based on this, before intercepting the bytecode C1, the information collection device can receive a user's information collection request, which includes the program identifier of the target application and the target container class selected from the container class model. Further, the information collection request can also include a target method selected from the container class model for operating the target container class. The container class model includes a container class model P1 and / or a container class model P2.

[0046] Assume that the container class model P1 includes built-in container class 1 and container class 2, methods 1 and 2 for operating container class 1, and methods 3 and 4 for operating container class 2; the container class model P2 includes a user-defined container class 3, and method 5 for operating container class 3. The information collection device can provide the user with the following information: Figure 2 The information configuration interface shown is used for the user to select the program identifier of the application to be detected, the container class to be plugged, and the method for operating the container class, and to send an information collection request to the information collection device by clicking the submit button. Figure 2 It is an exemplary schematic diagram of the information configuration interface in the embodiment of this specification.

[0047] It should be noted that by making the information collection device include a container class model, the user only needs to perform a relatively simple configuration based on the container class model to perform analysis, which can reduce the user's energy consumption. In addition, the solution provided in the embodiment of this specification can be applied to built-in container classes and custom container classes, and does not require modification of the target virtual machine or source code, and the overhead is controllable, which is suitable for various production software.

[0048] When the target virtual machine runs the bytecode C2, it can Figure 1 As shown, the local method NM receives the operation information I1 of the target container object collected by the method M1, and writes the operation information I1 into the file F1. The operation information I1 is used for inefficient behavior detection of the target container object. It should be pointed out that the operation information I1 can show various information that is helpful for detecting inefficient behavior of container objects, such as the target method used to perform the operation indicated by the operation information I1, the target container class to which the target method belongs, the address of the target container object that references the target method, the parameters of the target method (such as input parameters), the return value of the target method, the line number of the call instruction for calling the target method referenced by the target container object, the timestamp, etc. The address of the target container object in the operation information I1 can serve as the object identifier of the target container object.

[0049] In one implementation, a manual detection method or an automatic detection method may be used to perform inefficient behavior detection on the target container object according to various operation information of the target container object in the file F1.

[0050] In another embodiment, Figure 1 The application scenario shown may also involve a data storage device and a target database. The target database includes but is not limited to a relational database (such as SqlLite, etc.). Among them, SqlLite is a very lightweight relational database system. Figure 1 As shown, the data storage device can obtain the file F1 and write the operation information in the file F1 into the target database. Therefore, the inefficient behavior of the target container object can be analyzed offline based on the operation information of the target container object in the target database by manual detection or automatic detection. In one example, the data storage device can include an offline script, and the file F1 can be obtained and the operation information in the file F1 can be written into the target database by running the offline script.

[0051] It should be noted that when an automated detection method is needed to detect inefficient behavior of the target container object, Figure 1 The application scenario shown may also involve detection equipment. Figure 1 As shown, the detection device can obtain various operation information of the target container object from the target database, and perform inefficient behavior detection on the target container object according to the various operation information.

[0052] Next, combine Figure 3 , introduces the behavior detection scheme for container objects. Among them, Figure 3 It is a timing diagram of the behavior detection method for container objects in the embodiment of this specification. The method includes steps S301-S307 as shown below.

[0053] like Figure 3 As shown, in step S301, the information collection device intercepts the bytecode C1 of the target application loaded by the target virtual machine.

[0054] In practice, the target virtual machine may include a class loader (ClassLoader), and the target virtual machine may load bytecodes by the class loader. In addition, the target virtual machine may provide a mechanism for detecting the loading behavior of the class loader on the bytecode. The information collection device may detect the loading behavior of the class loader on the bytecode C1 by subscribing to the mechanism, thereby intercepting the bytecode C1. In one example, the information collection device may include a control unit, and the control unit may detect the loading behavior of the class loader on the bytecode C1 by subscribing to the mechanism, thereby intercepting the bytecode C1.

[0055] Next, in step S303, the information collection device injects method M1 into the bytecode C1 for the target container class to obtain bytecode C2.

[0056] As an implementation method, method M1 can be injected into the call instruction for calling the target method. The target method is a method for operating the target container class. It should be noted that since the stub is inserted before entering the method body of the target method, method M1 cannot access the local variables of the target method during the subsequent execution of the bytecode C2 by the target virtual machine. Method M1 needs to obtain the runtime information of the target container object by operating the operand stack in the target virtual machine, and then generate the operation information of the target container object.

[0057] Considering that the operand stack in the target virtual machine is prone to errors and will introduce a large number of stack operation instructions, as another implementation method, method M1 can be injected at the entry and exit of the target method used to operate the target container class. This plugging method can achieve fine-grained plugging. It should be noted that since the plugging is performed after entering the target method, in the subsequent process of running the bytecode C2 in the target virtual machine, method M1 can obtain the runtime information of the target container object by accessing the local variables of the target method, and then generate the operation information of the target container object.

[0058] Next, in step S305, the information collection device sends the bytecode C2 to the target virtual machine for loading.

[0059] As an implementation method, the information collection device includes a bytecode operation unit in addition to the control unit as described above. After intercepting the bytecode C1, the control unit can provide the bytecode C1 to the bytecode operation unit, and the bytecode operation unit injects the method M1 into the bytecode C1 for the target container class to obtain the bytecode C2. Then, the control unit can receive the bytecode C2 returned by the bytecode operation unit and send the bytecode C2 to the target virtual machine for loading.

[0060] Next, in step S307, when the target virtual machine is running the bytecode C2, the local method NM receives the operation information I1 of the target container object collected by the method M1, and writes the operation information I1 into the file F1; wherein, the target container object is an instance of the target container class, and the operation information I1 is used for inefficient behavior detection of the target container object.

[0061] According to the above description, the local method NM is defined by the information collection device. In one example, the information collection device may include a method declaration unit, and the declaration of the local method NM may be stored in the method declaration unit. The method declaration unit may provide the declaration of the local method NM to the target virtual machine for loading.

[0062] As is known to all, Java involves multi-threaded scenarios, and using Java for multi-threaded file reading and writing will face a large performance loss. In order to effectively avoid this performance loss, in one embodiment, for the target method for executing the operation indicated by the operation information I1, the file F1 can be made a private file of the thread T1 for executing the target method.

[0063] Furthermore, the file F1 may be located on a disk, such as a disk of a server where the target virtual machine is located. In order to improve the overall performance of information collection, the local method NM may write the operation information I1 into a private data structure defined for thread T1 in the memory, and move the operation information I1 from the private data structure to the file F1 when the migration condition corresponding to the private data structure is met. Specifically, all the operation information including the operation information I1 in the private data structure may be moved to the file F1.

[0064] The above private data structure can be defined by the local method NM through the target keyword. In one example, when the local method NM is implemented using the C++ language, the target keyword can include the thread_local keyword. In practice, the thread_local keyword is used in C++ to define thread local storage (TLS) variables. This type of variable is independent for each thread, which means that each thread has its own copy of the data and will not share it with other threads. This can help reduce common data contention and synchronization problems in multi-threaded programming.

[0065] The migration condition as mentioned above may include, for example, a preset threshold value. When the number of operation information in the private data structure exceeds the preset threshold value, the migration condition may be determined to be satisfied. Alternatively, the migration condition may include, for example, several time points. When the current time reaches a certain time point among the several time points, the migration condition may be determined to be satisfied. It should be understood that the content of the migration condition may be set according to actual needs and is not specifically limited here.

[0066] exist Figure 3 In the scheme provided by the corresponding embodiment, the target virtual machine includes a local method NM defined by an information collection device. The information collection device can intercept the bytecode C1 of the target application loaded by the target virtual machine, inject method M1 into the bytecode C1 for the target container class, obtain bytecode C2, and send bytecode C2 to the target virtual machine for loading. During the process of running the bytecode C2, the local method NM receives the operation information I1 of the target container object collected by the method M1, and writes the operation information I1 into the file F1. Among them, the target container object is an instance of the target container class, and the operation information I1 is used for inefficient behavior detection of the target container object. Therefore, the scheme can collect accurate container object operation information online for inefficient behavior detection of container objects by bytecode instrumentation of the container class, avoiding the introduction of any false positives or negatives.

[0067] Combined with the previous article Figure 3 A behavior detection scheme for container objects is introduced. In practice, the target virtual machine also includes a garbage collection (GC) component. GC is a mechanism for automatically managing memory, which is used to recycle objects that are no longer needed, thereby freeing up memory space, preventing memory leaks and improving performance. During the process of the target virtual machine running the bytecode C2, the garbage collection component may call the target function (such as the memmove function) for moving objects to move the target container object. Since method M1 usually collects the address of the container object as the object identifier, there may be multiple operation records containing different addresses of the same container object in file F1. In order to facilitate the rapid acquisition of the multiple operation records corresponding to the same container object during analysis, it is also necessary to collect the address information of the object moved by the garbage collection component through the target function.

[0068] Based on this, in one embodiment, the information collection device can also perform the following steps: Figure 4 The mobile object address collection process shown in FIG. Figure 4 is a schematic diagram of the mobile object address collection process in the embodiment of this specification. The collection process includes: step S401, intercepting the call behavior of the garbage collection component to the target function for moving the object; step S403, obtaining the address information of the object to be moved from the input parameter of the target function, including the source address and the target address; step S405, writing the address information into the file F2. In one example, the file F2 can be a private file of the thread used to execute the garbage collection component.

[0069] Furthermore, the information collection device may include an address collection unit, which may intercept the garbage collection component's call to the target function for moving objects, obtain address information of the object to be moved from the input parameters of the target function, and write the address information into file F2.

[0070] In one embodiment, when the target virtual machine is a Java virtual machine, the control unit as described above may be referred to as Figure 5 The JVMTI (Java Virtual Machine Tool Interface) agent shown in FIG. 10 , the method declaration unit can be called as follows Figure 5 The Java agent shown in FIG. 1 may include a bytecode operation unit such as Figure 5 The ASM framework shown in FIG. 1 may include an address acquisition unit such as Figure 5 LD_PRELOAD as shown. Among them, Figure 5 It is an exemplary structural diagram of the information collection device in the embodiment of this specification. In practice, JVMTI is a set of native interfaces provided by the Java virtual machine for development and debugging tools to more deeply detect and manage the execution of Java applications. ASM is a popular Java bytecode operation framework that allows programmers to operate Java classes at the bytecode level, including creating, modifying and analyzing bytecodes. The LD_PRELOAD environment variable can be used to intercept and replace function calls in shared libraries, including calls to memmove.

[0071] The JVMTI agent in the information collection device can communicate with the Java virtual machine by calling the JVMTI provided by the Java virtual machine. The mechanism provided by the Java virtual machine for detecting the loading behavior of the class loader for bytecodes can be a ClassFileLoadHook event callback. The JVMTI agent can detect the loading behavior of the class loader for bytecode C1 by subscribing to the ClassFileLoadHook event callback, thereby intercepting the bytecode C1. Afterwards, the JVMTI agent can provide the bytecode C1 to the ASM framework for bytecode instrumentation. Specifically, the ASM framework can inject method M1 into the bytecode C1 for the target container class, obtain bytecode C2, and return bytecode C2 to the JVMTI agent. Then, the JVMTI agent can send the bytecode C2 to the Java virtual machine for loading through RetransformClasses provided by the Java virtual machine. Among them, RetransformClasses is a mechanism of the Java virtual machine, which allows programmers to reconvert loaded classes at runtime. In addition, the information collection device can intercept the calling behavior of the garbage collection component to the memmove function through LD_PRELOAD, obtain the address information of the object to be moved from the input parameter of the memmove function, and write the address information into the file F2.

[0072] In one embodiment, in order to facilitate the detection of inefficient behaviors of the target container object, the operation information in the file F1 may be written into the target database.

[0073] Next, combine Figure 6 , describes the process of writing the operation information in file F1 into the target database. Figure 6 It is a schematic diagram of the process of writing the operation information in the file F1 into the target database in the embodiment of this specification.

[0074] like Figure 6 As shown, in step S601, the data storage device obtains file F1.

[0075] Next, in step S603, the data storage device writes the operation information in the file F1 into the target database.

[0076] Specifically, the data storage device may include an offline script, and the file F1 may be acquired by running the offline script, and the operation information in the file F1 may be written into the target database.

[0077] In addition, the data storage device can write the operation information in the file F1 into the target database in the order of the timestamp from small to large. Thus, the operation information of different container objects can be stored in the target database in a linear arrangement according to the timestamp through offline analysis, which is convenient for users to write custom rules through SQL (Structured Query Language) to query any inefficient container mode of interest.

[0078] It should be noted that when the information collection device executes Figure 4 In the case of the mobile object address collection process shown, the specific implementation process of step S603 may include: sub-step S6031, determining whether there are multiple operation information containing different addresses of the same container object in file F1 according to the address information in file F2; sub-step S6033, if the determination result is yes, generating a virtual address for the above-mentioned same container object, and writing the virtual address into the above-mentioned multiple operation information; sub-step S6035, writing the updated multiple operation information into the target database.

[0079] Among them, in sub-step S6031, for any two pieces of operation information in file F1, if the two pieces of operation information include different container object addresses, then address information that simultaneously includes the container object addresses included in the two pieces of operation information can be searched in file F2. If found, it is determined that the two pieces of operation information include different addresses of the same container object, that is, it is determined that the two pieces of operation information correspond to the same container object. For the virtual address in sub-step S6033, it is different from the real address in the above-mentioned multiple pieces of operation information, but can be the same as the real address structure.

[0080] In one embodiment, after the operation information in the file F1 is written into the target database, the detection device can automatically detect the inefficient behavior of the target container object according to the operation information of the target container object in the target database. For example, the detection device can obtain the operation information of the target container object from the target database, and perform inefficient behavior detection on the target container object according to the operation information. The inefficient behavior of the container object may include but is not limited to at least one of unaccessed container objects, limited length container objects, initial capacity waste, suboptimal algorithm container objects, redundant traversal, redundant copying, and NULL element waste.

[0081] As an example, when detecting whether the target container object is an unvisited container object, operation information showing a method for accessing the target container object may be searched in each operation information of the target container object. If not found, the target container object is determined to be an unvisited container object.

[0082] When detecting whether the target container object is a finite-length container object, the actual length of the target container object may be determined according to various operation information of the target container object. If the actual length does not exceed a preset threshold, the target container object is determined to be a finite-length container.

[0083] When detecting whether the target container object wastes initial capacity, the actual length and initial capacity of the target container object can be determined according to various operation information of the target container object. If the actual length is less than the initial capacity, it is determined that the target container object wastes initial capacity.

[0084] When detecting whether the target container object is an algorithm suboptimal container object, for an operation indicated by any one of the operation information of the target container object, if there is another type of container object that can implement the operation, and the execution efficiency of the other type of container object is higher than that of the target container object, then the target container object is determined to be an algorithm suboptimal container object.

[0085] When detecting whether there is redundant traversal behavior in the target container object, two operation information that both show methods for traversal access of the container object and have adjacent timestamps can be searched in each operation information of the target container object. If found, it is determined whether there is operation information showing a method for updating elements in the container object between the two operation information. If the determination result is no, it is determined that the target container object has redundant traversal behavior.

[0086] When detecting whether the target container object has redundant copy behavior, the operation information showing the method for copying all elements in a container object to the target container object can be searched in each operation information of the target container object. If found, it is determined that the target container object has redundant copy behavior.

[0087] When detecting whether the target container object has Null element waste behavior, the operation information showing the method for adding elements to the target container object can be searched in each operation information of the target container object. If found, it is determined whether the input parameter of the method in the operation information includes the Null element to be added. If the determination result is yes, it is determined that the target container object has Null element waste behavior.

[0088] Figure 7 It is a structural diagram of the information collection device in the embodiment of this specification. The device includes: a control unit 701, which is configured to intercept the first bytecode of the target application loaded by the target virtual machine, wherein the target virtual machine includes a local method defined by the information collection device; a bytecode operation unit 702, which is configured to inject the first method into the first bytecode for the target container class to obtain the second bytecode; the control unit 701 is also configured to send the second bytecode to the target virtual machine for loading, so that when the target virtual machine runs the second bytecode, the local method receives the first operation information of the target container object collected by the first method, and writes the first operation information into the first file; wherein the target container object is an instance of the target container class, and the first operation information is used for inefficient behavior detection of the target container object.

[0089] In one embodiment, the information collection device includes a predefined first container class model, which includes a container class built into the programming language of the target application, and a method for operating the container class; the information collection device may also include: a receiving unit (not shown in the figure), which is configured to receive a user's information collection request before the control unit 701 intercepts the first bytecode of the target application loaded by the target virtual machine, wherein the request includes a program identifier of the target application and a target container class selected from the first container class model.

[0090] Furthermore, the information collection request may also include a target method selected from the first container class model for operating the target container class.

[0091] In one embodiment, the information collection device may further include a customized second container class model, which includes a customized container class and methods for operating the container class.

[0092] In one implementation, the bytecode operation unit 702 may be further configured to: inject the first method into the entry and exit of the target method for operating the target container class.

[0093] In one implementation, the first file is a private file for a first thread that executes the target method.

[0094] In one embodiment, the target virtual machine also includes a garbage collection component; the information collection device may also include: an address collection unit (not shown in the figure), configured to intercept the garbage collection component's call behavior on the target function for moving the object, obtain the address information of the object to be moved from the input parameters of the target function, and write the address information into a second file; wherein the address information includes a source address and a target address.

[0095] The present specification also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed in a computer, the computer is caused to execute the following Figure 3 , Figure 4 , Figure 6 Describe the method.

[0096] The embodiment of the present specification also provides a computing device, including a memory and a processor, wherein the memory stores an executable code, and when the processor executes the executable code, the following is implemented: Figure 3 , Figure 4 , Figure 6 Describe the method.

[0097] The embodiments of the present specification also provide a computer program product, including a computer program / instruction, which is executed by a processor to implement the following Figure 3 , Figure 4 , Figure 6 Describe the steps of the method.

[0098] Those skilled in the art should be aware that in one or more of the above examples, the functions described in the multiple embodiments disclosed in this specification can be implemented by hardware, software, firmware, or any combination thereof. When implemented by software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium.

[0099] In some cases, the actions or steps described in the claims may be performed in a different order than in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or sequential order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0100] The specific implementation methods described above further illustrate in detail the purposes, technical solutions and beneficial effects of the multiple embodiments disclosed in this specification. It should be understood that the above description is only the specific implementation methods of the multiple embodiments disclosed in this specification, and is not used to limit the protection scope of the multiple embodiments disclosed in this specification. Any modifications, equivalent substitutions, improvements, etc. made on the basis of the technical solutions of the multiple embodiments disclosed in this specification should be included in the protection scope of the multiple embodiments disclosed in this specification.< / string>

Claims

1. A behavior detection method for a container object, involving an information collection device and a target virtual machine, wherein the target virtual machine includes a local method defined by the information collection device, and the behavior detection method includes: The information collection device intercepts the first bytecode of the target application loaded by the target virtual machine; The information collection device injects a first method into the first bytecode for the target container class to obtain a second bytecode, and sends the second bytecode to the target virtual machine for loading; During the process of the target virtual machine running the second bytecode, the native method receives first operation information of the target container object collected by the first method, and writes the first operation information into a first file; wherein, the target container object is an instance of the target container class, and the first operation information is used for inefficient behavior detection of the target container object.

2. The behavior detection method according to claim 1, wherein: The information collection device includes a predefined first container class model, which includes a container class built into the programming language of the target application and a method for operating the container class; Before intercepting the first bytecode of the target application loaded by the target virtual machine, the method further includes: The information collection device receives a user's information collection request, which includes a program identifier of the target application program and a target container class selected from the first container class model.

3. The behavior detection method according to claim 2, wherein: The information collection request also includes a target method selected from the first container class model for operating the target container class.

4. The behavior detection method according to claim 2, wherein: The information collection device also includes a customized second container class model, which includes a customized container class and a method for operating the container class.

5. The behavior detection method according to claim 1, wherein: The injecting the first method into the target container class includes: The first method is injected at the entry and exit of a target method for operating the target container class.

6. The behavior detection method according to claim 5, wherein: The first file is a private file of a first thread used to execute the target method.

7. The behavior detection method according to claim 6, wherein: The first file is located on a disk; The step of writing the first operation information into a first file comprises: The first operation information is written into a private data structure defined for the first thread in the memory, and when a migration condition corresponding to the private data structure is met, the first operation information is moved from the private data structure to the first file.

8. The behavior detection method according to any one of claims 1 to 7, further comprising: The data storage device obtains the first file and writes the operation information in the first file into the target database.

9. The behavior detection method according to claim 8, wherein: The data storage device includes an offline script; The obtaining of the first file and writing the operation information in the first file into the target database comprises: The first file is obtained by running the offline script, and the operation information in the first file is written into the target database.

10. The behavior detection method according to claim 8, wherein: The operation information in the first file includes a timestamp; Writing the operation information in the first file into the target database comprises: The operation information in the first file is written into the target database in the order of timestamps from small to large.

11. The behavior detection method according to claim 8, wherein: The target virtual machine also includes a garbage collection component, and the operation information in the first file includes an address of a corresponding container object; The behavior detection method also includes: The information collection device intercepts the calling behavior of the garbage collection component on the target function for moving objects, obtains the address information of the object to be moved from the input parameter of the target function, and writes the address information into the second file; wherein the address information includes a source address and a target address; Writing the operation information in the first file into the target database comprises: Determine, according to the address information in the second file, whether there are multiple pieces of operation information containing different addresses of the same container object in the first file; If the determination result is yes, a virtual address is generated for the same container object, the virtual address is written into the multiple pieces of operation information, and the updated multiple pieces of operation information are written into the target database.

12. The behavior detection method according to claim 8, further comprising: The detection device obtains each operation information of the target container object from the target database, and performs inefficient behavior detection on the target container object according to the each operation information.

13. The behavior detection method according to claim 12, wherein: The performing inefficient behavior detection on the target container object according to each operation information includes: Searching for second operation information in each of the operation information, which indicates a second method for accessing the target container object; If not found, it is determined that the target container object is an unvisited container object.

14. The behavior detection method according to claim 12, wherein: The performing inefficient behavior detection on the target container object according to each operation information includes: Determine the actual length of the target container object according to the operation information; If the actual length does not exceed the preset threshold, the target container object is determined to be a container of limited length.

15. The behavior detection method according to claim 12, wherein: The performing inefficient behavior detection on the target container object according to each operation information includes: Determine the actual length and initial capacity of the target container object according to the operation information; If the actual length is smaller than the initial capacity, it is determined that the target container object wastes initial capacity.

16. The behavior detection method according to claim 12, wherein: The performing inefficient behavior detection on the target container object according to each operation information includes: Searching for third operation information in each of the operation information, which indicates a third method for adding an element to the target container object; In response to finding the third operation information, determining whether an input parameter of the third method in the third operation information includes a Null element to be added; If the determination result is yes, it is determined that the target container object has Null element waste behavior.

17. A behavior detection method for a container object, involving an information collection device and a target virtual machine, the target virtual machine including a local method defined by the information collection device, the behavior detection method being executed by the information collection device, comprising: intercepting a first bytecode of a target application loaded by the target virtual machine; Injecting a first method into the first bytecode for the target container class to obtain a second bytecode; The second bytecode is sent to the target virtual machine for loading, so that when the target virtual machine runs the second bytecode, the local method receives the first operation information of the target container object collected by the first method, and writes the first operation information into a first file; wherein the target container object is an instance of the target container class, and the first operation information is used for inefficient behavior detection of the target container object.

18. An information collection device, comprising: a control unit configured to intercept a first bytecode of a target application loaded by a target virtual machine, wherein the target virtual machine includes a local method defined by the information collection device; a bytecode operation unit configured to inject a first method into the first bytecode for a target container class to obtain a second bytecode; The control unit is further configured to send the second bytecode to the target virtual machine for loading, so that when the target virtual machine runs the second bytecode, the local method receives the first operation information of the target container object collected by the first method, and writes the first operation information into a first file; wherein the target container object is an instance of the target container class, and the first operation information is used for inefficient behavior detection of the target container object.

19. A computer program product, comprising a computer program / instruction, which implements the steps of the behavior detection method according to claim 17 when executed by a processor.

20. A computing device comprising a memory and a processor, wherein: The memory stores executable code, and when the processor executes the executable code, the behavior detection method described in claim 17 is implemented.