Enabling the JBolt Feature
Introduction
In mainstream just-in-time (JIT) compilation, method code is added to the code cache based on compilation timing. When there are a large number of hot, scattered methods, iCache/iTLB miss causes high CPU penalty, resulting in front-end system bottlenecks. The JBolt feature uses sampling to obtain the hotspots and call chains of JIT methods at runtime, and then uses algorithms to reorder hot method code, which improves spatial locality, reduces the iCache/iTLB miss rate, and boosts program performance.
Application Scenario
The iCache/iTLB miss rate is high due to high JIT code cache usage, and there are many hot, scattered methods in the program. (You can use a performance analysis tool to trace the CPU cache hit rate, such as the Linux perf command.)
Restrictions
The JBolt feature supports only BiSheng JDK 17 (17.0.14 and later versions).
(Recommended) Method 1: One-Step Mode
In this mode, sampling and reordering are automatically completed within the same program running phase. Repeated sampling and reordering are also supported.
- Enable and start JBolt to automatically perform sampling and reordering. It is strongly recommended that the -Xlog:jbolt=info parameter be added. This parameter will output information to the console in each important phase of JBolt. After sampling, reordering is automatically performed. If the -Xlog parameter is added, "JBolt reordering succeeds" is displayed after the reordering is done, indicating that the JBolt feature takes effect. This parameter is also applicable to the two-step mode. In the following command, spring-petclinic.jar is an example of the service program package. Replace it with your target program.
$JAVA_HOME/bin/java -XX:+UnlockExperimentalVMOptions -XX:+UseJBolt -Xlog:jbolt=info -jar spring-petclinic.jar
In one-step mode, the following two parameters can be used together:
- -XX:JBoltSampleInterval: sampling duration, in seconds. Unless otherwise specified, the default value is 600.
- -XX:JBoltCodeHeapSize: JBolt heap size. The default value is 8M. This value may be insufficient in scenarios where there are many compilation methods (the initial code cache usage is high). You need to configure this parameter based on the scenario and align the value with the page size. The reference value is 1/4 to 1/2 of the used non-profiled size. (Use the -XX:+PrintCodeCache parameter to query. For example, if non-profiled used=16M, set JBoltCodeHeapSize to a value between 4M and 8M.)
- Use jcmd to set the sampling time and start JBolt hotspot reordering online.
The following commands are supported. Usage: jcmd <pid> JBolt.xxx
<pid> indicates the ID of the Java process enabled in 1. Replace it with the actual PID.
- JBolt.start: starts automatic sampling in an interval and performs reordering after the sampling ends. The duration parameter can be used as required. It has the same meaning as -XX:JBoltSampleInterval and defaults to the value of JBoltSampleInterval. Example:
$JAVA_HOME/bin/jcmd <pid> JBolt.start [duration=<sample interval>]
If sampling or reordering is being performed, this command will fail. You can wait until the current process is complete or run the stop or abort command to end the current process in advance.
- JBolt.stop: immediately stops current sampling and performs reordering. Example:
$JAVA_HOME/bin/jcmd <pid> JBolt.stop
- JBolt.abort: similar to JBolt.stop but does not perform reordering. Example:
$JAVA_HOME/bin/jcmd <pid> JBolt.abort
- JBolt.dump: exports the sequence table in the current application. A valid file path must be specified in the filename parameter. Example:
$JAVA_HOME/bin/jcmd <pid> JBolt.dump filename=<eg: order.log>
- JBolt.start: starts automatic sampling in an interval and performs reordering after the sampling ends. The duration parameter can be used as required. It has the same meaning as -XX:JBoltSampleInterval and defaults to the value of JBoltSampleInterval. Example:
Method 2: Two-Step Mode
In this mode, sampling and reordering are performed in two phases.
- Enable the dump mode and perform sampling. The sampling persists until the program exits normally or is manually stopped by running Ctrl+C. In this case, the sequence table is exported to a specified file (not exported upon an abnormal exit).
$JAVA_HOME/bin/java -XX:+UnlockExperimentalVMOptions -XX:+UseJBolt -XX:+JBoltDumpMode -XX:JBoltOrderFile=<eg: order.log> -Xlog:jbolt=info -jar spring-petclinic.jar
- Use the generated sequence table file to start the program again for layout reordering. The reordering is performed after the application program is started for a period of time. For details about how to verify whether this step takes effect, refer to step 1 in the one-step mode. After the reordering takes effect, the program performance is expected to be improved.
$JAVA_HOME/bin/java -XX:+UnlockExperimentalVMOptions -XX:+UseJBolt -XX:+JBoltLoadMode -XX:JBoltOrderFile=<eg: order.log> -Xlog:jbolt=info -jar spring-petclinic.jar
In two-step mode, the jcmd command cannot be used to set the sampling time.