search
HomeJavajavaTutorialDetailed explanation of ParallelGC logs

ParallelGC 日志详解

JVM startup parameters

JAVA_OPTS = "-Xms4G -Xmx4G -Xmn2G -XX:MetaspaceSize=512M -XX:MaxMetaspaceSize=512M -XX:+UseParallelGC -XX:+PrintGCDetails -Xloggc:/home/gc.log -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC"

Setting JVM startup parameters

  • -XX:+PrintGCDetails: Output detailed information of GC, including heap memory usage after each garbage collection and the status before and after collection.
  • -Xloggc:/home/gc.log: Save GC logs to the file /home/gc.log instead of outputting to the console. This allows the logs to be analyzed after the application has run.
  • -XX:+PrintGCDateStamps: Add a date stamp to each GC log record to facilitate viewing the time when garbage collection occurred.
  • -XX:+PrintGCTimeStamps: Add the elapsed time after JVM startup to each GC log, in seconds.
  • -XX:+PrintHeapAtGC: Print the detailed status of the heap before and after garbage collection, including the memory allocation of each generation (young generation, old generation, metaspace).
  • -XX:+UseParallelGC: Use Parallel GC (parallel garbage collector) to improve performance by executing garbage collection in parallel with multiple threads.

GC log snippet

OpenJDK 64-Bit Server VM (25.342-b07) for linux-amd64 JRE (1.8.0_342-b07), built on Jul 16 2022 09:19:19 by "openjdk" with gcc 4.4.7 20120313 (Red Hat 4.4.7-23)
Memory: 4k page, physical 8388608k(8386904k free), swap 0k(0k free)
CommandLine flags: -XX:CompressedClassSpaceSize=528482304 -XX:InitialHeapSize=4294967296 -XX:MaxHeapSize=4294967296 -XX:MaxMetaspaceSize=536870912 -XX:MaxNewSize=2147483648 -XX:MetaspaceSize=536870912 -XX:NewSize=2147483648 -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC

2024-09-24T10:43:44.094+0800: 21.703: Total time for which application threads were stopped: 0.0015655 seconds, Stopping threads took: 0.0000978 seconds
{Heap before GC invocations=11 (full 0):
 PSYoungGen      total 1494528K, used 1466389K [0x0000000790800000, 0x00000007f0800000, 0x00000007f0800000)
  eden space 1414656K, 100% used [0x0000000790800000,0x00000007e6d80000,0x00000007e6d80000)
  from space 79872K, 64% used [0x00000007eba00000,0x00000007eec85748,0x00000007f0800000)
  to   space 78336K, 0% used [0x00000007e6d80000,0x00000007e6d80000,0x00000007eba00000)
 ParOldGen       total 2621440K, used 72408K [0x00000006f0800000, 0x0000000790800000, 0x0000000790800000)
  object space 2621440K, 2% used [0x00000006f0800000,0x00000006f4eb60e0,0x0000000790800000)
 Metaspace       used 114761K, capacity 120350K, committed 120576K, reserved 1155072K
  class space    used 13324K, capacity 14260K, committed 14336K, reserved 1048576K
2024-09-24T10:43:44.149+0800: 21.759: [GC (Allocation Failure) [PSYoungGen: 1466389K->41915K(1492992K)] 1538798K->152295K(4114432K), 0.0591035 secs] [Times: user=0.16 sys=0.01, real=0.06 secs]
Heap after GC invocations=11 (full 0):
 PSYoungGen      total 1492992K, used 41915K [0x0000000790800000, 0x00000007f0800000, 0x00000007f0800000)
  eden space 1414656K, 0% used [0x0000000790800000,0x0000000790800000,0x00000007e6d80000)
  from space 78336K, 53% used [0x00000007e6d80000,0x00000007e966ee58,0x00000007eba00000)
  to   space 78336K, 0% used [0x00000007ebb80000,0x00000007ebb80000,0x00000007f0800000)
 ParOldGen       total 2621440K, used 110380K [0x00000006f0800000, 0x0000000790800000, 0x0000000790800000)
  object space 2621440K, 4% used [0x00000006f0800000,0x00000006f73cb088,0x0000000790800000)
 Metaspace       used 114761K, capacity 120350K, committed 120576K, reserved 1155072K
  class space    used 13324K, capacity 14260K, committed 14336K, reserved 1048576K
}
2024-09-24T10:43:44.209+0800: 21.818: Total time for which application threads were stopped: 0.0593724 seconds, Stopping threads took: 0.0000333 seconds


