Java 9 : Unified logging for JVM
Java 9 implemented JEP 158: Unified JVM Logging, which requested to introduce a common logging system for all the components of the JVM. The main components of JVM include the following:
Method area
Heap area
PC registers
Native method stack
Interpreter
The JIT compiler
Garbage collection
Native method interface JNI
Native method library
java -Xlog:help
Here is the output:
The format of the -Xlog option is defined as follows:
-Xlog[:[what][:[output][:[decorators][:output-options]]]]
1. Run the following command:
java -Xlog:cpu -cp ./cookbook-1.0.jar
com.packt.cookbook.ch12_memory.Chapter12Memory
There are no messages because the JVM does not log messages with the cpu
tag only. The tag is used in combination with other tags.
2. Add a * sign and run the command again:
java -Xlog:cpu* -cp ./cookbook-1.0.jar
com.packt.cookbook.ch12_memory.Chapter12Memory
As you can see, the tag cpu brings only messages that log time it took a
garbage collection task to execute. Even if we set the log level to trace or
debug (-Xlog:cpu*=debug, for example), no other messages will be shown.
3. Now run the command with the heap tag:
java -Xlog:heap* -cp ./cookbook-1.0.jar
com.packt.cookbook.ch12_memory.Chapter12Memory
You will only get heap-related messages.
instead of PID/main-class, put the process identifier or the main class
name. The list is specific to the JVM, so the command requests the data from
the specific process.
jcmd -h
which prints all the performance counters(statistics) of the process.
jcmd Chapter12Memory GC.heap_info
It shows the total heap size and how much of it was used
jcmd Chapter12Memory Thread.print
jcmd Chapter12Memory VM.info
address range, and state (alive, non-entrant, and zombie) and allows the
selection of printing to stdout , a file, XML, or text printout
Compiler.codecache: This prints the content of the code cache, where the JIT
compiler stores the generated native code to improve performance
Compiler.directives_add file: This adds compiler directives from a file to
the top of the directives stack
Compiler.directives_clear: This clears the compiler directives stack (leaves
the default directives only)
Compiler.directives_print: This prints all the directives on the compiler
directives stack from top to bottom
Compiler.directives_remove: This removes the top directive from the
compiler directives stack
GC.heap_info: This prints the current heap parameters and status
GC.finalizer_info: This shows the status of the finalizer thread, which
collects objects with a finalizer (that is, a finalize() method)
JFR.configure: This allows configuring the Java Flight Recorder
JVMTI.data_dump: This prints the Java Virtual Machine Tool Interface data
dump
JVMTI.agent_load: This loads (attaches) the Java Virtual Machine Tool
Interface agent
ManagementAgent.status: This prints the status of the remote JMX agent
Thread.print:This prints all the threads with stack traces
VM.log [option]: This allows setting the JVM log configuration (which we
described in the previous recipe) at runtime, after the JVM has started (the
availability can be seen by using VM.log list)
VM.info: This prints the unified JVM info (version and configuration), a list
of all threads and their state (without thread dump and heap dump), heap
summary, JVM internal events (GC, JIT, safepoint, and so on), memory
map with loaded native libraries, VM arguments and environment
variables, and details of the operation system and hardware
VM.dynlibs: This prints information about dynamic libraries
VM.set_flag: This allows setting the JVM writable (also called manageable)
flags (see the JVM documentation for a list of the flags)
VM.stringtable and VM.symboltable: These print all UTF-8 string constants
VM.class_hierarchy [full-class-name]: This prints all the loaded classes or
just a specified class hierarchy
VM.classloader_stats: This prints information about the classloader
VM.print_touched_methods: This prints all the methods that have been touched
at runtime
- Class loader
- Runtime data area
Method area
Heap area
PC registers
Native method stack
- Execution engine
Interpreter
The JIT compiler
Garbage collection
Native method interface JNI
Native method library
Command:
java -Xlog:helpHere is the output:
The format of the -Xlog option is defined as follows:
-Xlog[:[what][:[output][:[decorators][:output-options]]]]
1. Run the following command:
java -Xlog:cpu -cp ./cookbook-1.0.jar
com.packt.cookbook.ch12_memory.Chapter12Memory
There are no messages because the JVM does not log messages with the cpu
tag only. The tag is used in combination with other tags.
2. Add a * sign and run the command again:
java -Xlog:cpu* -cp ./cookbook-1.0.jar
com.packt.cookbook.ch12_memory.Chapter12Memory
As you can see, the tag cpu brings only messages that log time it took a
garbage collection task to execute. Even if we set the log level to trace or
debug (-Xlog:cpu*=debug, for example), no other messages will be shown.
3. Now run the command with the heap tag:
java -Xlog:heap* -cp ./cookbook-1.0.jar
com.packt.cookbook.ch12_memory.Chapter12Memory
You will only get heap-related messages.
jcmd commands
jcmd PID/main-class-name helpinstead of PID/main-class, put the process identifier or the main class
name. The list is specific to the JVM, so the command requests the data from
the specific process.
jcmd -h
which prints all the performance counters(statistics) of the process.
jcmd Chapter12Memory GC.heap_info
It shows the total heap size and how much of it was used
jcmd Chapter12Memory Thread.print
jcmd Chapter12Memory VM.info
JDK 9 introduced the following new jcmd commands:
Compiler.codelist: This prints n-methods (compiled) with full signature,address range, and state (alive, non-entrant, and zombie) and allows the
selection of printing to stdout , a file, XML, or text printout
Compiler.codecache: This prints the content of the code cache, where the JIT
compiler stores the generated native code to improve performance
Compiler.directives_add file: This adds compiler directives from a file to
the top of the directives stack
Compiler.directives_clear: This clears the compiler directives stack (leaves
the default directives only)
Compiler.directives_print: This prints all the directives on the compiler
directives stack from top to bottom
Compiler.directives_remove: This removes the top directive from the
compiler directives stack
GC.heap_info: This prints the current heap parameters and status
GC.finalizer_info: This shows the status of the finalizer thread, which
collects objects with a finalizer (that is, a finalize() method)
JFR.configure: This allows configuring the Java Flight Recorder
JVMTI.data_dump: This prints the Java Virtual Machine Tool Interface data
dump
JVMTI.agent_load: This loads (attaches) the Java Virtual Machine Tool
Interface agent
ManagementAgent.status: This prints the status of the remote JMX agent
Thread.print:This prints all the threads with stack traces
VM.log [option]: This allows setting the JVM log configuration (which we
described in the previous recipe) at runtime, after the JVM has started (the
availability can be seen by using VM.log list)
VM.info: This prints the unified JVM info (version and configuration), a list
of all threads and their state (without thread dump and heap dump), heap
summary, JVM internal events (GC, JIT, safepoint, and so on), memory
map with loaded native libraries, VM arguments and environment
variables, and details of the operation system and hardware
VM.dynlibs: This prints information about dynamic libraries
VM.set_flag: This allows setting the JVM writable (also called manageable)
flags (see the JVM documentation for a list of the flags)
VM.stringtable and VM.symboltable: These print all UTF-8 string constants
VM.class_hierarchy [full-class-name]: This prints all the loaded classes or
just a specified class hierarchy
VM.classloader_stats: This prints information about the classloader
VM.print_touched_methods: This prints all the methods that have been touched
at runtime
Comments
Post a Comment