JVM Insider: detailed explanation of Java virtual machine, jvm Insider: Java Virtual Machine

Source: Internet
Author: User

JVM Insider: detailed explanation of Java virtual machine, jvm Insider: Java Virtual Machine

This article explains the internal architecture of Java Virtual Machine (JVM. Displays typical JVM core internal components that comply with Java SE 7 specifications.

The displayed components are explained in two chapters. The first chapter discusses the components created for each thread, and the second chapter discusses the thread-independent components.

  • Thread
    • JVM system thread
    • Related to each thread
    • Program counters
    • Stack
    • Local Stack
    • Stack restrictions
    • Stack frame
    • Local variable array
    • Operand Stack
    • Dynamic Link
  • Thread sharing
    • Heap
    • Memory Management
    • Non-heap memory
    • Instant Compilation
    • Method Area
    • Class file structure
    • Class Loader
    • Faster class loading
    • Where is the method area?
    • Classloader reference
    • Runtime constant pool
    • Exception table
    • Symbol table
    • Interned string
Thread

The thread mentioned here refers to a thread entity during program execution. JVM allows an application to execute multiple threads concurrently. The Java thread in the Hotspot JVM has a direct ing relationship with the native operating system thread. When the thread is locally stored, the buffer is allocated, the synchronization object, the stack, and the program counter are ready, an operating system native thread is created. When the Java thread ends, the native thread is recycled. The operating system schedules all threads and assigns them to any available CPU. When the native thread Initialization is complete, the Java thread's run () method will be called. When run () is returned, the native thread determines whether to terminate the JVM process (for example, this thread is the last non-daemon thread) because of its termination ). When the thread ends, all resources of the native thread and Java thread are released.

JVM system thread

If you use jconsole or other debuggers, you will see many threads running in the background. These background threads run together with the main thread that triggers the public static void main (String []) function and other threads created by the main thread. The main system threads running in the Hotspot JVM background are as follows:

Virtual Machine thread) This thread waits for the JVM to arrive at the security point. These operations must be performed in an independent thread, because when the heap cannot be modified, the thread must be on the JVM security point. The types of these operations include stop-the-world garbage collection, thread stack dump, thread pause, and biased locking.
Periodic task thread This thread is responsible for timer events (that is, interruptions) and is used to schedule the execution of periodic operations.
GC thread These threads support different garbage collection activities in the JVM.
Compiler thread These threads dynamically compile the bytecode associated with the platform at runtime.
Signal Distribution thread This thread receives signals sent to the JVM and calls the appropriate JVM method for processing.
Thread-related components

Each running thread contains the following components:

Program counter (PC)

PC refers to the address of the current command (or operation code), except for local commands. If the current method is the native method, the PC value is undefined. All CPUs have one PC. In a typical state, each command is automatically incremented. Therefore, the PC stores the command address pointing to the next command to be executed. The JVM uses a PC to track where commands are executed. The PC actually points to a memory address in the Method Area.

Stack)

Each thread has its own stack, and the stack contains the stack frames for each method execution. The stack is a data structure of the last-in-first-out (LIFO), so the method currently executed is at the top of the stack. During each method call, a new stack frame is created and pushed to the top of the stack. When the method returns normally or an uncaptured exception is thrown, the stack frame will go out of the stack. In addition to the stack frame pressure stack and the out stack, the stack cannot be operated directly. Therefore, stack frames can be allocated on the stack without the need for continuous memory.

Native Stack

Not all JVM implementations support native methods. The supported JVM generally creates a local method stack for each thread. If JVM uses the C-linkage model to implement JNI (Java Native Invocation), the local stack is a C stack. In this case, the parameter sequence and return value of the local method Stack are the same as that of a typical C program. Generally, local methods can (depending on JVM implementation) Call Java methods in JVM in turn. This native method calls Java will occur on the stack (generally the Java stack); the thread will leave the local method stack and open a new stack frame on the Java stack.

Stack restrictions

Stack can be dynamically allocated or fixed. If the thread requests a space that exceeds the permitted range, a StackOverflowError is thrown. If the thread needs a new stack frame but does not have enough memory to allocate it, an OutOfMemoryError will be thrown.

Stack Frame)

Each method call creates a new stack frame and pushes it to the top of the stack. When the method returns normally or an uncaptured exception is thrown during the call process, the stack frame will go out of the stack.

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.