JVM memory management and jvm Memory Management

Source: Internet
Author: User

JVM memory management and jvm Memory Management

It is said that it is because C solves the problem and relies on programmers. However, we have an exception mechanism in Java. If the array is out of bounds, it will prompt that the development efficiency is higher than that in C, and programmers do not need to know much about the underlying layer. This is because of the most difficult problem, it has been solved by our predecessors. All of this is due to the Java Virtual Machine-Java Virtual Machine. JVM is actually an abstract computer. It has its own instruction set, its own machine language (ByteCode, Class file), and its own memory management. This series will unlock its true colors one by one.

This article is based on the Java HotSpot virtual machine, JDK 1.8, and will discuss:

  • JVM Internal Structure
  • JVM Memory Management

 

Figure 1 JVM Internal Structure

1. JVM Internal Structure

The process of executing a program is as follows. Taking the C language as an example, the source code is first compiled into an executable file and stored on the disk in binary format, first, load the data from the disk to the memory, and then the processor starts to execute machine commands in the target program. In contrast, Java is first compiled into a bytecode file and has nothing to do with the platform. The JVM loads the file to the memory through ClassLoader, and then runs the machine commands in the file. The JVM helps us deal with the operating system. With bytecode and JVM, Java achieves platform independence. JVM memory consists of the following parts:

(1) Heap

Heap, a very important region, shared by all threads. Basically all object instances are allocated here, and most garbage collection occurs here, JVM uses Garbage Collector (Automatic Memory Management Tool) to allocate memory for objects and uses different Garbage collection policies to release memory. Objects cannot be displayed for release. You can use parameters to control whether the Java heap capacity is fixed or dynamically scalable.

(2) JVM Stacks

The stack is closely related to the thread. The thread is private. It is generated with the thread and dead. This part of memory does not need to be managed by JVM. It is mainly used to store stack frames. When a method is called, a stack frame is created, and the method ends destruction. From the stack perspective, it is the inbound and outbound operations.

Stack frame is a data structure used to store local variables, operand stacks, and references to the current class runtime frequent pool. Local variable array: used to save the basic type variables defined in the method. The subscript starts from 0. JVM uses the local variable table to pass the method parameters. When an instance method is called, 0th the location stores this reference of the current object. The operand stack is used to execute operations, prepare parameters for calling methods, and return results of methods. Dynamic Link: The runtime constant pool of referenced objects.

(3) PC Register

Program counters and threads are private. The main function is to retrieve, decode, and execute them. If the execution method is native local method, the counter value is undefined.

(4) Metaspace

The HotSpot VM before JDK8 is called a method zone or permanent generation and is shared by various threads. It stores the structure information of a class, for example, the pool, fields, and methods of running time. Stored in local memory, irrelevant to heap.

(5) Native Method Stacks

The JVM stack is prepared for the Java method, so the local method stack calls the local method service for the virtual machine.

2. JVM Memory Management

First, let's take a look at the structure of the HotSpot VM internal heap:

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.