Jvm-java memory Management (1)

Source: Internet
Author: User
Tags scalar

Description of the issue:
1. How is the memory in the virtual machine divided?
2. What are the specific areas?
3. What actions cause a memory overflow or an exception?

1) In these areas, some areas will exist as the virtual machine process starts, and some areas are created and destroyed since the start and end of the user thread

Noun Explanation:
1) Program counter:is a small memory space that acts as a line number indicator of the bytecode that is being executed by the current thread. (Note: The multithreading of a Java Virtual machine is implemented in a way that threads rotate and allocate processor execution time, and a kernel executes only one thread at a time, so that when the thread switches back to the correct execution location, each thread needs a separate program counter, which is a thread-private)
2) Virtual machine stack:When each method is executed, a stack frame is created to store information such as local variable tables, operation stacks, dynamic links, method exits, and so on. The process of each method from being called to executing completes corresponds to a stack frame in the virtual machine into the stack to the stack. (Note: The virtual machine stack is thread-private and its life cycle is the same as the thread.) If the thread requests a stack depth greater than the virtual machine allows, the Stackoverflowerror exception is thrown and the OutOfMemoryError exception is thrown when the extension fails to request enough memory.
3) Local method stack:Similar to the Java Virtual machine stack, the virtual machine stack is for executing Java method Services, and the local method stack serves the native method used by the virtual machine. Throwing exceptions is similar to a virtual machine stack.
**4) Java heap: The **java heap is a piece of memory that is shared by all threads and is created when the virtual machine is started. The only function is to store the object instance. The Java Virtual Machine Specification description is: All object instances and arrays are allocated on the heap, but with the development of JIT editor and the maturity of escape technology, stack allocation, scalar substitution and other optimization techniques make the allocation method is not unique. (Escape technology:??) Scalar allocation: The Java heap page is called GC heap, which can be subdivided into the new generation and the old age, then subdivided into Eden Space, from Survivor space, to survivor space, etc. A OutOfMemoryError exception will be thrown if there is no memory in the heap to complete the instance assignment and the heap can no longer be expanded.
5) Method area:is an area of memory shared by each thread that stores data such as class information, constants, static constants, and code compiled by the immediate compiler that have been loaded by the virtual machine. The OutOfMemoryError exception is thrown when the region fails to meet the memory allocation.
6) Run the constant-rate pool:Part of the method area. To say run a constant pool, first of all, to understand the file constants pool, that is, the class file in the constant pool, in addition to the class file to save the classes of the version, field, method, interface and other descriptive information, there is a constant pool, for the compilation period generated by the various literal and symbolic references, This section is stored in the run-time pool of the method area after the class is loaded.
**7) Direct Memory: **nio introduces a channel-to-buffer-based I/O method that can be used to directly allocate out-of-heap memory using the native library and then operate through a Directbytebuffer object stored in the Java heap as a reference to this memory. Significantly improved performance. Limited by native memory.

Object access: The primary access method is to use a handle and a direct pointer.
* * Handle Mode: **java heap will be divided into a block of memory as a handle pool, reference is stored in the object's handle address, the handle contains the object instance data and the type data of the respective address information.
* * Direct pointer mode: **java heap object layout needs to consider how to place the information about the type data, reference is directly stored in the object address.
comparison between the two: the most important advantage of the handle is that the reference store a stable handle address, in which the object movement is only changing the instance data pointer in the handle, and the reference itself does not need to be modified;
The biggest advantage of direct pointer access is faster.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Jvm-java memory Management (1)

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.