Java Memory Space Brief

Source: Internet
Author: User

Memory space of the JVM:

  • 1. Register (Registers): The fastest save area, located inside the processor, is assigned by the compiler. The primary function is to record the line number of the bytecode executed by the current thread. The bytecode interpreter works by changing the current thread's program counter to select the next bytecode directive. Any branch, loop, method invocation, Judgment, exception handling, thread wait, and resume thread, recursion, etc. are all done through this counter. for multi-threaded implementations, each thread will have a separate program counter to record the line number of the current instruction so that the thread waits for the end to return to the correct location for execution. This memory is also known as "thread-private" memory. If the method being called is native, the register does not store any information.
  • 2. Stack (Stack): JVM stack is thread-private, and each thread creates a JVM stack, which holds the variables (eight) of the local base type in the current thread, the partial return result, and the stack Frame. Non-primitive types of objects (reference types) hold only one address to the heap memory on the JVM stack, so primitive type variables in Java are passed by value, whereas reference type objects are passed by reference. Because the stack is thread-private, the memory allocation is very efficient and the memory is automatically recycled when the thread finishes running.
  • 3. Heap:
  • 4. Method Area (Methodarea): in the Java Virtual Machine specification, the method area is described as a logical part of the heap, but is generally separate from the heap. Contains the loaded class information (name, modifier, etc.), static variables in the class, constants defined in the class as the final type, field information in the class, method information in the class, and when the developer obtains information in the program through GetName, Isinterface, and so on in the class object , the data is derived from the method area, and the importance of the method area is visible. Similarly, the method area is shared globally, and it will be GC under certain conditions when the virtual machine starts, and when the method area needs to use more memory than it allows, it throws a outofmemory error message. In the Sun JDK, this area corresponds to the permanetgeneration, also known as the persistent generation, the default is 64M, you can specify its size by-xx:permsize and-xx:maxpermsize.
  • 5. Run the Runtimeconstant pool: is part of the method area. Similar to the symbol table in c, stored as a fixed constant information in the class, Methods and field reference information, and so on, its space from the method area is allocated. The Chang of a class or interface is assigned when the class file is successfully loaded by the Java virtual machine.
  • 6. Local method Stack (Nativemethod Stacks): Very similar to the above stack, the above stack is mainly for virtual machine execution Java method (bytecode file) service, while the local method stack is for the native method service. The local method stack also throws Stackoverflowerror and OutOfMemoryError errors.

Java Memory Space Brief

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.