Java Piecemeal points 001--deep understanding of the Jvm_java heap memory _ Stack memory _ and the role of the Run-time data area __java

Source: Internet
Author: User


Program counter: A line number indicator that can be viewed as the byte code executed by the current thread, and in the conceptual model of the virtual machine, the bytecode interpreter works by changing the value of the counter to select the next byte code instruction to execute. Because JVM multithreading is implemented through the way that threads switch and allocate processor execution time, at any one time, a processor executes only the instructions in one thread. In order for the thread to switch back to the correct location, the program counter must be thread-private, independently stored and the counters between the threads do not affect each other. If the thread is executing a Java method, this counter records the address of the executing virtual machine byte-code instruction; If you are executing a native method (simply put, a native is an interface to Java calling non-Java code.) A native method is a Java approach: the implementation of this method is implemented by a non-Java language, such as C. , the value of this counter is NULL, and this memory area is the only area that does not specify any outofmemoryerror in the Java Virtual Machine specification.
Virtual machine stack: The virtual machine stack is also thread-private, and its lifecycle and thread are the same. The virtual machine stack describes the memory model that is executed by the Java method: Each method is executed at the same time creating a stack frame (stack frame) for storing local variable tables, operation stacks, dynamic links, method exits, and so on. Each method is invoked until the completion of the process, corresponding to a stack frame in the virtual machine stack from the stack to the process. The virtual machine stack holds the various basic data types (Boolean, Byte, char, short, int, float, long, double), object reference type (Reference Types), and returnadress types that are known at compile time. (The value of the ReturnAddress type points to the opcode of a virtual machine instruction.) Unlike the native types of the numeric classes described earlier, the ReturnAddress type does not exist in the Java language and cannot change the value of the ReturnAddress type while the program is running.
Local method Stacks: The local method stack plays a very similar role to the virtual machine stack, the virtual machine stack performs Java method services for the virtual machine, and the local method stack is a Native method service for virtual machines, which has no mandatory specification for the local method stack, and the virtual machines are free to implement him. The local method stack also throws Stackoverflowerror and OutOfMemoryError exceptions.
Heap: The Java heap is an area of memory that is shared by all threads and is created when the virtual machine is started. The only purpose of this memory area is to hold the object instance, where almost all object instances allocate memory. This is described in the Java Virtual Machine specification: All object instances and arrays are allocated on the heap. The heap is the primary area of GC management. The Java heap can also be subdivided into cenozoic and old eras. There are, of course, finer ways of dividing, not too much elaboration here.
Method Area: The method area is also the memory area shared by each thread, which is used to store data such as class information that has been loaded by the virtual machine, constants, static variables, just-in-time compiler compiled code, and so on. The Java Virtual machine specification Describes a method to describe a logical part of a stack, but it has a name non-heap (not a heap) that should be distinguished from the Java heap. The Java Virtual Machine specification has a looser limit for this area, as is the case with Java heaps, where the method does not require contiguous memory, can choose a fixed size, can be extended, and generally does not implement garbage collection for the region.
Run a constant pool: a run-time pool is a part of the method area that holds the various literal and symbolic references generated by the compilation, and for a constant pool, the Java Virtual Machine specification does not require any detail, and different JVMs can implement the memory area on their own as required. In addition, new constants can be put into the pool during the run. Excerpt from: Deep understanding of the JVM

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.