{Heap before GC invocations=906 (full 2):
 PSYoungGen      total 2065920K, used 2041627K [0x0000000760800000, 0x00000007e0800000, 0x00000007e0800000)
  eden space 2034688K, 100% used [0x0000000760800000,0x00000007dcb00000,0x00000007dcb00000)
  from space 31232K, 22% used [0x00000007de980000,0x00000007df046e10,0x00000007e0800000)
  to   space 31232K, 0% used [0x00000007dcb00000,0x00000007dcb00000,0x00000007de980000)
 ParOldGen       total 2097152K, used 2080736K [0x00000006e0800000, 0x0000000760800000, 0x0000000760800000)
  object space 2097152K, 99% used [0x00000006e0800000,0x000000075f7f8060,0x0000000760800000)
 Metaspace       used 176015K, capacity 189742K, committed 191104K, reserved 1218560K
  class space    used 19024K, capacity 21351K, committed 21632K, reserved 1048576K
2024-09-24T14:14:45.047+0800: 11571.644: [GC (Allocation Failure) [PSYoungGen: 2041627K->26414K(2061312K)] 4122363K->2109278K(4158464K), 0.0208053 secs] [Times: user=0.07 sys=0.00, real=0.02 secs]
Heap after GC invocations=906 (full 2):
 PSYoungGen      total 2061312K, used 26414K [0x0000000760800000, 0x00000007e0800000, 0x00000007e0800000)
  eden space 2034688K, 0% used [0x0000000760800000,0x0000000760800000,0x00000007dcb00000)
  from space 26624K, 99% used [0x00000007dcb00000,0x00000007de4cba70,0x00000007de500000)
  to   space 33792K, 0% used [0x00000007de700000,0x00000007de700000,0x00000007e0800000)
 ParOldGen       total 2097152K, used 2082863K [0x00000006e0800000, 0x0000000760800000, 0x0000000760800000)
  object space 2097152K, 99% used [0x00000006e0800000,0x000000075fa0be58,0x0000000760800000)
 Metaspace       used 176015K, capacity 189742K, committed 191104K, reserved 1218560K
  class space    used 19024K, capacity 21351K, committed 21632K, reserved 1048576K
}
{Heap before GC invocations=907 (full 3):
 PSYoungGen      total 2061312K, used 26414K [0x0000000760800000, 0x00000007e0800000, 0x00000007e0800000)
  eden space 2034688K, 0% used [0x0000000760800000,0x0000000760800000,0x00000007dcb00000)
  from space 26624K, 99% used [0x00000007dcb00000,0x00000007de4cba70,0x00000007de500000)
  to   space 33792K, 0% used [0x00000007de700000,0x00000007de700000,0x00000007e0800000)
 ParOldGen       total 2097152K, used 2082863K [0x00000006e0800000, 0x0000000760800000, 0x0000000760800000)
  object space 2097152K, 99% used [0x00000006e0800000,0x000000075fa0be58,0x0000000760800000)
 Metaspace       used 176015K, capacity 189742K, committed 191104K, reserved 1218560K
  class space    used 19024K, capacity 21351K, committed 21632K, reserved 1048576K
2024-09-24T14:14:45.068+0800: 11571.665: [Full GC (Ergonomics) [PSYoungGen: 26414K->0K(2061312K)] [ParOldGen: 2082863K->300700K(2097152K)] 2109278K->300700K(4158464K), [Metaspace: 176015K->174750K(1218560K)], 0.6404574 secs] [Times: user=1.88 sys=0.00, real=0.64 secs]
Heap after GC invocations=907 (full 3):
 PSYoungGen      total 2061312K, used 0K [0x0000000760800000, 0x00000007e0800000, 0x00000007e0800000)
  eden space 2034688K, 0% used [0x0000000760800000,0x0000000760800000,0x00000007dcb00000)
  from space 26624K, 0% used [0x00000007dcb00000,0x00000007dcb00000,0x00000007de500000)
  to   space 33792K, 0% used [0x00000007de700000,0x00000007de700000,0x00000007e0800000)
 ParOldGen       total 2097152K, used 300700K [0x00000006e0800000, 0x0000000760800000, 0x0000000760800000)
  object space 2097152K, 14% used [0x00000006e0800000,0x00000006f2da7140,0x0000000760800000)
 Metaspace       used 174750K, capacity 187618K, committed 191104K, reserved 1218560K
  class space    used 18827K, capacity 20997K, committed 21632K, reserved 1048576K
}

