Java memory overflow and java Overflow

Source: Internet
Author: User

Java memory overflow and java Overflow

  • Program counters

    A program counter is a small piece of memory, which is private to the thread and can be seen as a counter for executing bytecode in the current thread. In the virtual machine conceptual model, the bytecode interpreter uses this counter to find the next command to be executed. In java, branch statements, loops, exception handling, and thread recovery are implemented through program counters.

    Since the JVM executes each thread in turn through the CPU during thread execution, the CPU can only execute a certain instruction of one thread at a time. This requires that the correct Command Execution location be restored each time the thread is switched. Therefore, the program counter of the thread must be private to the thread. Each thread does not affect each other and is stored independently.

    If the thread is executing a java method, the value of the program counter is the instruction position of the current virtual bytecode being executed after the method is compiled. If the current thread executes a native method, the counter value is null Undefined. This region is the region where the VM specification does not specify an OutOfMemoryError.

  • Virtual Machine Stack

    This region is also private to the thread, and its lifecycle is consistent with that of the corresponding thread. The Virtual Machine stack describes the Memory Model of java method execution: each method creates a stack frame on the Virtual Machine stack during execution to save the local variable table, Operation stack, and dynamic link, method exit and other information. Each method is called to correspond to a stack frame in the Virtual Machine Stack from the stack channel out of the stack process.

    We often see that memory is divided into heap memory and stack memory. The stack memory here refers to the local variable table on the VM stack. The local variable table stores various basic data types known during the compilation period, such as int, float, boolean ...... And object reference. The 64-bit long and double types occupy two local variable storage spaces (slots ). The rest occupy one. The memory space required by the local variable table is completely determined during compilation. The size does not change during running. The Java virtual machine specification specifies two exceptions for this memory zone: If the stack depth of the thread request is greater than the maximum depth allowed by the virtual machine, StackOverflowError is thrown. if the Virtual Machine stack can be dynamically expanded and cannot be applied for with enough memory during expansion, an OutOfMemoryError will be thrown.

  • Local method Stack

    Like the preceding two regions, this region is also the private region of the thread. It is similar to the Virtual Machine stack. The difference is that the virtual machine stack serves java methods, while the local method stack serves local methods called by java. The local method Stack also throws two exceptions that are identical to the Virtual Machine stack.

  • Java heap

    The java heap memory is created when the VM is started. All object instances are saved in this region, including arrays. Therefore, heap memory is also the main work area of the garbage collector. From the perspective of memory collection, the collectors basically use generational collection policies, so java heap can be subdivided into the new generation and old generation. A little more detailed information can be divided into: Eden space, FromSurvior space, toyun or space.

    ----------------------------------------------------------- <To be continued> -------------------------------------------------------------

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.