Java Virtual Machine (1)--run-time data area

Source: Internet
Author: User

  

First, run-time data region

1.1 Program Counters

Records the address of the virtual machine bytecode instruction being executed (empty if the local method is being executed).

1.2 Java virtual Machine stack

Each Java method executes and creates a stack frame to store information such as the local variable table, the operand stack, the Chang reference, and so on. From the method call until the completion of the process, it corresponds to a stack frame in the Java virtual machine stack in the stack and the process of the stack.

You can specify the Java virtual machine stack memory size for each thread by-XSS this virtual machine parameter:

java-xss512m Hackthejava

The zone may throw the following exception:

    • A Stackoverflowerror exception is thrown when the thread requests a stack depth that exceeds the maximum value;
    • When the stack is dynamically expanding, it throws a OutOfMemoryError exception if it cannot request enough memory.

1.3 Local Method Stack

The local method stack is similar to the Java virtual machine stack, where the difference is simply that the local method stack serves the local method.

Local methods are typically written in other languages (C, C + +, or assembly language), and are compiled into native hardware and operating system-based programs that require special handling.

1.4 Stacks

All objects allocate memory here, which is the primary area of garbage collection ("GC heap").

The modern garbage collector basically uses the Generational collection algorithm, the main idea is to take different garbage collection algorithm for different types of objects, can divide the heap into two blocks:

    • New Generation (young Generation)
    • Old Age (Generation)

The heap does not require contiguous memory and can dynamically increase its memory, and increasing the failure throws a OutOfMemoryError exception.

You can specify the heap memory size of a program through the-XMS and-xmx two virtual machine parameters, the first parameter sets the initial value, and the second parameter sets the maximum value.

Java-xms1m-xmx2m Hackthejava

1.5 Method Area

Used to store data such as the loaded class information, constants, static variables, immediate compiler-compiled code, and so on.

Like heaps, which do not require contiguous memory and can be dynamically extended, the OutOfMemoryError exception is thrown as a dynamic expansion failure.

The main goal of garbage collection for this area is to recycle the constant pool and unload the class, but it is generally more difficult to implement.

The HotSpot virtual machine treats it as a permanent generation for garbage collection. However, it is difficult to determine the size of a permanent generation because it is affected by many factors, and the size of the permanent generation after each full GC changes, so it is often thrown outofmemoryerror exceptions. To make it easier to manage the method area, start with JDK 1.8, remove the permanent generation, and move the method area to the meta space, which is in local memory rather than in virtual machine memory.

1.6 Running a constant-rate pool

Running a constant pool is part of the method area.

The Chang in the class file (the various literal and symbolic references generated by the compiler) are placed in this area after the class is loaded.

In addition to the constants generated at compile time, it is also possible to generate dynamically, such as The Intern () of the String class.

1.7 Direct Memory

In JDK 1.4, new NIO classes are added, which can be used to directly allocate out-of-heap memory (Native heap) using the Native Library, and then operate through a Directbytebuffer object stored in the Java heap as a reference to this memory.

This can significantly improve performance in some scenarios because it avoids copying data back and forth in the Java heap and Native heap.

Java Virtual Machine (1)--run-time data area

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.