Java Virtual machine Memory area

Source: Internet
Author: User

The Java Virtual machine divides the memory it manages into several different data regions during the execution of a Java program. These areas have their own uses, as well as the time of creation and destruction. Depending on the Java Virtual Machine specification, there are several run-time data areas. First, the program counterMemory space: small. Function: The line number indicator of the bytecode executed by the current thread. Feature Analysis: The multithreaded execution of a Java virtual machine is done by rotating threads and allocating processor execution time. At a certain point in time, a processor executes only the instructions in one thread. Therefore, in order for the thread to switch back to the correct execution location, each thread needs a separate program counter, the count of each thread does not affect each other, independent storage. is a thread-private area of memory. Record value: If the thread is executing a Java method, the executing virtual machine bytecode instruction address is logged, and if the thread executes the native method, the value is empty.This memory area is the only area in the Java Virtual Machine specification that does not stipulate any outofmemoryerror. Second, Java Virtual machine stackis thread-private, with the same life cycle as the thread. Role: Describes the memory model of the Java method execution: Each method is executed to create a stack frame for storing local variable tables, operand stacks, dynamic links, method exits and other information. Each method is called until the completion of the process, corresponding to a stack frame in the stack of the stack and the stack process. The local variable table in the virtual machine stack holds thethe various basic data types (Boolean, Byte, char, short, int, float, long, double) that are known at compile time, object references. The reference type is not the same as the object itself, depending on the virtual machine implementation, it may be a reference pointer to the start address of the object, or it may point to a handle representing the object. 64-bit lengths of long and double data consume two local variable tablespace (slots), and the rest of the data types occupy only one.The amount of memory space required for a local variable table is allocated during compilation, and when entering a method, the method needs to allocate much of the local variable space in the frame is fully deterministic and does not change the size of the local variable table while the method is running. In the Java Virtual Machine specification, there are two exceptions to the virtual machine stack: (1) A Stackoverflowerror exception will be thrown if the thread requests a stack depth greater than the virtual machine's allowed depth. (2) If the virtual machine stack can be dynamically extended, the OutOfMemoryError exception will be thrown when the extension cannot request enough memory.third, the local method stackFunction: Similar to the virtual machine stack. Difference: The virtual machine stack executes the Java Method (bytecode) service for the virtual machine, while the local method stack executes the native method service for the virtual machine. Stackoverflowerror exceptions and OutOfMemoryError exceptions are also thrown.iv. java HeapMemory space: The largest chunk of memory managed by a Java virtual machine.The Java heap is a piece of memory that is shared by all threads and created when the virtual machine is started. Sole Purpose: Store object instances where almost all object instances are allocated memory. The Java heap is a major area of garbage collector management and is often referred to as a GC heap.Memory Recovery angle: Java heap is divided into the new generation and the old age, and then more detailed there is Eden space, from Survivo space, to survivor space. memory allocation angle: Multiple thread-Private allocation buffers (Tlab) can be divided. In any case, regardless of the content of the store, no matter what area, the storage is an object instance, further divided just to better reclaim memory or to allocate memory more quickly. The Java heap can be in a physically discontinuous memory space, as long as it is logically contiguous. On the implementation, it can be either fixed or extensible. A OutOfMemoryError exception is thrown if there is no memory in the heap to complete the strength allocation and the heap cannot be extended. v. Method areasThe method area, like the Java heap, is also a zone shared by each thread, or it can be in a discontinuous physical memory space, optionally fixed or extensible. Function: Used to store data such as the class information loaded by the virtual machine, constants, static variables, the immediate compiler compiled code, and so on. Garbage collection behavior is seldom performed in the method area, and the memory recovery target in this region is primarily for the collection of constant pools and unloading of types. The OutOfMemoryError exception occurs when memory allocation requirements are not met.Vi. operation of the constant-volume poolRunning a constant pool is part of the method area. The constant pool information in the class file (used to hold various literal and symbolic references generated by the compilation period) is stored in the run-time pool after the class is loaded. Java virtual machines have strict specifications for each part of a class file, and each byte is used to store which data must conform to the requirements of the specification in order to be recognized, loaded, and executed by the virtual machine. However, the Java Virtual Machine specification does not require any details about running a constant pool. Virtual machines implemented by different vendors can implement this memory area according to their own needs.Another important feature of running a constant pool relative to a const pool in a class file is that it is dynamic, and the Java language requires constants that are not necessarily only generated during compilation, but also that the new constants can be put into a run-time pool during runtime. such as The Intern () method of the String class. seven, Direct memoryDirect memory is not part of the data area when the virtual machine is running, nor is it a content area defined in the Java VM specification. However, outofmemoryerror exceptions can occur.

Java Virtual machine Memory area

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.