Deep understanding of Java Virtual Machine-java memory area and memory overflow exception

Source: Internet
Author: User

Thread run data is differentiated into thread share and thread exclusive zone

The thread exclusive zone means that each thread that is opened will have a thread exclusive zone

As shown in the following:

Program Counter:

1) is a small memory space that can be seen as the line number indicator of the byte code executed by the current thread

2) It is in the thread exclusive zone (each thread will have its own thread exclusive zone)

3) If the thread executes a Java method, this counter records the address of the virtual machine bytecode instruction being executed, and if the native method is being executed, the value of this counter is undefined

4) This area is the only area where no outofmemory is specified in the Java Virtual Machine specification (developer does not operate program counters, maintained internally by the Java Virtual machine)

Java Virtual machine stack:

1) describes the dynamic memory model that is performed by the Java method

2) Stack frame: Each method execution creates a stack frame, along with the method from creation to execution completion.

stack frames are used to store local variable tables, operand stacks, dynamic links, method exits, and so on.

3) Local Variables table: Store the compiler to know the various basic data types, reference types. ReturnAddress type;

The memory space of the local variable table is allocated in the compiler, and when a method is entered, this method requires the frame allocation how much memory is fixed, the size of the local variable table is not changed during the method run

4) stack size problem: Stack full throw stackoverflowerror stack memory overflow

Outofmerory

Local method Stack: virtual machine Stack executes Java method service for virtual machine, local method stack executes native method service for virtual machine

Java heap:

1) Storing object instances (not all object instances are stored in the heap)

2) is the main area of garbage collector management

3) New generation, old age, Eden space

Method Area:

1) Store the virtual machine load class information (including the class version, fields, methods, interfaces, etc.), constants, static variables, the instant compiler compiled code and other data

2) method area and permanent generation (both of which are equivalent in the hotspot)

3) garbage collection behavior in the method area

4) Exception Definition: Application failure will throw OutOfMemoryError

Run a constant pool (part of a method area)

Object is created:

Method: The New keyword--"stored in the Java heap

Problems encountered:

1) Allocate memory to the object:

Pointer Collision method (used when Java heap use and free are regular);

Idle list method (use a table to record which memory is not in use)

2) Thread safety issues

Adopt thread synchronous method to solve;

Use local thread allocation buffers (TLAB) to improve performance

3) Initialize the object

After initialization:

The abstract data type defaults to null; Basic data type defaults to 0;boolean type default to False

4) Execution of construction methods

Explore the object structure:

Object Access Location: (How to find the object)

1) using handles

2) direct pointer, fast speed, reduce performance overhead

Deep understanding of Java Virtual Machine-java memory area and memory overflow exception

Related Article

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.