A garbage disposal method, device, equipment and storage medium for Java virtual machine
By obtaining snapshots of candidate programs in Java virtual machines and building collection containers, memory management is performed based on dynamic loading mechanisms and reflection mechanisms, the inefficiency and crash problems in garbage collection in old-age areas in Java programs are solved, and more efficient memory is achieved Recycling and utilization.
Patent Information
- Application Number
- CN202411053116.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-02
- Publication Date
- 2024-11-05
- Estimated Expiration
- 2044-08-02
AI Technical Summary
When Java programs are running, garbage collection in young and old areas is likely to cause application pause, central processing unit usage rate 100% and application crashes, especially when memory usage rate is too high or space is lacking in the elderly areas .
By obtaining a snapshot of the candidate program of the current program, determining whether the candidate object meets the garbage collection conditions, building a collection container based on the dynamic loading mechanism and reflection mechanism, and allocating the target memory space in direct memory for serialization and recycling according to the memory size.
It improves the recycling efficiency and space utilization efficiency of objects to be recycled, and avoids application crashes and high CPU usage problems during garbage collection in the elderly area.
Smart Images

Figure CN118606008B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, in particular to the field of Java virtual machine technology, and specifically to a garbage disposal method, apparatus, device and storage medium for a Java virtual machine. Background Art
[0002] When a Java program is running, there will be a division between the young generation area and the old generation area. After an object is created in the memory, it will first enter the young generation area, and then be recycled through the object reference judgment of eden (Eden Space), s0 (Survivor Space 0), and s1 (Survivor Space 1). Objects that are not recycled enter the old generation area, or large objects enter the old generation area directly.
[0003] After executing garbage collection in the young generation area, a batch of objects need to be put into the old generation area. At this time, the old generation area does not have enough memory space to store these objects, and it must be triggered immediately; or when the memory usage rate of the old generation area exceeds 92%, etc., it will trigger garbage collection in the old generation area. When the old generation area is recycled, the application will be suspended, the CPU usage rate will be 100%, and the application will crash. Summary of the invention
[0004] The present application provides a garbage disposal method, apparatus, device and storage medium for a Java virtual machine to improve the recycling efficiency and space utilization efficiency of objects to be recycled.
[0005] According to one aspect of the present application, a garbage disposal method for a Java virtual machine is provided, the method comprising:
[0006] During the execution of the current program, a candidate program snapshot of the current program is obtained, and whether the candidate object meets the garbage collection condition is determined according to the candidate object in the candidate program snapshot and the reference object predetermined by the current program, and if so, the candidate object is used as an object to be recycled;
[0007] Based on the dynamic loading mechanism and the reflection mechanism, construct a first collection container for the object to be recycled;
[0008] Determine a target memory size according to a first memory size of the first collection container and a second memory size of the current program, and allocate a target memory space for the object to be recycled in direct memory based on the target memory size;
[0009] The objects to be recycled in the first collection container are serialized to store the objects to be recycled in the first collection container in the target memory space, and the target memory space is destroyed when the current program is finished.
[0010] According to another aspect of the present application, a garbage processing device for a Java virtual machine is provided, the device comprising:
[0011] An object determination module is used to obtain a candidate program snapshot of the current program during the execution of the current program, and determine whether the candidate object meets the garbage collection condition based on the candidate object in the candidate program snapshot and the reference object predetermined by the current program, and if so, the candidate object is used as an object to be recycled;
[0012] A container construction module, used to construct a first collection container for the object to be recycled based on a dynamic loading mechanism and a reflection mechanism;
[0013] a space allocation module, configured to determine a target memory size according to a first memory size of the first collection container and a second memory size of the current program, and allocate a target memory space for the to-be-reclaimed object in direct memory based on the target memory size;
[0014] The object processing module is used to serialize the objects to be recycled in the first collection container to store the objects to be recycled in the first collection container into the target memory space, and destroy the target memory space when the current program ends.
[0015] According to another aspect of the present application, an electronic device is provided, the electronic device comprising:
[0016] one or more processors;
[0017] A memory for storing one or more programs;
[0018] When the one or more programs are executed by the one or more processors, the one or more processors implement any one of the Java virtual machine garbage disposal methods provided in the embodiments of the present application.
[0019] According to another aspect of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the program is executed by a processor, the garbage disposal method of any Java virtual machine provided in the embodiments of the present application is implemented.
[0020] The present application obtains a candidate program snapshot of the current program during the execution of the current program, and determines whether the candidate object meets the garbage collection conditions based on the candidate object in the candidate program snapshot and the reference object predetermined by the current program. If so, the candidate object is used as the object to be recycled; based on the dynamic loading mechanism and the reflection mechanism, a first collection container is constructed for the object to be recycled; based on the first memory size of the first collection container and the second memory size of the current program, the target memory size is determined, and based on the target memory size, the target memory space is allocated in the direct memory for the object to be recycled; the object to be recycled in the first collection container is serialized to store the object to be recycled in the first collection container to the target memory space, and the target memory space is destroyed when the current program ends. The above technical scheme can improve the recycling efficiency and space utilization efficiency of the object to be recycled. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 is a flow chart of a garbage disposal method for a Java virtual machine provided according to Embodiment 1 of the present application;
[0022] Figure 2 is a flow chart of a garbage disposal method for a Java virtual machine provided according to Embodiment 2 of the present application;
[0023] Figure 3 It is a structural schematic diagram of a garbage disposal device of a Java virtual machine provided according to the third embodiment of the present application;
[0024] Figure 4 It is a structural schematic diagram of an electronic device that implements the garbage disposal method of a Java virtual machine according to an embodiment of the present application. DETAILED DESCRIPTION
[0025] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0026] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0027] In addition, it should be noted that the collection, storage, use, processing, transmission, provision and disclosure of relevant data such as current program and candidate program snapshots involved in the technical solution of this application are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0028] Embodiment 1
[0029] Figure 1 This is a flowchart of a Java virtual machine garbage disposal method provided according to the first embodiment of the present application. This embodiment is applicable to the case of optimizing the garbage collection of the Java virtual machine, and can be executed by a Java virtual machine garbage disposal device. The Java virtual machine garbage disposal device can be implemented in the form of hardware and / or software. The Java virtual machine garbage disposal device can be configured in a computer device, such as a server. Figure 1 As shown, the method includes:
[0030] S110. During the execution of the current program, a candidate program snapshot of the current program is obtained, and whether the candidate object meets the garbage collection condition is determined based on the candidate object in the candidate program snapshot and a reference object predetermined by the current program. If so, the candidate object is used as an object to be recycled.
[0031] The current program refers to the program currently running in the Java virtual machine. The candidate program snapshot refers to a static capture of the current running state of the current program, which may include relevant information such as class name, instance number, and byte size. A candidate object refers to an entity that is checked in the candidate program snapshot and is determined to be reclaimed based on the garbage collection criteria. A reference object refers to an object that is confirmed to be still referenced during program execution. It is an active object in the program and will not be recycled.
[0032] Optionally, before obtaining the candidate program snapshot of the current program, a scanning cycle of a preset period is established to scan the proportion of the configured memory of the Java virtual machine occupied by the current program; when the configured memory proportion meets the snapshot extraction condition, an initial program snapshot of the current program is obtained.
[0033] The preset period is set manually based on actual conditions or experience, and may be five minutes. The configuration memory ratio refers to the ratio between the configuration memory used during the current program running and the initial configuration memory of the Java virtual machine. The snapshot extraction condition is set manually based on actual conditions or experience, and may be the number of times the configuration memory ratio reaches 60% for more than five times. The initial program snapshot is a static capture of the current program running state obtained by preprocessing the current program, which may include relevant information such as class name, strength number, and byte size.
[0034] In an optional implementation, obtaining the initial program snapshot of the current program can be by obtaining the program name of the current program when it is running through the management interface of the Java virtual machine; and splitting the program name through a preset delimiter to obtain the program number of the current program; and obtaining the program object data in the current program through the program number; parsing the program object data to establish an initial program snapshot including the class name, number of instances and byte size.
[0035] Among them, the management interface refers to the interface provided by Java for managing and monitoring the runtime status of the Java virtual machine. The program name refers to the runtime name of the Java process, which usually contains multiple runtime information, such as the process identifier and the host name, etc., and can be obtained through the method interface used to obtain the Java virtual machine name in Java. The preset separator refers to the character used to split the program name string, which can be the @ separator, which is used to split the program name into different parts. The program number refers to the program identifier, which is a part extracted from the split program name, usually a unique identifier used to identify a specific instance of the running Java program. The program object data refers to the statistical data of active objects in the Java virtual machine obtained, including information such as the number of instances of each class and the size of bytes occupied. The class name indicates the name of the Java class. The number of instances indicates the number of instances of the class in memory. The byte size indicates the total amount of memory occupied by all instances of the class.
[0036] It should be noted that the number of the initial program snapshot is at least one; accordingly, when the extraction of the initial snapshot meets the extraction stop condition, the acquisition of the initial program snapshot is stopped.
[0037] The extraction stop condition is manually set according to actual conditions or experience values, which may be that the total number of initial program snapshots is 100 or the number of times the CPU usage exceeds 100% during the current program running process within 1 hour reaches 5 times.
[0038] Furthermore, the reference object can be determined in the following manner: traverse the initial program snapshot, determine the initial program object traversed for the first time in the initial program snapshot as the reference object, and put it into the initial collection container; in the subsequent execution of each initial program snapshot, based on the initial collection container, compare the class name corresponding to each object in the initial program snapshot with the number of instances and memory size of the same class name in the initial collection container; if the number of instances and the memory size are the same as the data of the initial collection container, determine the program object in the initial program snapshot as an object to be recycled and put it into a candidate collection container; if the number of instances and the memory size are greater than the data of the initial collection container, replace the data of the initial collection container; if the number of instances and the memory size are less than the data of the initial collection container, mark the program object in the initial program snapshot as a suspected reference object once, and in the subsequent execution of the initial program snapshot, if it is found that the number of instances and the byte size of the program object fluctuate, then determine the program object as a reference object.
[0039] The initial collection container refers to a data structure or class used to store and manage reference objects, and the candidate collection container refers to a data structure or class used to store and manage objects to be recycled.
[0040] Furthermore, a class name list of objects to be recycled is extracted from the candidate collection container, and Java basic class name data is automatically removed; the objects to be recycled in the candidate collection container after the basic class name data is removed are output to a path set used to load classes and resources when the current program is running.
[0041] The basic class name data refers to the most basic data type built into the Java language, which is used to store simple values and may include at least one of an integer type, a floating point type, and a character type.
[0042] S120: Building a first collection container for the objects to be recycled based on a dynamic loading mechanism and a reflection mechanism.
[0043] Among them, the dynamic loading mechanism refers to a mechanism that loads classes or resources as needed when the program is running; in Java, a class loader can be used to dynamically load classes, which allows the program to load specific classes according to conditions or configurations at runtime, rather than determining all required classes at compile time. The reflection mechanism refers to a powerful feature provided by Java that allows the program to check the structure of a class, call object methods, operate on object properties, etc. at runtime; through reflection, the program can obtain class information and dynamically call class methods or create objects without determining these operations at compile time. The first collection container refers to a data structure or class used to store processed objects to be recycled.
[0044] S130: Determine a target memory size according to a first memory size of the first collection container and a second memory size of the current program, and allocate a target memory space for the object to be recycled in the direct memory based on the target memory size.
[0045] The first memory size refers to the size of the memory space occupied by the first collection container. The second memory size refers to the memory size occupied by a data structure or object in the current program. The target memory size refers to the memory size occupied by the target memory space in the direct memory. The target memory space is the direct memory space applied for the object to be recycled in the direct memory. For example, the target memory space can be applied to the direct memory through the method interface used to create a direct byte buffer in Java.
[0046] Exemplarily, the target memory size may be determined by the following formula:
[0047]
[0048] A refers to the target memory size, B refers to the first memory size, and C refers to the second memory size.
[0049] S140: Serialize the objects to be recycled in the first collection container to store them in a target memory space, and destroy the target memory space when the current program ends.
[0050] Serialization refers to the process of converting the object to be recycled into a persistent or transferable format so as to recreate or restore the object in a different system, process or time point.
[0051] Exemplarily, based on the serialization mechanism, the objects to be recycled in the first collection container are serialized into a byte stream; and the objects to be recycled converted into the byte stream are written into the target memory space.
[0052] The serialization mechanism refers to the process of converting the state of an object into a byte stream. A byte stream refers to a linear sequence of bytes.
[0053] The embodiment of the present application obtains a candidate program snapshot of the current program during the execution of the current program, and determines whether the candidate object meets the garbage collection conditions based on the candidate object in the candidate program snapshot and the reference object predetermined by the current program. If so, the candidate object is used as the object to be recycled; based on the dynamic loading mechanism and the reflection mechanism, a first collection container is constructed for the object to be recycled; based on the first memory size of the first collection container and the second memory size of the current program, the target memory size is determined, and based on the target memory size, a target memory space is allocated in the direct memory for the object to be recycled; the object to be recycled in the first collection container is serialized to store the object to be recycled in the first collection container to the target memory space, and the target memory space is destroyed when the current program ends. The above technical scheme can improve the recycling efficiency and space utilization efficiency of the object to be recycled.
[0054] Embodiment 2
[0055] Figure 2 This is a flow chart of a garbage disposal method for a Java virtual machine provided in accordance with the second embodiment of the present application. Based on the technical solutions of the above embodiments, this embodiment refines "building a first collection container for objects to be recycled based on a dynamic loading mechanism and a reflection mechanism" into "determining the type object corresponding to the object to be recycled based on the dynamic loading mechanism and the class name corresponding to the object to be recycled; performing reflection operations on the type object to obtain the object calling method of the object to be recycled; and setting an object screening tool for the object calling method; building a first collection container for objects to be recycled based on the object screening tool". It should be noted that for the parts not described in detail in the embodiments of the present application, please refer to the relevant statements of other embodiments. Figure 2 As shown, the method includes:
[0056] S210. During the execution of the current program, a candidate program snapshot of the current program is obtained, and whether the candidate object meets the garbage collection condition is determined based on the candidate object in the candidate program snapshot and a reference object predetermined by the current program. If so, the candidate object is used as an object to be recycled.
[0057] S220: Based on the dynamic loading mechanism, determine the type object corresponding to the object to be recycled according to the class name corresponding to the object to be recycled.
[0058] Among them, the type object refers to the metadata object of the class, and the class constructor, fields, methods and other information can be obtained through the reflection mechanism.
[0059] Exemplarily, the first collection container is read, and the class object of the object to be recycled is determined by dynamically loading the class name corresponding to the object to be recycled.
[0060] S230: Perform reflection operation on the type object to obtain the object calling method of the object to be recycled; and set an object screening tool for the object calling method.
[0061] The object calling method refers to all methods defined in the class corresponding to the object to be recycled, including the method name, parameter list, return type, etc. The object screening tool refers to a tool for screening the objects to be recycled, which can be a preprocessor dynamically embedded in the method.
[0062] S240: Building a first collection container for the objects to be recycled based on the object screening tool.
[0063] Optionally, it is determined by an object screening tool whether there is a container for the object to be recycled; if there is no container for the object to be recycled, a first collection container is constructed for the object to be recycled according to the correspondence between the object to be recycled and the object attributes of the object to be recycled.
[0064] The correspondence between the object to be recycled and the object attribute of the object to be recycled refers to a correspondence constructed by taking the object to be recycled as a key and the attribute and attribute value of the object to be recycled as a key value.
[0065] Exemplarily, a preprocessor is dynamically implanted inside each method. Based on the preprocessor, it is determined whether there is a first collection container for the current object to be recycled; if not, a first collection container is constructed for the object to be recycled; the key of the container is the current object to be recycled; the key value is a state object created according to the attributes and attribute values of the current object to be recycled, and the current state of the marked current object to be recycled.
[0066] In an optional implementation, an object processing tool is set for the object calling method; if the current program calls the object to be recycled in the first collection container, the object processing tool is used to determine whether the current state of the object to be recycled meets the object calling condition; if so, the object to be recycled is called.
[0067] The object processing tool refers to a tool that determines the state of the current object to be recycled and decides whether it can be called. It can be a post-processor dynamically embedded in the method. The object calling condition is manually set according to the actual situation or experience value. For example, the current state can be the Java virtual machine storage state. The current state is used to describe the storage state of the current object to be recycled, which can include the Java virtual machine storage state and the direct memory storage state.
[0068] Exemplarily, based on the post-processor, the key value of the current object to be recycled is obtained according to the current object to be recycled in the first collection container; according to the key value, it is determined whether the state of the current object to be recycled meets the object calling condition, and if so, it is returned.
[0069] In another optional implementation, after building the first collection container for the current object to be recycled, the value of the attribute of the current object to be recycled is automatically cleared to empty, and a global data trusteeship count is established; when the trusteeship count exceeds 10% of the total storage, garbage collection is automatically triggered to clean up the relevant data of the object to be recycled.
[0070] S250: Determine a target memory size according to a first memory size of the first collection container and a second memory size of the current program, and allocate a target memory space for the object to be recycled in the direct memory based on the target memory size.
[0071] S260: Serialize the objects to be recycled in the first collection container to store them in a target memory space, and destroy the target memory space when the current program ends.
[0072] Optionally, according to the current program, a space destruction thread is created for the target memory space; when it is recognized that the current program has ended, the target memory space is destroyed by destroying the thread.
[0073] Exemplarily, the shutdown hook of the Java virtual machine can be registered through the method interface for registering threads in Java; when the Java program stops, the target memory space is destroyed through the shutdown hook.
[0074] In an optional implementation, after the serialization process, garbage collection is performed on the Java virtual machine.
[0075] In another optional implementation, when an object to be recycled is identified in a calling target memory space, candidate object data of the object to be recycled is read from the target memory space based on the candidate index and candidate memory attributes of the object to be recycled in the target memory space; the candidate object data is deserialized to obtain the target object, and returned.
[0076] The candidate index refers to the SI position (System Integration Position) of the object to be recycled. The candidate memory attribute refers to the SE size (Software Engineering Size) of the object to be recycled. The candidate object data refers to the data obtained by reading the object to be recycled. Deserialization refers to converting the byte stream back into an object.
[0077] The embodiment of the present application obtains a candidate program snapshot of the current program during the execution of the current program, and determines whether the candidate object meets the garbage collection condition based on the candidate object in the candidate program snapshot and the reference object predetermined by the current program. If it meets the condition, the candidate object is used as the object to be recycled; based on the dynamic loading mechanism, the type object corresponding to the object to be recycled is determined according to the class name corresponding to the object to be recycled; the type object is reflected to obtain the object call method of the object to be recycled; and an object screening tool is set for the object call method; based on the object screening tool, a first collection container is constructed for the object to be recycled; based on the first memory size of the first collection container and the second memory size of the current program, the target memory size is determined, and based on the target memory size, the target memory space is allocated in the direct memory for the object to be recycled; the objects to be recycled in the first collection container are serialized to store the objects to be recycled in the first collection container to the target memory space, and the target memory space is destroyed when the current program ends. The above technical scheme can improve the recycling efficiency and space utilization efficiency of the objects to be recycled.
[0078] Embodiment 3
[0079] Figure 3 This is a schematic diagram of the structure of a garbage disposal device for a Java virtual machine provided in accordance with the third embodiment of the present application, which can be applied to the case of optimizing the garbage collection of a Java virtual machine. The garbage disposal device for the Java virtual machine can be implemented in the form of hardware and / or software, and the garbage disposal device for the Java virtual machine can be configured in a computer device, such as a server. Figure 3 As shown, the device comprises:
[0080] The object determination module 310 is used to obtain a candidate program snapshot of the current program during the execution of the current program, and determine whether the candidate object meets the garbage collection condition based on the candidate object in the candidate program snapshot and the reference object predetermined by the current program. If so, the candidate object is used as an object to be recycled;
[0081] A container construction module 320, used to construct a first collection container for the objects to be recycled based on a dynamic loading mechanism and a reflection mechanism;
[0082] The space allocation module 330 is used to determine the target memory size according to the first memory size of the first collection container and the second memory size of the current program, and allocate the target memory space for the object to be recycled in the direct memory based on the target memory size;
[0083] The object processing module 340 is used to serialize the objects to be recycled in the first collection container to store the objects to be recycled in the first collection container into a target memory space, and destroy the target memory space when the current program ends.
[0084] The embodiment of the present application obtains a candidate program snapshot of the current program during the execution of the current program, and determines whether the candidate object meets the garbage collection conditions based on the candidate object in the candidate program snapshot and the reference object predetermined by the current program. If so, the candidate object is used as the object to be recycled; based on the dynamic loading mechanism and the reflection mechanism, a first collection container is constructed for the object to be recycled; based on the first memory size of the first collection container and the second memory size of the current program, the target memory size is determined, and based on the target memory size, a target memory space is allocated in the direct memory for the object to be recycled; the object to be recycled in the first collection container is serialized to store the object to be recycled in the first collection container to the target memory space, and the target memory space is destroyed when the current program ends. The above technical scheme can improve the recycling efficiency and space utilization efficiency of the object to be recycled.
[0085] Optionally, the container construction module 320 includes:
[0086] An object determination unit, used to determine the type object corresponding to the object to be recycled according to the class name corresponding to the object to be recycled based on a dynamic loading mechanism;
[0087] A method determination unit is used to perform a reflection operation on the type object to obtain the object calling method of the object to be recycled; and to set an object screening tool for the object calling method;
[0088] The container construction unit is used to construct a first collection container for the objects to be recycled based on the object screening tool.
[0089] Optional, container building unit, specifically used for:
[0090] Use the object screening tool to determine whether the object to be recycled exists in a container;
[0091] If there is no container for the object to be recycled, a first collection container is constructed for the object to be recycled according to the corresponding relationship between the object to be recycled and the object attribute of the object to be recycled.
[0092] Optionally, the device further includes a first object calling module, and the first object calling module is specifically configured to:
[0093] Set up object handling tools for object call methods;
[0094] If the current program calls the object to be recycled in the first collection container, the object processing tool is used to determine whether the current state of the object to be recycled meets the object calling condition; if so, the object to be recycled is called.
[0095] Optionally, the object processing module 340 is specifically configured to:
[0096] According to the current program, create a space destruction thread for the target memory space;
[0097] When it is recognized that the current program has ended, the target memory space is destroyed by destroying the thread.
[0098] Optionally, the device further includes a second object calling module, wherein the second object calling module is specifically configured to:
[0099] When an object to be recycled in the target memory space is identified, candidate object data of the object to be recycled is read from the target memory space according to a candidate index and a candidate memory attribute of the object to be recycled in the target memory space;
[0100] Deserialize the candidate object data to obtain the target object and return it.
[0101] The garbage disposal device for a Java virtual machine provided in the embodiments of the present application can execute the garbage disposal method for a Java virtual machine provided in any embodiment of the present application, and has functional modules and beneficial effects corresponding to executing the garbage disposal method for each Java virtual machine.
[0102] Embodiment 4
[0103] Figure 4 4 is a schematic diagram of the structure of an electronic device 410 that implements the garbage disposal method of the Java virtual machine of the embodiment of the present application. The electronic device is intended to represent various forms of digital computers, 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 (such as helmets, glasses, watches, etc.) 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 application described and / or required herein.
[0104] like Figure 4As shown, the electronic device 410 includes at least one processor 411, and a memory connected to the at least one processor 411 in communication, such as a read-only memory (ROM) 412, a random access memory (RAM) 413, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 411 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 412 or the computer program loaded from the storage unit 418 to the random access memory (RAM) 413. In RAM413, various programs and data required for the operation of the electronic device 410 can also be stored. The processor 411, ROM412 and RAM413 are connected to each other via a bus 414. An input / output (I / O) interface 415 is also connected to the bus 414.
[0105] Multiple components in the electronic device 410 are connected to the I / O interface 415, including: an input unit 416, such as a keyboard, a mouse, etc.; an output unit 417, such as various types of displays, speakers, etc.; a storage unit 418, such as a disk, an optical disk, etc.; and a communication unit 419, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 419 allows the electronic device 410 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0106] The processor 411 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 411 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 411 executes the various methods and processes described above, such as a garbage disposal method of a Java virtual machine.
[0107] In some embodiments, the garbage disposal method of the Java virtual machine may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 418. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 410 via the ROM 412 and / or the communication unit 419. When the computer program is loaded into the RAM 413 and executed by the processor 411, one or more steps of the garbage disposal method of the Java virtual machine described above may be performed. Alternatively, in other embodiments, the processor 411 may be configured as the garbage disposal method of the Java virtual machine by any other appropriate means (e.g., by means of firmware).
[0108] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0109] The computer programs for implementing the methods of the present application may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a garbage disposal device of a general-purpose computer, a special-purpose computer, or other programmable Java virtual machine, so that when the computer programs are executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer programs may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0110] In the context of the present application, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, device, or equipment. A computer-readable storage 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. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. 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.
[0111] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device 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 a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0112] The systems and techniques described herein may be implemented in a computing system that includes backend 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 frontend 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 backend components, middleware components, or frontend 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), a blockchain network, and the Internet.
[0113] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0114] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this application can be executed in parallel, sequentially or in different orders, as long as the expected results of the technical solution of this application can be achieved, and this document is not limited here.
[0115] The above specific implementations do not constitute a limitation on the protection scope of this application. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of this application should be included in the protection scope of this application.
Claims
1. A garbage disposal method for a Java virtual machine, characterized in that: include: During the execution of the current program, a candidate program snapshot of the current program is obtained, and whether the candidate object meets the garbage collection condition is determined according to the candidate object in the candidate program snapshot and the reference object predetermined by the current program, and if so, the candidate object is used as an object to be recycled; the candidate program snapshot refers to a static capture of the current running state of the current program; Based on the dynamic loading mechanism and the reflection mechanism, construct a first collection container for the object to be recycled; Determine a target memory size according to a first memory size of the first collection container and a second memory size of the current program, and allocate a target memory space for the object to be recycled in direct memory based on the target memory size; Serializing the objects to be recycled in the first collection container to store the objects to be recycled in the first collection container into the target memory space, and destroying the target memory space when the current program ends. The step of constructing a first collection container for the object to be recycled based on the dynamic loading mechanism and the reflection mechanism includes: Based on the dynamic loading mechanism, determining the type object corresponding to the object to be recycled according to the class name corresponding to the object to be recycled; Performing a reflection operation on the type object to obtain an object calling method of the object to be recycled; and setting an object screening tool for the object calling method; Based on the object screening tool, construct a first collection container for the objects to be recycled; The step of constructing a first collection container for the objects to be recycled based on the object screening tool includes: By using the object screening tool, determining whether the object to be recycled exists in a container; If no container exists for the object to be recycled, a first collection container is constructed for the object to be recycled according to a correspondence between the object to be recycled and an object attribute of the object to be recycled.
2. The method according to claim 1, characterized in that: After performing a reflection operation on the type object to obtain the object calling method of the object to be recycled, the method further includes: Setting an object processing tool for the object calling method; If the current program calls the object to be recycled in the first collection container, the object processing tool is used to determine whether the current state of the object to be recycled meets the object calling condition; if so, the object to be recycled is called.
3. The method according to claim 1, characterized in that When the current program ends, destroying the target memory space includes: According to the current program, creating a space destruction thread for the target memory space; When it is identified that the current program has ended, the target memory space is destroyed through the destruction thread.
4. The method according to claim 1, characterized in that: After storing the objects to be recycled in the first collection container into the target memory space, the method further includes: In the case of identifying that the object to be recycled in the target memory space is called, reading candidate object data of the object to be recycled from the target memory space according to the candidate index and candidate memory attribute of the object to be recycled in the target memory space; Deserialize the candidate object data to obtain the target object and return it.
5. A garbage disposal device for a Java virtual machine, characterized in that: include: An object determination module is used to obtain a candidate program snapshot of the current program during the execution of the current program, and determine whether the candidate object meets the garbage collection condition based on the candidate object in the candidate program snapshot and the reference object predetermined by the current program, and if so, the candidate object is used as an object to be recycled; the candidate program snapshot refers to a static capture of the current running state of the current program; A container construction module, used to construct a first collection container for the object to be recycled based on a dynamic loading mechanism and a reflection mechanism; a space allocation module, configured to determine a target memory size according to a first memory size of the first collection container and a second memory size of the current program, and allocate a target memory space for the to-be-reclaimed object in direct memory based on the target memory size; an object processing module, configured to serialize the objects to be recycled in the first collection container so as to store the objects to be recycled in the first collection container into the target memory space, and to destroy the target memory space when the current program ends; The container building module includes: An object determination unit, used to determine the type object corresponding to the object to be recycled according to the class name corresponding to the object to be recycled based on a dynamic loading mechanism; A method determination unit is used to perform a reflection operation on the type object to obtain the object calling method of the object to be recycled; and to set an object screening tool for the object calling method; A container construction unit, used to construct a first collection container for the objects to be recycled based on the object screening tool; Wherein, the container construction unit is specifically used for: Use the object screening tool to determine whether the object to be recycled exists in a container; If there is no container for the object to be recycled, a first collection container is constructed for the object to be recycled according to the corresponding relationship between the object to be recycled and the object attribute of the object to be recycled.
6. An electronic device, characterized in that: include: one or more processors; A memory for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the garbage disposal method for a Java virtual machine as described in any one of claims 1 to 4.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the garbage disposal method for a Java virtual machine as described in any one of claims 1 to 4 is implemented.
8. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the garbage processing method for a Java virtual machine according to any one of claims 1 to 4.