Application pause time

During the GC process, all threads of the application are suspended, which is called the "Stop-The-World" (STW) event. Pause time directly affects the performance and responsiveness of the application.

Log example:

2024-09-24T10:43:44.094+0800: 21.703: Total time for which application threads were stopped: 0.0015655 seconds, Stopping threads took: 0.0000978 seconds

Total time for which application threads were stopped:

  • The total time the application thread was suspended, here is 0.0015655 seconds (~1.57 milliseconds).

Stopping threads took:

  • The time spent suspending the thread, here 0.0000978 seconds (approximately 0.098 milliseconds).

GC (Minor GC)

Log example

2024-09-24T10:43:44.149+0800: 21.759: [GC (Allocation Failure) [PSYoungGen: 1466389K->41915K(1492992K)] 1538798K->152295K(4114432K), 0.0591035 secs]
  • GC type: Minor GC, triggered by memory allocation failure (Allocation Failure).
  • Young generation changes: from 1466389K to 41915K, total capacity 1492992K.
  • Total change in heap memory: from 1538798K to 152295K, total capacity 4114432K.
  • Time taken: 0.0591035 seconds (about 59 milliseconds).

Full GC

Log example:

2024-09-24T14:14:45.068+0800: 11571.665: [Full GC (Ergonomics) [PSYoungGen: 26414K->0K(2061312K)] [ParOldGen: 2082863K->300700K(2097152K)] 2109278K->300700K(4158464K), [Metaspace: 176015K->174750K(1218560K)], 0.6404574 secs]
  • GC type: Full GC, triggered by JVM adaptive mechanism (Ergonomics).
  • Young generation change: from 26414K to 0K, indicating that the young generation has been fully recycled.
  • Old generation changes: reduced from 2082863K to 300700K, freeing up a lot of memory.
  • Total change in heap memory: from 2109278K to 300700K, total capacity 4158464K.
  • Metaspace change: reduced from 176015K to 174750K.
  • Time taken: 0.6404574 seconds (about 640 milliseconds).

Detailed status of heap memory

Due to the use of the -XX:+PrintHeapAtGC parameter, the GC log will print the detailed status of the heap memory before and after each GC, including the capacity and usage of each memory area.

Log example:

Heap before GC invocations=11 (full 0):
 PSYoungGen      total 1494528K, used 1466389K [0x0000000790800000, 0x00000007f0800000, 0x00000007f0800000)
  eden space 1414656K, 100% used [0x0000000790800000,0x00000007e6d80000,0x00000007e6d80000)
  from space 79872K, 64% used [0x00000007eba00000,0x00000007eec85748,0x00000007f0800000)
  to   space 78336K, 0% used [0x00000007e6d80000,0x00000007e6d80000,0x00000007eba00000)
 ParOldGen       total 2621440K, used 72408K [0x00000006f0800000, 0x0000000790800000, 0x0000000790800000)
  object space 2621440K, 2% used [0x00000006f0800000,0x00000006f4eb60e0,0x0000000790800000)
 Metaspace       used 114761K, capacity 120350K, committed 120576K, reserved 1155072K
  class space    used 13324K, capacity 14260K, committed 14336K, reserved 1048576K
  • PSYoungGen (young generation):

    • total (total capacity): 1494528K.
    • used: 1466389K.
    • eden space (Eden area): capacity 1414656K, usage rate 100%.
    • from space (Survivor area): Capacity 79872K, usage rate 64%.
    • to space (Survivor area): capacity 78336K, unused.
  • ParOldGen (old generation):

    • total (total capacity): 2621440K.
    • used: 72408K, usage rate is about 2%.
  • Metaspace:

    • used: 114761K.
    • capacity: 120350K.

Correspondence between JVM startup parameters and GC logs

