Java Virtual Machine Learning notes (i)--Runtime data region __java

Source: Internet
Author: User
Tags garbage collection
Preface

The Java Virtual machine divides the memory it manages into several different data regions as it executes the Java program.

The program counter is a small memory space, which can be seen as the line number Indicator program counter of the byte code executed by the current thread is in the thread exclusive area, and the multithreading of the Java Virtual machine is realized by the way that the thread turns over and allocates the processor execution time, in any moment, A processor executes only the instructions in one thread, and can revert to the correct execution position when the thread switches, so each thread needs to have a separate program counter if the thread is executing a Java method that records the address of the executing virtual machine byte-code directive. If the native method is being executed, the value of this counter is undefined. The native method here is a Java interface that calls non-Java code. As for why? See the Java native method This area is the only area where no outofmemoryerror condition is specified in the Java Virtual Machine specification, because the program counter is the area that the Java Virtual Machine manages itself, and the developer does not need to maintain it, so There is no provision for any OutOfMemoryError Java Virtual machine stack

Thread-Private, executing Java method services for virtual machines describes the dynamic memory model of Java method execution. Each method executes creates a stack frame that holds the local variable table, operand stack, dynamic link, method exit, and each method corresponds to the stack and stack process from the start of the call to the end of the call. Size: Method calls will be kept in the stack, when the stack size will be reported stackoverflowerror if the virtual machine can dynamically expand, if the extension can not request enough memory, you will report the OUTOFMEMORYERROR exception local variable table: The basic data types are stored in the compilation period, and the object references the local method stack

Performing native methods for virtual machines service other Java Virtual machine stacks java heap

Thread sharing is the largest stored object Java heap in the memory managed by the Java Virtual machine, can be in the physical discontinuous memory can be either fixed size, or can be dynamically extended, if the application is not memory, it will report OutOfMemoryError exception method Area

Thread sharing virtual machine loaded class information, constants, static variables (version of Class, fields, methods, interfaces) very few garbage collection size can be fixed or dynamically allocated, when not enough memory, will be reported outofmemoryerror abnormal direct memory and the operation of the frequent pool

A run-time pool is part of the method area and is subject to memory limitations, which are reported when there is not enough memory for the OUTOFMEMORYERROR exception run regular pool is used to hold the various literal and symbolic references generated by the compilation The direct memory is not part of the virtual Run-time data area, and can improve efficiency, Avoid copying data back and forth between the Java heap and the native heap direct memory is limited by native memory, so there are outofmemoryerror exceptions for example

public static void Main (string[] args) {
        String S1 = "abc";
        String s2 = "abc";
        String s3 = new String ("abc");

        System.out.println (S1 = = s2);
        System.out.println (S1 = = S3);
        System.out.println (S1 = = S3.intern ());
    }

S1 and S2 are placed in the stack area, pointing to the ABC reference in the constant pool, S3 is a new object, so put it in the heap, and when using the S3.intern () method, "ABC" is placed in the Run-time pool, and when the runtime is already present, it is no longer stored in a running constant pool. Instead, point directly to the reference!


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.