In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what are the data regions of the java runtime". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Java Runtime data region
Program counter
It is mainly used as the line number indicator of the bytecode executed by the current thread, which is used to know the bytecode instruction address to be executed. This area is thread private, you see if it is shared by the thread, who knows where to execute the next thread after switching threads. If the Native method is executed, the value of the counter is not the address of the bytecode instruction that needs to be executed, but Undefined.
The counter is the only area in memory that does not specify the OutOfMemoryError situation.
Virtual machine stack
The virtual machine stack is thread private, that is, each thread itself has a virtual machine stack, in which there is a stack frame, and each stack frame corresponds to a method call, that is, the call of a method is the entry of a stack frame, and the end of method execution is the unstack of a stack frame.
Stack frames are mainly used to store local variables, Operand stacks, dynamic links, method exits and other information. So the local variable inside the multithreaded operation method does not need to worry about visibility or atomicity, because it is thread private!
The local variable table stores various basic data types, object references, and returnAddress types known at compile time (for bytecode instructions jsr, jsr_w, and wet services, which points to the address of a bytecode instruction).
With the exception of long and double, which occupy two local variable spaces (slot), all other data types occupy only one space, and the required memory space has been determined by the compiler.
When the stack depth of the thread request is greater than the depth allowed by the virtual machine (for example, the recursive depth is too deep), a StackOverflowError is thrown. Or if the virtual machine stack allows dynamic scaling, then OutOfMemoryError is thrown when expanding to memory that cannot be requested.
Local method stack
Similar to the virtual machine stack, the main difference is that it serves the Native method, and the virtual machine stack serves the Java method. Some virtual machines combine the local method stack with the virtual machine stack, such as (HotSpot) virtual machines. And StackOverflowError and OutOfMemoryError are thrown just like the virtual machine stack.
Heap
For the most part, the heap takes up the largest amount of memory of these parts. It is a memory area shared by all threads, created with the startup of the virtual machine, and its purpose is to store object instances! All object instances and arrays are allocated on the heap.
And the heap is also the main management area of the garbage collector. According to the generation-by-generation collection algorithm of garbage processor, it is divided into new generation and old generation in the heap. OutOfMemoryError will be thrown when there is insufficient memory.
Method area
Like the heap, it is a memory area shared by all threads, which is used to store class information, constants, static variables, JIT-compiled code, etc., that have been loaded by the virtual machine. The compiler puts various generated literals and matching references into the constant pool, and it is possible to add new constants at run time, such as using the intern () method of String.
According to the garbage processor's generation-by-generation collection algorithm, the permanent generation is here. OutOfMemoryError will be thrown when there is insufficient memory.
Direct memory
Direct memory is not part of the data area of the virtual machine runtime, but let's talk about it here. Because it is still used very frequently!
NIO (New Input/Output), which allocates out-of-heap memory directly using the Native function library, and then manipulates this memory by using the DirectByteBuffer object in the heap as a reference.
The normal memory stream should be local IO-- > direct memory-- > indirect memory-- > direct memory-- > local IO.
The direct memory is local IO-- > direct memory-> local IO.
So it can significantly improve performance in some general scenarios. The size of direct memory is limited by the total memory of this machine!
This is the end of the content of "what are the data regions of the java runtime". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.