Due to manually setting the JVM startup parameters, the GC logs contain more detailed information that facilitates in-depth analysis:

  • Memory allocation and usage:

    • With -XX:+PrintHeapAtGC, you can view the heap memory status before and after each GC and understand the memory allocation and usage of each area.
  • Time stamp information:

    • -XX:+PrintGCDateStamps and -XX:+PrintGCTimeStamps provide precise time information to facilitate analysis of the time points and intervals of GC events.
  • GC event details:

    • -XX:+PrintGCDetails outputs detailed information such as the type of GC event, triggering reason, memory recycling status and time consumption.

The above is the detailed content of Detailed explanation of ParallelGC logs. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What are the advantages of using bytecode over native code for platform independence?What are the advantages of using bytecode over native code for platform independence?Apr 30, 2025 am 12:24 AM

Bytecodeachievesplatformindependencebybeingexecutedbyavirtualmachine(VM),allowingcodetorunonanyplatformwiththeappropriateVM.Forexample,JavabytecodecanrunonanydevicewithaJVM,enabling"writeonce,runanywhere"functionality.Whilebytecodeoffersenh

Is Java truly 100% platform-independent? Why or why not?Is Java truly 100% platform-independent? Why or why not?Apr 30, 2025 am 12:18 AM

Java cannot achieve 100% platform independence, but its platform independence is implemented through JVM and bytecode to ensure that the code runs on different platforms. Specific implementations include: 1. Compilation into bytecode; 2. Interpretation and execution of JVM; 3. Consistency of the standard library. However, JVM implementation differences, operating system and hardware differences, and compatibility of third-party libraries may affect its platform independence.

How does Java's platform independence support code maintainability?How does Java's platform independence support code maintainability?Apr 30, 2025 am 12:15 AM

Java realizes platform independence through "write once, run everywhere" and improves code maintainability: 1. High code reuse and reduces duplicate development; 2. Low maintenance cost, only one modification is required; 3. High team collaboration efficiency is high, convenient for knowledge sharing.

What are the challenges in creating a JVM for a new platform?What are the challenges in creating a JVM for a new platform?Apr 30, 2025 am 12:15 AM

The main challenges facing creating a JVM on a new platform include hardware compatibility, operating system compatibility, and performance optimization. 1. Hardware compatibility: It is necessary to ensure that the JVM can correctly use the processor instruction set of the new platform, such as RISC-V. 2. Operating system compatibility: The JVM needs to correctly call the system API of the new platform, such as Linux. 3. Performance optimization: Performance testing and tuning are required, and the garbage collection strategy is adjusted to adapt to the memory characteristics of the new platform.

How does the JavaFX library attempt to address platform inconsistencies in GUI development?How does the JavaFX library attempt to address platform inconsistencies in GUI development?Apr 30, 2025 am 12:01 AM

JavaFXeffectivelyaddressesplatforminconsistenciesinGUIdevelopmentbyusingaplatform-agnosticscenegraphandCSSstyling.1)Itabstractsplatformspecificsthroughascenegraph,ensuringconsistentrenderingacrossWindows,macOS,andLinux.2)CSSstylingallowsforfine-tunin

Explain how the JVM acts as an intermediary between the Java code and the underlying operating system.Explain how the JVM acts as an intermediary between the Java code and the underlying operating system.Apr 29, 2025 am 12:23 AM

JVM works by converting Java code into machine code and managing resources. 1) Class loading: Load the .class file into memory. 2) Runtime data area: manage memory area. 3) Execution engine: interpret or compile execution bytecode. 4) Local method interface: interact with the operating system through JNI.

Explain the role of the Java Virtual Machine (JVM) in Java's platform independence.Explain the role of the Java Virtual Machine (JVM) in Java's platform independence.Apr 29, 2025 am 12:21 AM

JVM enables Java to run across platforms. 1) JVM loads, validates and executes bytecode. 2) JVM's work includes class loading, bytecode verification, interpretation execution and memory management. 3) JVM supports advanced features such as dynamic class loading and reflection.

What steps would you take to ensure a Java application runs correctly on different operating systems?What steps would you take to ensure a Java application runs correctly on different operating systems?Apr 29, 2025 am 12:11 AM

Java applications can run on different operating systems through the following steps: 1) Use File or Paths class to process file paths; 2) Set and obtain environment variables through System.getenv(); 3) Use Maven or Gradle to manage dependencies and test. Java's cross-platform capabilities rely on the JVM's abstraction layer, but still require manual handling of certain operating system-specific features.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor