The Java Virtual Machine (JVM) is the core of the Java ecosystem, providing all the essential tools for running Java code. To fully understand how it works, it is crucial to understand the lifecycle of this interpreter and its implications for the performance and optimization of Java applications.
The entire JVM life cycle begins with a fundamental process called "JVM Bootstrapping" which is responsible for building the entire execution environment and preparing it. It is in this context that: the arguments passed on the command line are interpreted, the JVM code is allocated in memory, the JVM's internal data structures are initialized, memory management begins, and finally the main application thread passes operating. Let's explore each subprocess described in this paragraph individually:
Arguments passed on the command line are interpreted
When the program is started via the command line, the JVM starts a chain of processes responsible for analyzing the arguments provided, which may include initialization parameters — such as: -Xms and -Xmx to define the minimum size and maximum heap, the area of memory responsible for allocating and creating objects in the context of the application — debug specifications or configurations even of the Garbage Collector cycle itself.
Before proceeding, it is important to mention: for the sake of simplicity, we will be analyzing the segment of code that deals with parsing advanced JVM arguments — those that begin with -XX.
To have more clarity, we will use the open-source code from OpenJDK for further references. In the file arguments.cpp located in the directory src/hotspot/share/runtime.arguments.cpp the function that interprets advanced parameters (-XX) by the CLI is this:
Making a brief analysis, the function starts a check to see if the passed argument starts with or -, determining whether the flag is boolean, and also whether it should be deactivated or activated.
After that, the code begins extracting the flag name. Each character is analyzed, if it is not alphanumeric or not _, it ends (meaning the flag name is complete).
After doing the checks and identifying the flag name, the method JVMFlag* flag = find_jvm_flag(name, name_len); is finally invoked to see if there is any configuration available to what was provided.
This is a small summary of how -XX's most advanced arguments are parsed. It is possible to find, however, in this same file that I will mention, the argument processes that start with -X that go through another parsing function:
Example of the flag: -XMS
ARTICLE UNDER CONSTRUCTION
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3