Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The concept of JVM memory

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

The concept of JVM memory

Javamemory=directmemory (direct memory) + jvmmemory (MaxPermSize+Xmx)

1) Direct memory and heap direct memory is a piece of memory space managed by the program itself, which is more efficient than the standard memory pool and is mainly used to store data buffering during network communication and disk data exchange. The DirectMemory capacity can be specified by-XX:MaxDirectMemorySize or, if not specified, defaults to the same maximum value as the Java heap (specified by-Xmx). However, in the latest version of JVM on OSX, the default size of direct memory is revised to "the default allocated direct memory size is 64MB when no direct memory size is specified", and the specified direct memory size can be displayed with-XX:MaxMemorySize. 2) Heap and Non-heap memory officially: "the Java virtual machine has a heap, and the heap is the runtime data area from which all class instances and arrays of memory are allocated. The heap is created when the Java virtual machine starts." memory outside the heap in JVM is called non-heap memory (Non-heapmemory). You can see that JVM manages two main types of memory: heap and non-heap. Simply put, the heap is the memory available to Java code, which is reserved for developers; non-heap is reserved for JVM's own use, so the method area, memory needed for internal processing or optimization in JVM (such as JIT compiled code cache), each class structure (such as runtime constant pools, fields and method data), and the code for methods and constructors are all in non-heap memory.

3) Stack and stack solve the running problem of the program, that is, how the program executes, or how to deal with data; the heap solves the problem of data storage, that is, how to put the data and where to put it. In Java, a thread will have a corresponding thread stack, which is easy to understand, because different threads have different execution logic, so a separate thread stack is required. The heap is shared by all threads. Because the stack is the running unit, the information stored in it is related to the current thread (or program). It includes local variables, program running state, method return value, and so on, while the heap is only responsible for storing object information. Java's heap is a run-time data area from which objects of the class allocate space. These objects are established by instructions such as new, newarray, anewarray, and multianewarray, and they do not require program code to be explicitly released. The heap is responsible for garbage collection, and the advantage of the heap is that it can allocate memory dynamically, and the lifetime does not have to tell the compiler in advance, because it allocates memory dynamically at run time, and Java's garbage collector automatically collects the data that is no longer in use. However, the disadvantage is that the access speed is slow due to the dynamic allocation of memory at run time. The advantage of stack is that access speed is faster than heap, second only to registers, and stack data can be shared. However, the disadvantage is that the data size and lifetime in the stack must be determined and lack of flexibility. The stack mainly stores some basic types of variables (int,short,long,byte,float,double,boolean,char) and object handles. Thread occupancy size is used for memory request and allocation in MaxPermSize

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report