JVM Memory Management--computer memory and Java memory components __java

Source: Internet
Author: User
                                & nbsp   JVM Memory Management--computer memory and Java memory Components

The JVM has always been very good for us to manage memory, it is a wife: "to the Government (memory space) to the site, but also effective to their own three-acre management." "But sometimes, we do not know Shang to pressure on it, all our good and bad to throw it, but it does not complain, but in the earth when it will quietly tell us:" Stackoverflowerror or OutOfMemoryError. "Since it is so hard to pay, we should also know why it throws these anomalies." Or we can avoid these anomalies in some way so that our JVM can run more merrily on its three-acre ground. &NBSP
Before that, perhaps we should understand the environment in which it is surrounded by an acre of three points. The  
 
Registers are used to store intermediate results of a calculated cell execution instruction, and the register size determines the maximum value that can be used for a single calculation, and the connection RAM and the processor or register and the processor are called address bus select、read, address bus select、read determines the processor's maximum addressing space, The 32-bit bus width can have 2 of 32 memory locations, so the 32-bit bus can have 4G of memory space. &NBSP
When each program runs, it requests a separate memory space from the system, but with the size of the program and the complexity of the task, physical memory is not able to meet the requirements, there is virtual memory, virtual memory allows multiple processes to run simultaneously can share physical memory, The sharing here is only space sharing, logically they are still independent, of course, virtual memory can also extend the memory space. &NBSP
The system moves data from infrequently-active programs to a disk file. The real physical memory is left to the program that is actually running, but when this program is awakened, the OS will swap the data on the disk back into physical memory, and the disk will squeak, but we want to avoid this. The efficiency is very low, on the Linux server we often focus on the swap partition, if the swap partition is frequently used, the system will be very slow, indicating that the system memory is severely insufficient, or some programs do not release the memory immediately. &NBSP
Then we can see that the physical memory is very important for the program, and the physical memory will be divided into kernel space and user space, kernel space to ensure that the operation of the program and hardware logical connection, our program is automatically using user space, So every call will have two blocks of space to switch, for example, a network transmission, kernel space to receive the data from the remote host, and then copied from the kernel space to the user space for the program to use, this situation while ensuring security, but inefficient, of course, there are many ways to improve efficiency and reduce replication.

So here's the thing, how to use memory in our Java component. A. Heap

As we all know, the heap is where the Java object is stored, and its size is applied to the system once at the time the JVM is started,-XMX represents the maximum size of the heap, and-XMS represents the initialization size. Once the application is completed, the size of the heap is fixed, can not be in memory when the system to apply again, of course, the same memory idle time it will not return the memory, that is, since the world, another portal, life and death by their own. two. Thread

Looking at the JVM's execution with a simple piece of code. In this article we know that each thread creates a private stack to store the data, in hotspot this JVM does not differentiate between the virtual machine stack and the local method stack, the stack capacity size is set by-XSS. three. Class and loader

Classes and class Loaders are also stored in the heap, which is called the Permanent generation (PermGen area).
Note: A jar package class with which JVM to load that one, not a brain full load, the theoretical use of more classes, Java uses more classes, the need to occupy more memory. four. NIO

NIO uses memory that is native memory rather than memory on the Java heap, and the data generated by NIO's bytebuffer and network or disk interactions occur in the kernel space of the operating system, and do not need to be replicated to native memory, which is more efficient if we need to send very small data.
The main focus of data we're working with when the JVM runs is in the runtime data area, in the next chapter, I'll continue to learn the Java memory allocation structure and Java memory allocation policy

Article from: https://blog.csdn.net/sureSand/article/details/78715056

Related Article

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.