preface

As a Java practitioner, you will inevitably be asked about JVM knowledge when looking for a job. Knowledge of the JVM is seen by many interviewers as an important measure of a candidate’s technical depth. While most of you probably don’t have actual development and use experience with the JVM, this series of articles will give you an in-depth look at everything you need to know about the JVM. This will also help you make the transition from junior programmer to senior programmer.

Due to the length of the article, there are answers and analysis at the end of the article


directory

  • Threads (in detail)
  • JVM memory area (detail)
  • JVM runtime memory
  • Garbage collection and algorithms
  • JAVA four reference types
  • GC generation collection algorithm VS partition collection algorithm
  • GC garbage collector
  • JAVA IO/NIO
  • JVM class loading mechanism
  • If you want to know more about Java architecture technology, you can follow me. I will also sort out more knowledge points about architecture technology and share some of them: Spring, MyBatis, Netty source code analysis, high concurrency, high performance, distributed, microservice architecture principle, JVM performance optimization, concurrent programming these become the architect essential knowledge system.

    How to get it: Scan and get it for free




    The body of the

    I. Threads (detailed explanation)

    A thread here refers to a thread entity during the execution of a program. The JVM allows an application to execute multiple threads concurrently. Java threads in the Hotspot JVM map directly to native operating system threads. When thread local storage, buffer allocation, synchronous objects, stacks, program counters, and so on are ready, an operating system native thread is created. The Java thread terminates and the native thread is reclaimed. The operating system is responsible for scheduling all threads and allocating them to any available CPU. When the native thread completes initialization, the Java thread’s run() method is called. When the thread terminates, all resources of the native thread and Java thread are released.

    Hotspot JVM runs in the background on the following threads:

    JVM memory area (detailed explanation)

    The JVM memory area is mainly divided into thread private area (program counters, virtual stack, local method area), thread shared area (JAVA heap, method area), and direct memory.

    Thread-private data areas have the same life cycle as threads, and are created/destroyed depending on the start/end of the user thread (in HotspotVM, each thread is mapped directly to the operating system’s local thread, so the memory of this part of the memory area follows the life/death of the local thread).

    Thread shared areas are created/destroyed with the startup/shutdown of the virtual machine.

    Direct memory is not part of the JVM runtime data area, but is frequently used: NIO, introduced in JDK 1.4, provides Channel – and buffer-based I/O. It can use Native libraries to allocate out-of-heap memory directly, and then use DirectByteBuffer objects as references to this memory. Java I/O extensions), which avoids copying data back and forth between the Java heap and Native heap, and thus can significantly improve performance in some scenarios.

    1. Program counter (thread private)

    • A small area of memory that is a line number indicator of the bytecode being executed by the current thread. Each thread has a separate program counter. This type of memory is also called “thread-private” memory.
    • If the Java method is being executed, the counter records the address of the virtual machine bytecode instruction (the address of the current instruction). Null if the Native method is used.
    • This memory region is the only one in the virtual machine that does not specify any OutOfMemoryError cases.

    2. Virtual stack (thread private)

    Is a memory model that describes the execution of Java methods. Each method creates a Stack Frame for storing information such as local variable table, operand Stack, dynamic link, method exit, etc. The process of each method from invocation to completion corresponds to the process of a stack frame being pushed into and out of the virtual machine stack.

    Stack frames are data structures used to store data and partial process results. They are also used to handle Dynamic Linking, method return values, and Dispatch exceptions. Stack frames are created as the method is called and destroyed as the method terminates — method completion counts whether the method completes normally or if an exception completes (throwing an exception that was not caught within the method).

    3. Local method area (thread private)

    The local method Stack is similar to the Java Stack, except that the VM Stack serves the execution of Java methods, while the Native method Stack serves the execution of Native methods. If a VM implementation uses the C-linkage model to support Native calls, the Stack will be a C Stack. But HotSpot VM simply blends the local method stack with the virtual machine stack.

    4. Heap (Heap- thread shared) – run-time data area

    An area of memory shared by threads, where objects and arrays are created and stored in Java heap memory, is the most important area of memory for garbage collection by the garbage collector. Since modern VMS use generational collection algorithms, the Java heap can also be subdivided From a GC perspective into the new generation (Eden zone, From Survivor zone, and To Survivor zone) and the old.

    5. Method area/persistent generation (thread sharing)

    Permanent Generation, as it is often called, is used to store classes loaded by the JVM, constants, static variables, code compiled by the just-in-time compiler, and more. HotSpot VM extends GC generation collection to the method section using persistent generations of the Java heap to implement the method section, This allows HotSpot’s garbage collector to manage this part of memory in the same way it manages the Java heap, without having to develop a special memory manager for the method area (the main goal of persistent band memory reclamation is constant pool reclamation and type offloading, so the benefits are generally small).

    The Runtime Constant Pool is part of the method area. The Constant Pool Table is used to store various literals and symbolic references generated at compile time. This part of the content will be stored in the runtime Constant Pool of the method area after the Class is loaded. The Java virtual machine has strict rules on the format of each part of a Class file (including, of course, the constant pool), and each byte must be used to store what data must conform to the specification before it is accepted, loaded, and executed by the virtual machine.

    More analysis:

    JVM runtime memory

    • The new generation
    • The old s
    • The permanent generation

    Garbage collection and algorithm

    • How to identify garbage
    • Mark-sweep algorithm
    • Copying algorithms
    • Mark-compact Algorithm
    • Generational collection algorithm

    JAVA 4 reference types

    • Strong reference
    • Soft references
    • Weak application
    • Phantom reference

    Vi. GC generation collection algorithm VS Partition collection algorithm

    • Generational collection algorithm
    • Partition collection algorithm

    GC garbage collector

    Article information is organized in a document inside, the need for friends can be private message “JVM “to obtain yo

    • Serial garbage collector (single thread, replication algorithm)
    • ParNew garbage collector (Serial+ Multithreading)
    • Parallel Insane (Multi-threaded replication algorithm, Efficient)
    • Serial Old collector (single-threaded tag collation algorithm)
    • Parallel Old Collector (Multi-thread tag collation algorithm)
    • CMS collector (Multi-threaded tag clearing algorithm)
    • G1 collector (parse)

    G1 collector (parse)

    Garbage First Garbage collector is the most advanced theoretical development of Garbage collector. Compared with CMS collector, G1 collector has two most prominent improvements:

    1. Based on mark-collation algorithm, no memory fragmentation is generated.

    2. Pause times can be controlled very precisely to achieve low pause garbage collection without sacrificing throughput.

    The G1 collector avoids region-wide garbage collection by dividing heap memory into separate regions of fixed size and tracking the progress of garbage collection in these regions, while maintaining a priority list in the background that prioritizes the areas with the most garbage collected at a time based on the allowed collection time. Zone partitioning and priority zone collection mechanisms ensure that the G1 collector can achieve maximum garbage collection efficiency in limited time.

    Eight, JAVA IO/NIO

    • Blocking IO model
    • Non-blocking IO model
    • Multiplexing IO model
    • Signal driven IO model
    • Asynchronous IO model
    • JAVA IO package
    • JAVA NIO
    • Channel
    • Buffer
    • Selector

    JVM class loading mechanism

    • Load, validate, prepare, parse
    • Symbolic reference, direct reference
    • Initialize the
    • Class constructor
    • Class loader
    • Parents delegate
    • OSGI (Dynamic Modeling System)

    The last

    Give me a thumbs up and get this PDF for free!

    There are more free Java architecture learning materials, which cover all aspects of the Internet, encountered a variety of products and scenarios during the various problems, I hope to help you expand your technical breadth and knowledge.

    If you want to know more about Java architecture technology, you can follow me. I will also sort out more knowledge points about architecture technology and share some of them: Spring, MyBatis, Netty source code analysis, high concurrency, high performance, distributed, microservice architecture principle, JVM performance optimization, concurrent programming these become the architect essential knowledge system.

    How to get it: Scan and get it for free