[Java Basics] Java Virtual machine memory mechanism

Source: Internet
Author: User

Understanding the benefits of the Java Virtual Machine memory mechanism

When we need to solve some tricky problems, such as performance optimization, to solve the oom anomaly, if we understand the memory mechanism of the Java Virtual machine, we know where to begin to deal with these problems.


How to understand me from three aspects to explain his
Process level We do an app on the PC and make an app on the phone that exists at the level of the process. At this level of the process, memory is allocated/allocated to the Java heap, the method area (containing the constant store), the individual threads

    • Java heap: The Java heap is the area where GC threads reclaim memory, and he is primarily used to store various objects
    • Method Area: The method area stores the information after the class is loaded, such as global variables, methods, etc.
    • Constant store: The static variable store is included in the method area and is used to hold various static final constants, which are mutable

In addition to the Java heap and method areas, other memory spaces are allocated to individual threads.
There is a possibility that an oom exception will occur in these memory areas.
Thread level

    • Program counter: Each thread will have a program counter, this in debug when the track to go to which step. The program counters use very little memory, and this part does not produce OOM exceptions!
    • Java Virtual machine stack: As the name implies, the Java Virtual machine stack is in the form of a stack, so he accesses more quickly than the heap. The Java Virtual machine stack stores local variables, Java's basic data types, and object type/array types store addresses that point to the Java heap
    • Native method Stack: The native method stack corresponds to the contents of the native method stored in the Java Virtual machine stack
Stack and heap are different, stacks will throw stackoverflowexception, but also may throw oom, but in combat, stack memory exceeded the memory limit, generally throw is StackOverflowException

Other

    • Direct Memory: Direct memory is used in NIO, in order to avoid native heap and local heap copy data back and forth, and the implementation of the technology

Above, if there are errors, ask the great gods to correct them.

[Java Basics] Java Virtual machine memory mechanism

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.