Memory overflow positioning and resolution in Java

Source: Internet
Author: User

In the previous section, the Java Virtual Machine memory distribution said that the Java virtual machine is divided into five regions, and also know that in the Java Program Counter area does not appear oom (Outofmemeryerror), The following is an explanation of the principle of oom in four areas except for the program counter and how to solve it.


1.Java virtual machine stack and local method stack

The size of the stack controls the parameters when-xss.

The Java Virtual machine defines two exceptions, Strackoverflowerror and Outofmemeryerror, in the stack. Strackoverflowerror is thrown when the depth of the request stack is greater than the maximum allowable depth of the Java Virtual machine, and if the Java Virtual machine does not request enough space when the stack is extended, Outofmemeryerror is thrown.

Strackoverflowerror:java the virtual machine is in operation, when invoking the method, it is necessary to create a stack frame, when the stack of space is not enough to produce strackoverflowerror. Then the corresponding solution is only to adjust the-XSS parameter, or reduce the method call, reduce the size of the stack frame two ways.

Outofmemeryerror: An oom on the stack is generally a multithreaded scenario. First of all, let's analyze how much space the stack can use, take 32-bit operating systems for example, maximum memory 2g-xmx (maximum heap capacity)-MaxPermSize (maximum method area capacity)-memory consumed by the virtual machine itself and program counters. the rest of the memory is the stack can use space, when the parameters of the XSS configuration, then in the process of creating threads constantly, encountered can not apply to the stack space when it will throw oom, then the corresponding solution is to adjust the-XSS parameter to reduce the stack size, or adjust the size of the-XMX and MaxPermSize to extend the space for the stack.


2. Method Area Memory Overflow

The size of the method area is controlled by-permsize and-maxpermsize.

Because class constants and run times are also stored in the method area, too often too many runs can cause oom in the method area, but there are no parameters that directly control the size of the constant pool, which can only be controlled indirectly through-permsize and-maxpermsize.

Dynamic generation classes such as generatedconstructoraccessor, dynamic proxies, and cglib bytecode enhancement techniques are used in spring and hibernate,mybatis, and strong method areas are needed to support them.


3. Overflow of heap memory

Heap memory overflow is complex, need to adjust the GC and other parameters, we will explain in later chapters.


Memory overflow positioning and resolution in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.