Book summary-in-depth understanding of Java virtual machines

Source: Internet
Author: User

Java memory area and memory overflow exception

Partition Memory:
The Java Virtual machine divides memory into 5 parts when executing a java program. Thread-Private has a member counter, a virtual machine stack, a local method stack, a thread-shared method area, a heap.

The program counter stores the byte code line number, which does not specify any memory overflow exceptions. The virtual machine stack stores stack frames for the Java method to run. The local method stack is used to run the native method. The method area is used to store information, constants, static variables, and so on for the loaded class. Heap is used to store Java objects.

A run-time constant pool is part of the method area that stores the literal and symbolic references generated during the compilation period.
Direct memory is not part of the virtual machine data area, which can be allocated through the NIO class.

To create an object:
How do virtual machines create an object? Load the class first, then allocate memory for the object, depending on whether the heap memory is neatly followed by a pointer collision or a free list. You can use the Tlab method to avoid inter-thread conflicts that allocate memory. The memory is then assigned a value of 0. Then set the object header. Finally, the Init method is executed.

In hotpot virtual machines, object memory is divided into object headers, instance data, and alignment fills. The first part of the object header is "Mark Word" and the second part is the type pointer. Instance data is the value of each type of field. Aligns the padding with the placeholder effect.

To access an object:
There are two ways to access objects: Handle mode and direct pointer mode. The hotpot virtual machine uses a direct pointer method.

Exception Name enumeration:
OutOfMemoryError Stackoverflowerror

Book summary-in-depth understanding of Java virtual machines

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.