CN114527985A - Memory overflow method based on JAVA - Google Patents

Memory overflow method based on JAVA Download PDF

Info

Publication number
CN114527985A
CN114527985A CN202111669868.7A CN202111669868A CN114527985A CN 114527985 A CN114527985 A CN 114527985A CN 202111669868 A CN202111669868 A CN 202111669868A CN 114527985 A CN114527985 A CN 114527985A
Authority
CN
China
Prior art keywords
objects
stack
memory
traversing
java
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111669868.7A
Other languages
Chinese (zh)
Inventor
尤松波
周正虎
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tianyi Electronic Commerce Co Ltd
Original Assignee
Tianyi Electronic Commerce Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tianyi Electronic Commerce Co Ltd filed Critical Tianyi Electronic Commerce Co Ltd
Priority to CN202111669868.7A priority Critical patent/CN114527985A/en
Publication of CN114527985A publication Critical patent/CN114527985A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/443Optimisation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • G06F12/0253Garbage collection, i.e. reclamation of unreferenced memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44557Code layout in executable memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45504Abstract machines for programme code execution, e.g. Java virtual machine [JVM], interpreters, emulators
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2212/00Indexing scheme relating to accessing, addressing or allocation within memory systems or architectures
    • G06F2212/10Providing a specific technical effect
    • G06F2212/1041Resource optimization
    • G06F2212/1044Space efficiency improvement

Abstract

The invention discloses a memory overflow method based on JAVA, and relates to the technical field of IT and software development. The method comprises the following steps: firstly, defining a stack as a root; traversing all the references of the objects in the stack by using a common traversal mode of for circulation or a recursive traversal mode of the stack; traversing the objects in the stack again by using a method for traversing the stack objects; searching objects which are not pointed to in the heap by the reference of the objects in the stack, using a built-in callable function to check whether the objects can be called, wherein the objects which are not referred to are unreachable objects, and performing garbage collection on the unreachable objects, thereby reducing memory leakage. The invention reasonably arranges the utilization of the occupied space of the data, releases the unnecessary resource space, reduces the hidden danger of memory leakage, reduces the memory overflow condition caused by the hidden danger, ensures the normal operation of the server and has wide application prospect.

Description

Memory overflow method based on JAVA
Technical Field
The invention relates to the technical field of IT and software development, in particular to a memory overflow method based on JAVA.
Background
In daily production development, when a program cannot work normally in a server, a server log may generate an error report of memory overflow, because the virtual memory space of the JVM is not enough to support the normal operation of the program, and part of the reason for this is that resources cannot be reasonably used. Although JAVA is one of garbage collection languages, developers do not need to specially manage memory allocation, a lot of memory leakage possibility still exists in JAVA, if the memory leakage is not well handled, an APP memory unit cannot be released and wasted, and finally, a memory all occupies a stack (heap) and explodes, so that a program crashes. At present, the general solution is to extend the memory of the physical machine, or to implement the memory monitoring operation, find the memory leakage and automatically restart the system, but the problem of memory leakage cannot be solved from the root cause. Based on this, it is necessary to develop a JAVA-based memory overflow method.
Disclosure of Invention
Aiming at the defects in the prior art, the invention aims to provide a JAVA-based memory overflow method, which reasonably arranges the utilization of data occupied space, releases unnecessary resource space, reduces the hidden danger of memory leakage, reduces the memory overflow condition caused by the hidden danger, enables a server to normally operate and is easy to popularize and use.
In order to achieve the purpose, the invention is realized by the following technical scheme: a memory overflow method based on JAVA comprises the following steps:
(1) firstly, defining a stack as root;
(2) traversing references of all objects in the stack;
(3) traversing the objects in the stack again;
(4) the objects which are not pointed to in the heap are searched by the reference of the objects in the stack, and a built-in callable function callable (func) is used for checking whether the objects can be called or not, the objects which are not referred to are unreachable objects, and the unreachable objects are subjected to garbage collection, so that the memory leakage is reduced.
Preferably, the step (2) traverses the objects in the stack by using a common traversal mode of a for loop or a recursive traversal mode of the stack.
Preferably, the step (3) uses a method of traversing stack objects to traverse objects in the heap.
The invention has the beneficial effects that: the method carries out code optimization from the bottom layer of the JVM virtual machine, reasonably arranges the utilization of the occupied space of data, and releases the unnecessary resource space, thereby reducing the hidden danger of memory leakage, reducing the memory overflow condition caused by the hidden danger, leading the server to normally run and having wide application prospect.
Drawings
The invention is described in detail below with reference to the drawings and the detailed description;
FIG. 1 is a main flow diagram of the present invention;
FIG. 2 is a flow chart of the present invention.
Detailed Description
In order to make the technical means, the creation characteristics, the achievement purposes and the effects of the invention easy to understand, the invention is further described with the specific embodiments.
Referring to fig. 1-2, the following technical solutions are adopted in the present embodiment: a memory overflow method based on JAVA comprises the following steps:
(1) firstly, defining a stack as root;
(2) reference traversing all objects in the stack: objects in the stack can be traversed by using a common traversal mode of a for loop or a recursive traversal mode of the stack;
(3) the objects in the stack are traversed again: traversing objects in the heap by using a method of traversing stack objects;
(4) the method comprises the steps that the objects in the stack are deleted after the referencing of the objects in the stack is finished, the objects which are not pointed to in the stack are searched through the referencing of the objects in the stack, a built-in callable function callable (func) is used for checking whether the objects can be called or not, False is returned to be certain to be not called, the objects which are not referenced are unreachable objects, and the unreachable objects are subjected to garbage collection, so that memory leakage is reduced.
In the code level, the embodiment redefines the objects by using the WeakReference in a mode of excessively turning strong and weak references, does not refer to the objects as soft reference objects, and automatically points the objects without indication and any strong reference objects to the objects when the memory is insufficient to perform garbage collection.
The specific implementation mode runs in a virtual data storage area created by JVM according to java, code optimization is carried out from the bottom layer of the JVM, according to the characteristics of the memory, the problem of memory leakage caused by an unreached object is thoroughly solved from the code layer and the bottom dimension of the JVM, utilization of data occupied space can be reasonably arranged, unnecessary resource space is released, the problem of memory overflow caused by memory leakage is solved, hidden danger of memory leakage is reduced, the memory overflow condition caused by memory leakage is reduced, the server runs normally, cost expenditure of an enterprise to the server can be reduced, maintenance cost of the server is reduced, the server is efficiently used, production efficiency of the server is improved, downtime is reduced, and the method has a wide market application prospect.
The foregoing shows and describes the general principles and broad features of the present invention and advantages thereof. It will be understood by those skilled in the art that the present invention is not limited to the embodiments described above, which are described in the specification and illustrated only to illustrate the principle of the present invention, but that various changes and modifications may be made therein without departing from the spirit and scope of the present invention, which fall within the scope of the invention as claimed. The scope of the invention is defined by the appended claims and equivalents thereof.

Claims (3)

1. A memory overflow method based on JAVA is characterized by comprising the following steps:
(1) firstly, defining a stack as root;
(2) traversing references of all objects in the stack;
(3) traversing the objects in the stack again;
(4) the objects which are not pointed to in the heap are searched by the reference of the objects in the stack, and a built-in callable function callable (func) is used for checking whether the objects can be called or not, the objects which are not referred to are unreachable objects, and the unreachable objects are subjected to garbage collection, so that the memory leakage is reduced.
2. The JAVA-based memory overflow method of claim 1, wherein step (2) uses a normal traversal mode of for loop or a recursive traversal mode of stack to traverse objects in the stack.
3. A JAVA based memory overflow method as claimed in claim 1, wherein step (3) uses a method of traversing stack objects to traverse objects in the heap.
CN202111669868.7A 2021-12-30 2021-12-30 Memory overflow method based on JAVA Pending CN114527985A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111669868.7A CN114527985A (en) 2021-12-30 2021-12-30 Memory overflow method based on JAVA

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111669868.7A CN114527985A (en) 2021-12-30 2021-12-30 Memory overflow method based on JAVA

Publications (1)

Publication Number Publication Date
CN114527985A true CN114527985A (en) 2022-05-24

Family

ID=81620462

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111669868.7A Pending CN114527985A (en) 2021-12-30 2021-12-30 Memory overflow method based on JAVA

Country Status (1)

Country Link
CN (1) CN114527985A (en)

Similar Documents

Publication Publication Date Title
US8336033B2 (en) Method and system for generating a hierarchical tree representing stack traces
US7904493B2 (en) Method and system for object age detection in garbage collection heaps
US8601469B2 (en) Method and system for customizing allocation statistics
US8589653B2 (en) Memory management method and computer using the method
US10949342B2 (en) Persistent memory garbage collection
EP2834744B1 (en) System and method for memory management
CN102722432B (en) Follow the trail of the method and apparatus of internal storage access
US8825718B2 (en) Methods and apparatus for marking objects for garbage collection in an object-based memory system
US20120197944A1 (en) System and method for determining an object's lifetime in an object oriented environment
CN102063338A (en) Method and device for requesting exclusive resource
US7600223B2 (en) Abstracted managed code execution
CN103927305A (en) Method and device for controlling memory overflow
US8966212B2 (en) Memory management method, computer system and computer readable medium
US20080163009A1 (en) Method and system for providing enhanced memory error messages
CN106202459A (en) Relevant database storage performance optimization method under virtualized environment and system
US8856186B1 (en) Object grouping for garbage collecting
US9208080B2 (en) Persistent memory garbage collection
CN114527985A (en) Memory overflow method based on JAVA
CN110058859B (en) Method, device, equipment and medium for realizing program running and virtual machine instance
CN104778087A (en) Information processing method and information processing device
CN113590637A (en) Method and device for updating multi-process shared database table and database system
CN111767155A (en) Deadlock detection method, device, equipment and computer readable storage medium
Mann et al. Study of Energy-Efficient Optimization Techniques for High-Level Homogeneous Resource Management
CN115480875A (en) Dynamic memory recovery method for cloud desktop virtual machine
CN111881196A (en) Method and system for changing program data source based on Redis

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication