Java virtual machine garbage disposal method, device and equipment and storage medium
By obtaining candidate program snapshots and building collection containers in the Java virtual machine, and using the dynamic loading mechanism and reflection mechanism to allocate space in direct memory for serialization processing, the low garbage collection efficiency and low space utilization of the old generation area of the Java virtual machine are solved. problem, enabling more efficient recycling and space management.
Patent Information
- Application Number
- CN202411053116.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-02
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2044-08-02
AI Technical Summary
When the Java virtual machine performs garbage collection in the old generation area, it is easy to cause application suspension, CPU usage reaching 100%, application crash, and low space utilization efficiency.
By obtaining the candidate program snapshot of the current program, determine whether the candidate object meets the garbage collection conditions, build a collection container based on the dynamic loading mechanism and reflection mechanism, and allocate the target memory space in direct memory for serialization processing. The objects to be recycled are collected at the end of the program. Destroy the target memory space.
It improves the recycling efficiency and space utilization efficiency of objects to be recycled, and avoids the problem of pauses and crashes during garbage collection in the old generation area.
Smart Images

Figure CN118606008A
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and more particularly to the field of Java Virtual Machine technology, specifically to a method, apparatus, device, and storage medium for garbage disposal in a Java Virtual Machine. Background Technology
[0002] In Java program execution, there is a division between the young generation and the old generation. After an object is created in memory, it first enters the young generation. After object reference judgment and reclamation in Eden (Eden Space), s0 (Survivor Space 0), and s1 (Survivor Space 1), objects that are not reclaimed enter the old generation, or large objects directly enter the old generation.
[0003] After garbage collection in the young generation, a batch of objects need to be moved to the old generation. At this time, the old generation does not have enough memory space to store these objects, so garbage collection in the old generation must be triggered immediately. Garbage collection in the old generation will also be triggered when the memory usage of the old generation exceeds 92%. When the old generation is being collected, the application may be paused, the CPU usage may reach 100%, or the application may crash. Summary of the Invention
[0004] This 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 this application, a garbage collection method for a Java Virtual Machine is provided, the method comprising:
[0006] During the execution of the current program, a snapshot of the candidate program is obtained, and the candidate object is determined to meet the garbage collection conditions based on the candidate object in the snapshot and the reference object predetermined by the current program. If the conditions are met, the candidate object is designated as an object to be collected.
[0007] Based on dynamic loading and reflection mechanisms, a first collection container is constructed for the objects to be recycled.
[0008] Based on the first memory size of the first collection container and the second memory size of the current program, a target memory size is determined, and based on the target memory size, a target memory space is allocated in direct memory for the object to be reclaimed;
[0009] The objects to be recycled in the first collection container are serialized to store them in the target memory space, and the target memory space is destroyed when the current program finishes running.
[0010] According to another aspect of this application, a garbage disposal apparatus for a Java Virtual Machine is provided, the apparatus comprising:
[0011] The object determination module is used to obtain a snapshot of the candidate program of the current program during the execution of the current program, and determine whether the candidate object meets the garbage collection conditions based on the candidate object in the candidate program snapshot and the reference object pre-determined by the current program. If it meets the conditions, the candidate object is regarded as an object to be collected.
[0012] A container building module is used to construct a first collection container for the objects to be recycled based on a dynamic loading mechanism and a reflection mechanism.
[0013] The space allocation module is used to determine the target memory size based on the first memory size of the first collection container and the second memory size of the current program, and to allocate target memory space for the object to be reclaimed 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, so as 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 finishes running.
[0015] According to another aspect of this application, an electronic device is provided, the electronic device comprising:
[0016] One or more processors;
[0017] Memory, used to store 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 of the Java Virtual Machine garbage collection methods provided in the embodiments of this application.
[0019] According to another aspect of this application, a computer-readable storage medium is provided, on which a computer program is stored, which, when executed by a processor, implements any of the Java Virtual Machine garbage disposal methods provided in the embodiments of this application.
[0020] This application improves the garbage collection efficiency and space utilization efficiency of garbage collection objects by obtaining a snapshot of candidate programs during the execution of the current program, and determining whether the candidate objects meet the garbage collection conditions based on the candidate objects in the snapshot and the reference objects predetermined by the current program. If they meet the conditions, the candidate objects are designated as objects to be collected. A first collection container is constructed for the objects to be collected based on a dynamic loading mechanism and a reflection mechanism. A target memory size is determined based on a first memory size of the first collection container and a second memory size of the current program. Based on the target memory size, target memory space is allocated in direct memory for the objects to be collected. The objects to be collected in the first collection container are serialized to store them in the target memory space. The target memory space is then destroyed when the current program terminates. This technical solution improves the garbage collection efficiency and space utilization efficiency of the objects to be collected. Attached Figure Description
[0021] Figure 1 This is a flowchart of a garbage disposal method for a Java Virtual Machine according to Embodiment 1 of this application;
[0022] Figure 2 This is a flowchart of a garbage disposal method for a Java Virtual Machine according to Embodiment 2 of this application;
[0023] Figure 3 This is a schematic diagram of the structure of a garbage disposal device for a Java Virtual Machine according to Embodiment 3 of this application;
[0024] Figure 4 This is a schematic diagram of the structure of an electronic device that implements the garbage disposal method of the Java Virtual Machine according to the embodiments of this application. Detailed Implementation
[0025] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort 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, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0027] Furthermore, 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 all comply with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0028] Example 1
[0029] Figure 1 This is a flowchart of a garbage collection method for a Java Virtual Machine (JVM) according to Embodiment 1 of this application. This embodiment is applicable to situations where garbage collection for a JVM is optimized. It can be executed by a JVM garbage collection device, which can be implemented in hardware and / or software and 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, obtain a snapshot of the candidate program of the current program, and determine 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 it meets the conditions, then the candidate object is regarded as an object to be collected.
[0031] Here, "current program" refers to the program currently running in the Java Virtual Machine. A candidate program snapshot is a static capture of the current program's runtime state, which may include information such as class name, instance size, and byte size. A candidate object is an entity examined in the candidate program snapshot and its eligibility for garbage collection is determined based on garbage collection criteria. A reference object is an object that is still referenced during program execution; it is an active object in the program and will not be garbage collected.
[0032] Optionally, before obtaining a candidate program snapshot of the current program, a preset scanning period is established to scan the proportion of the configured memory occupied by the current program in the Java Virtual Machine; when the configured memory proportion meets the snapshot extraction conditions, the initial program snapshot of the current program is obtained.
[0033] The preset period is set manually based on actual conditions or experience, and can be as low as five minutes. The configured memory ratio refers to the ratio between the configured memory used during the current program's execution and the initial configured memory of the Java Virtual Machine. The snapshot extraction condition is set manually based on actual conditions or experience, and can be that the configured memory ratio reaches 60% more than 5 times. The initial program snapshot is a static capture of the current program's running state obtained after preprocessing, and may include relevant information such as class names, instance count, and size in bytes.
[0034] In one optional implementation, obtaining the initial program snapshot of the current program can be achieved by: obtaining the program name of the current program at runtime through the Java Virtual Machine's management interface; splitting the program name using a preset delimiter to obtain the program number of the current program; obtaining the program object data in the current program through the program number; parsing the program object data to establish an initial program snapshot containing class names, number of instances, and byte size.
[0035] The management interface refers to the interface provided by Java for managing and monitoring the runtime state of the Java Virtual Machine. The program name refers to the runtime name of the Java process, typically containing several runtime information such as the process identifier and hostname, which can be obtained through Java methods for retrieving the Java Virtual Machine name. The default separator is the character used to separate the program name string; it can be the @ separator, used to divide the program name into different parts. The program number is the program identifier, extracted from the segmented program name, usually a unique identifier used to identify a specific instance of the running Java program. Program object data refers to the statistical data of active objects in the Java Virtual Machine, including the number of instances of each class and the size in bytes occupied. The class name represents the name of the Java class. The instance count represents the number of instances of that class in memory. The size in bytes represents the total memory occupied by all instances of that class.
[0036] It should be noted that there is at least one initial program snapshot; correspondingly, the acquisition of initial program snapshots will stop when the extraction of initial snapshots meets the extraction stop condition.
[0037] The extraction stop condition is set manually based on actual conditions or experience. It can be that the total number of initial program snapshots is 100 or the CPU usage exceeds 100% five times within one hour during the current program's operation.
[0038] Furthermore, reference objects can be determined in the following way: Traverse the initial program snapshot, identify the first initial program object encountered in the initial program snapshot as a reference object, and place it in the initial collection container; during the execution of each subsequent 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 memory size are the same as the data in the initial collection container, then the program object in the initial program snapshot is identified as an object to be reclaimed and placed in the candidate collection container; if the number of instances and memory size are greater than the data in the initial collection container, then the data in the initial collection container is replaced; if the number of instances and memory size are less than the data in the initial collection container, then the program object in the initial program snapshot is marked as a suspected reference object once. During the execution of subsequent initial program snapshots, if the number of instances and the size in bytes of this program object fluctuate, then this program object is identified as a reference object.
[0039] The initial collection container refers to the data structure or class used to store and manage reference objects. The candidate collection container refers to the data structure or class used to store and manage objects to be garbage collected.
[0040] Furthermore, the list of class names of objects to be recycled is extracted from the candidate collection container, and the basic Java class name data is automatically removed; the objects to be recycled in the candidate collection container after removing the basic class name data are output to the path set used for loading classes and resources at the current program runtime.
[0041] Among them, basic class name data refers to the most basic data type built into the Java language, used to store simple values, and can include at least one of integer type, floating-point type and character type.
[0042] S120. Based on the dynamic loading mechanism and reflection mechanism, construct the first collection container for the objects to be recycled.
[0043] Dynamic loading refers to the mechanism of loading classes or resources as needed at runtime. In Java, class loaders can be used to dynamically load classes, allowing the program to load specific classes at runtime based on conditions or configurations, rather than determining all necessary classes at compile time. Reflection is a powerful feature provided by Java that allows programs to inspect class structure, call object methods, and manipulate object attributes at runtime. Through reflection, programs can obtain class information and dynamically call class methods or create objects without needing to determine these operations at compile time. The first collection container refers to a data structure or class used to store processed objects awaiting garbage collection.
[0044] S130. Determine the target memory size based on the first memory size of the first collection container and the second memory size of the current program, and allocate target memory space for the objects to be reclaimed in direct memory based on the target memory size.
[0045] Here, 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 size of the memory occupied by a certain data structure or object in the current program. The target memory size refers to the size of the memory occupied by the target memory space in direct memory. The target memory space is the direct memory space allocated for the object to be garbage collected in direct memory. For example, the target memory space can be allocated from direct memory through the method interface used in Java to create direct byte buffers.
[0046] For example, the target memory size can be determined by the following formula:
[0047]
[0048] Where 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 the target memory space, and destroy the target memory space when the current program ends.
[0050] Serialization refers to the process of converting objects to be recycled into a persistent or transmissible format so that the objects can be recreated or restored in different systems, processes, or points in time.
[0051] For example, based on the serialization mechanism, the objects to be recycled in the first collection container are serialized into a byte stream; the objects to be recycled, converted into byte streams, are written into the target memory space.
[0052] Serialization refers to the process of converting the state of an object into a byte stream. A byte stream is a linear sequence of bytes.
[0053] This application embodiment obtains a snapshot of candidate programs during the execution of the current program, and determines whether a candidate object meets the garbage collection conditions based on the candidate objects in the snapshot and a pre-determined reference object in the current program. If it does, the candidate object is designated as a garbage-collecting object. A first collection container is constructed for the garbage-collecting objects based on a dynamic loading mechanism and a reflection mechanism. A target memory size is determined based on a first memory size of the first collection container and a second memory size of the current program, and target memory space is allocated for the garbage-collecting objects in direct memory based on the target memory size. The garbage-collecting objects in the first collection container are serialized to store them in the target memory space, and the target memory space is destroyed when the current program finishes running. This technical solution can improve the garbage collection efficiency and space utilization efficiency of garbage-collecting objects.
[0054] Example 2
[0055] Figure 2 This is a flowchart of a Java Virtual Machine garbage collection method according to Embodiment 2 of this application. Based on the technical solutions of the above embodiments, this embodiment refines "constructing a first collection container for objects to be garbage collected based on a dynamic loading mechanism and a reflection mechanism" to "based on a dynamic loading mechanism, determining the type object corresponding to the object to be garbage collected according to the class name of the object to be garbage collected; performing reflection on the type object to obtain the object calling method of the object to be garbage collected; and setting an object filtering tool for the object calling method; constructing a first collection container for the objects to be garbage collected based on the object filtering tool." It should be noted that for parts not detailed in this embodiment, please refer to the relevant descriptions in other embodiments. Figure 2 As shown, the method includes:
[0056] S210. During the execution of the current program, obtain a snapshot of the candidate program of the current program, and determine 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 it meets the conditions, then the candidate object is regarded as an object to be collected.
[0057] S220. Based on the dynamic loading mechanism, determine the type object corresponding to the object to be garbage collected according to the class name of the object to be garbage collected.
[0058] Among them, the type object refers to the metadata object of the class, which can obtain information such as the class's constructor, fields, and methods through reflection.
[0059] For example, 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 on the type object to obtain the object call method of the object to be garbage collected; and set up an object filtering tool for the object call method.
[0061] Here, "object method invocation" refers to all methods defined in the class corresponding to the object to be garbage collected, including the method name, parameter list, return type, etc. "Object filtering tool" refers to the tool used to filter objects to be garbage collected; it can be a pre-processor dynamically implanted within a method.
[0062] S240. Based on the object filtering tool, construct a first collection container for the objects to be recycled.
[0063] Optionally, an object filtering tool can be used to determine whether a container exists for the objects to be recycled; if no container exists for the objects to be recycled, a first collection container can be constructed for the objects to be recycled based on the correspondence between the objects to be recycled and their object attributes.
[0064] The correspondence between objects to be recycled and their attributes refers to the correspondence constructed by using the object to be recycled as the key and its attributes and attribute values as key-value pairs.
[0065] For example, a preprocessor is dynamically implanted inside each method. Based on the preprocessor, it is determined whether the first collection container exists for the object to be recycled; if not, the first collection container is constructed for the object to be recycled; the key of the container is the object to be recycled; the key value is a state object created based on the attributes and attribute values of the object to be recycled, and the current state of the object to be recycled is marked.
[0066] In one alternative implementation, an object processing tool is set up for object invocation methods; if the current program calls an object to be reclaimed in the first collection container, the object processing tool determines whether the current state of the object to be reclaimed meets the object invocation conditions; if it does, the object to be reclaimed is invoked.
[0067] Object processing tools refer to tools that determine the state of objects awaiting garbage collection and decide whether they can be invoked. These tools can be dynamically implanted post-processors within methods. Object invocation conditions are set manually based on actual circumstances or experience; for example, the current state could be the Java Virtual Machine (JVM) storage state. The current state describes the storage state of the object awaiting garbage collection and can include both JVM storage state and direct memory storage state.
[0068] For example, based on the post-processor, the key value of the object to be recycled is obtained according to the object to be recycled in the first collection container; based on the key value, it is determined whether the state of the object to be recycled meets the object call condition, and if it does, it is returned.
[0069] In another alternative implementation, after constructing the first collection container for the current objects to be reclaimed, the values of the attributes of the current objects to be reclaimed are automatically cleared to null, and a global data management count is established; if the management count exceeds 10% of the total storage, garbage collection is automatically triggered to clean up the relevant data of the objects to be reclaimed.
[0070] S250. Determine the target memory size based on the first memory size of the first collection container and the second memory size of the current program, and allocate target memory space for the objects to be reclaimed in 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 the target memory space, and destroy the target memory space when the current program ends.
[0072] Optionally, a space destruction thread can be created for the target memory space based on the current program; if the current program is detected to have ended, the target memory space can be destroyed through the destruction thread.
[0073] For example, a Java Virtual Machine shutdown hook can be registered through the Java method interface used to register threads; when the Java program stops, the target memory space is destroyed through the shutdown hook.
[0074] In one alternative implementation, a garbage collection is performed on the Java Virtual Machine after serialization.
[0075] In another alternative implementation, when an object to be reclaimed is identified in the target memory space, candidate object data of the object to be reclaimed is read from the target memory space according to the candidate index and candidate memory attributes of the object to be reclaimed; the candidate object data is deserialized to obtain the target object, and then returned.
[0076] Here, candidate index refers to the System Integration Position (SI) of the object to be reclaimed. Candidate memory attribute refers to the Software Engineering Size (SE) of the object to be reclaimed. Candidate object data refers to the data obtained from reading the object to be reclaimed. Deserialization refers to converting the byte stream back into an object.
[0077] This application embodiment improves garbage collection efficiency and space utilization by acquiring a snapshot of candidate programs during the execution of the current program, and determining whether the candidate objects in the snapshot meet the garbage collection conditions based on the candidate objects and pre-determined reference objects in the current program. If they do, the candidate objects are designated as objects to be garbage collected. Based on a dynamic loading mechanism, the type object corresponding to the object to be garbage collected is determined according to its class name. Reflection is performed on the type object to obtain the object call method of the object to be garbage collected. An object filtering tool is set for the object call method. Based on the object filtering tool, a first collection container is constructed for the objects to be garbage collected. A target memory size is determined based on the first memory size of the first collection container and the second memory size of the current program. Based on the target memory size, target memory space is allocated in direct memory for the objects to be garbage collected. The objects to be garbage collected in the first collection container are serialized to store them in the target memory space. The target memory space is then destroyed when the current program terminates. This technical solution improves the garbage collection efficiency and space utilization efficiency of the objects to be garbage collected.
[0078] Example 3
[0079] Figure 3 This is a schematic diagram of a garbage collection device for a Java Virtual Machine (JVM) according to Embodiment 3 of this application. It is applicable to situations where garbage collection for a JVM is optimized. This JVM garbage collection device can be implemented in hardware and / or software and can be configured in a computer device, such as a server. Figure 3 As shown, the device includes:
[0080] The object determination module 310 is used to obtain a snapshot of the candidate program during the execution of the current program, and determine whether the candidate object meets the garbage collection conditions based on the candidate object in the candidate program snapshot and the reference object pre-determined by the current program. If it meets the conditions, the candidate object is regarded as an object to be collected.
[0081] Container building module 320 is used to build the first collection container for objects to be recycled based on dynamic loading and reflection mechanisms.
[0082] The space allocation module 330 is used to determine the target memory size based on the first memory size of the first collection container and the second memory size of the current program, and to allocate target memory space for the objects to be reclaimed in 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, so as 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.
[0084] This application embodiment obtains a snapshot of candidate programs during the execution of the current program, and determines whether a candidate object meets the garbage collection conditions based on the candidate objects in the snapshot and a pre-determined reference object in the current program. If it does, the candidate object is designated as a garbage-collecting object. A first collection container is constructed for the garbage-collecting objects based on a dynamic loading mechanism and a reflection mechanism. A target memory size is determined based on a first memory size of the first collection container and a second memory size of the current program, and target memory space is allocated for the garbage-collecting objects in direct memory based on the target memory size. The garbage-collecting objects in the first collection container are serialized to store them in the target memory space, and the target memory space is destroyed when the current program finishes running. This technical solution can improve the garbage collection efficiency and space utilization efficiency of garbage-collecting objects.
[0085] Optional, container building block 320 includes:
[0086] The object determination unit is used to determine the type of object to be garbage collected based on the class name of the object to be garbage collected, using a dynamic loading mechanism.
[0087] The method determination unit is used to perform reflection operations on type objects to obtain the object call methods of the objects to be garbage collected; and to set up object filtering tools for the object call methods.
[0088] The container building unit is used to build the first collection container for objects to be recycled based on the object filtering tool.
[0089] Optional, container building blocks, specifically used for:
[0090] Use object filtering tools to determine if the objects to be recycled exist in a container;
[0091] If no container exists for the objects to be recycled, a first collection container is constructed for the objects to be recycled based on the correspondence between the objects to be recycled and their object attributes.
[0092] Optionally, the device further includes a first object invocation module, which is specifically used for:
[0093] Set up object handling tools for calling methods on an object;
[0094] If the current program calls an object to be garbage collected in the first collection container, the object processing tool will determine whether the current state of the object to be garbage collected meets the object call conditions; if it does, the object to be garbage collected will be called.
[0095] Optional, object processing module 340, specifically used for:
[0096] Based on the current program, create a space destruction thread for the target memory space;
[0097] Upon detecting that the current program has terminated, the target memory space is destroyed by destroying the thread.
[0098] Optionally, the device further includes a second object invocation module, which is specifically used for:
[0099] If an object to be reclaimed is identified in the target memory space, the candidate object data of the object to be reclaimed is read from the target memory space according to the candidate index and candidate memory attributes of the object to be reclaimed.
[0100] The candidate object data is deserialized to obtain the target object, and then returned.
[0101] The garbage disposal device for the Java Virtual Machine provided in this application can execute the garbage disposal method for the Java Virtual Machine provided in any embodiment of this application, and has the corresponding functional modules and beneficial effects for executing the garbage disposal method for each Java Virtual Machine.
[0102] Example 4
[0103] Figure 4 This is a schematic diagram of the structure of an electronic device 410 implementing the garbage collection method of the Java Virtual Machine according to embodiments of this 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 processors, cellular phones, smartphones, 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 illustrative and are not intended to limit the implementation of the application described and / or claimed herein.
[0104] like Figure 4As shown, the electronic device 410 includes at least one processor 411 and a memory, such as a read-only memory (ROM) 412 or a random access memory (RAM) 413, communicatively connected to the at least one processor 411. The memory stores computer programs executable by the at least one processor. The processor 411 can perform various appropriate actions and processes based on the computer program stored in the ROM 412 or loaded from storage unit 418 into the RAM 413. The RAM 413 may also store various programs and data required for the operation of the electronic device 410. The processor 411, ROM 412, and RAM 413 are interconnected via a bus 414. An input / output (I / O) interface 415 is also connected to the bus 414.
[0105] Multiple components in electronic device 410 are connected to I / O interface 415, including: input unit 416, such as keyboard, mouse, etc.; output unit 417, such as various types of displays, speakers, etc.; storage unit 418, such as disk, optical disk, etc.; and communication unit 419, such as network card, modem, wireless transceiver, etc. Communication unit 419 allows electronic device 410 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0106] Processor 411 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 411 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 411 performs the various methods and processes described above, such as the garbage collection methods of the Java Virtual Machine.
[0107] In some embodiments, the Java Virtual Machine (JVM) garbage collection method can be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 418. In some embodiments, part or all of the computer program can be loaded and / or installed on electronic device 410 via ROM 412 and / or communication unit 419. When the computer program is loaded into RAM 413 and executed by processor 411, one or more steps of the JVM garbage collection method described above can be performed. Alternatively, in other embodiments, processor 411 can be configured as the JVM garbage collection method by any other suitable means (e.g., by means of firmware).
[0108] Various embodiments 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-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0109] Computer programs used to implement the methods of this application may be written in any combination of one or more programming languages. These computer programs may be provided to the processor of a general-purpose computer, a special-purpose computer, or other programmable Java Virtual Machine garbage collection device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The computer programs may execute entirely on the machine, partially on the machine, as a standalone software package partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0110] In the context of this application, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium can be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0111] To provide interaction with a user, the systems and techniques described herein can 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 pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0112] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0113] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0114] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this application can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this application can be achieved, and this is not limited herein.
[0115] The specific embodiments described above do not constitute a limitation on the scope of protection of this application. Those skilled in the art should understand 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 within the scope of protection 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; 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; 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.
2. The method according to claim 1, characterized in that Based on the dynamic loading mechanism and the reflection mechanism, a first collection container is constructed for the object to be recycled, including: 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, a first collection container is constructed for the objects to be recycled.
3. The method according to claim 2, characterized in that Based on the object screening tool, constructing a first collection container for the objects to be recycled 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.
4. The method according to claim 2, 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.
5. 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.
6. 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.
7. 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; 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; 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.
8. 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 6.
9. 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 6 is implemented.
10. 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 6.
Citation Information
Patent Citations
Computer system based on virtualization technology and virtual machine generating method
CN102177503A
Dynamic module loading method and device
CN106354533A
Garbage collection method, device and equipment for Java virtual machine and storage medium
CN109669759A
Virtual machine container for applications
CN112368678A
Virtual machine memory processing method and device, electronic equipment and storage medium
CN115390993A
