Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the JDK built-in commands

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains the "what JDK built-in commands", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "what JDK built-in commands" bar!

Javap

You can view the source file decompiled with Java bytecode using javap. The format of the javap command is as follows:

Let's demonstrate decompiling the code with javap-c. First, write a HelloWorld class, as follows:

Public class HelloWorld {

Public static void main (String [] args) {

System.out.println ("Hello World")

}

}

Then using javap-c HelloWorld.class, you can decompile to get the following results:

Compiled from "HelloWorld.java"

Public class HelloWorld {

Public HelloWorld ()

Code:

0: aload_0

1: invokespecial # 1 / / Method java/lang/Object. "() V

4: return

Public static void main (java.lang.String [])

Code:

0: getstatic # 2 / / Field java/lang/System.out:Ljava/io/PrintStream

3: ldc # 3 / / String Hello World

5: invokevirtual # 4 / / Method java/io/PrintStream.println: (Ljava/lang/String;) V

8: return

}

Jps

Jps is used to query the pid of all current processes. The usage of the command is shown in the following figure:

Execute jps to get the pid of the native Java program. The running result is as follows:

[root@wupx ~] # jps

8825 spring-boot-0.0.1-SNAPSHOT.jar

Using jps-mlvV, you can get the pid of the process, the name of the jar package, JVM parameters, and so on.

[root@wupx ~] # jps-mlvV

8825 / root/spring-boot-0.0.1-SNAPSHOT.jar-server.port=8090-logging.file=/root/log/spring-boot.log-Xmx1024m-Xms1024m

Jstat

Jstat is mainly used to monitor JVM, mainly GC information, and is often used in performance optimization. The command content is as follows:

For example, the process number 8825 we found through jps above, we use jstat-gc 8825 to view the GC information of the process:

[root@wupx ~] # jstat-gc 8825

S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT

65536.0 69120.0 0.0 160.0 10425344.0 1036247.8 21135360.0 19489859.7 84608.0 81123.8 9600.0 8834.1 99517 2070.459 0 0.000 2070.459

Where S0C represents the current Survivor0 capacity, S1C represents the current Survivor1 capacity, S0U represents the current Survivor0 utilization, S1U represents the current Survivor1 utilization, EC represents the Eden capacity, EU represents the Eden utilization, OC represents the old age utilization, OU represents the old age utilization, MC represents the Metaspace capacity, MU represents the Metaspace utilization, CCSC represents the class pointer compressed space capacity, CCSU represents the class pointer used to compress the space YGC represents the number of new generation GC, YGCT represents the time of new generation GC, FGC represents the number of times of Full Gc, FGCT represents the time of Full GC, and GCT represents the total time of GC.

Each object has a pointer to its own class, _ klass: a 4-byte pointer to the class, and _ klass on a 64-bit platform: an 8-byte pointer to the class. in order to save this space, class pointers are introduced to compress the space.

Jcmd

Jcmd can view JVM information. Common commands are as follows:

First use jcmd 8825 help to see what commands are supported:

[root@wupx ~] # jcmd 8825 help

8825:

The following commands are available:

JFR.stop

JFR.start

JFR.dump

JFR.check

VM.native_memory

VM.check_commercial_features

VM.unlock_commercial_features

ManagementAgent.stop

ManagementAgent.start_local

ManagementAgent.start

VM.classloader_stats

GC.rotate_log

Thread.print

GC.class_stats

GC.class_histogram

GC.heap_dump

GC.finalizer_info

GC.heap_info

GC.run_finalization

GC.run

VM.uptime

VM.dynlibs

VM.flags

VM.system_properties

VM.command_line

VM.version

Help

Let me choose a parameter to give you an example, such as printing the information of the heap, using the jcmd 8825 GC.heap_dump command:

[root@wupx ~] # jcmd 8825 GC.heap_info

8825:

PSYoungGen total 628736K, used 41772K [0x0000000715a00000, 0x0000000746480000, 0x00000007c0000000)

Eden space 609792K, 4% used [0x0000000715a000000x00000007173d5478pr 0x000000073ad80000)

From space 18944K, 80% used [0x000000073ad80000memori0x000000073bc75e68memori0x000000073c000000)

To space 19968K, 0% used [0x00000007451000000x00000007451000000x0000000746480000)

ParOldGen total 250880K, used 21756K [0x00000005c0e00000, 0x00000005d0300000, 0x0000000715a00000)

Object space 250880K, 8% used [0x00000005c0e00000J0x00000005c233f160pr 0x00000005d0300000)

Metaspace used 44797K, capacity 45562K, committed 45824K, reserved 1089536K

Class space used 5669K, capacity 5832K, committed 5888K, reserved 1048576K

It can be seen that the size and proportion of Cenozoic, old age, metaspace, Eden, From Survivor and To Survivor can be obtained.

Jmap

Jmap prints out the Object in the memory of the Java process, or outputs the heap in JVM into text in binary, as follows:

Use jmap-heap 8825 to view the current heap usage information:

[root@wupx ~] # jmap-heap 8825

Attaching to process ID 8825, please wait...

Debugger attached successfully.

Server compiler detected.

JVM version is 25.201-b09

Using thread-local object allocation.

Parallel GC with 10 thread (s)

Heap Configuration:

MinHeapFreeRatio = 0

MaxHeapFreeRatio = 100

MaxHeapSize = 8575254528 (8178.0MB)

NewSize = 178782208 (170.5MB)

MaxNewSize = 2858418176 (2726.0MB)

OldSize = 358088704 (341.5MB)

NewRatio = 2

SurvivorRatio = 8

MetaspaceSize = 21807104 (20.796875MB)

CompressedClassSpaceSize = 1073741824 (1024.0MB)

MaxMetaspaceSize = 17592186044415 MB

G1HeapRegionSize = 0 (0.0MB)

Heap Usage:

PS Young Generation

Eden Space:

Capacity = 624427008 (595.5MB)

Used = 32083672 (30.597373962402344MB)

Free = 592343336 (564.9026260375977MB)

5.138098062536078% used

From Space:

Capacity = 19398656 (18.5MB)

Used = 15687272 (14.960548400878906MB)

Free = 3711384 (3.5394515991210938MB)

80.86782919394004% used

To Space:

Capacity = 20447232 (19.5MB)

Used = 0 (0.0MB)

Free = 20447232 (19.5MB)

0.0% used

PS Old Generation

Capacity = 256901120 (245.0MB)

Used = 22278496 (21.246429443359375MB)

Free = 234622624 (223.75357055664062MB)

8.672012017697703 used

24741 interned Strings occupying 2987512 bytes.

First of all, some related configurations of the heap will be printed, such as the maximum Cenozoic, the size of metaspace, and so on. The following is the usage of the heap, including the Eden area, S0 area, S1 area and the old age of the Cenozoic era.

Jmap can also save the heap information as a file, which is equivalent to a snapshot of the file, and execute the jmap-dump:live,format=b,file=heap.bin 8825 command:

[root@wupx ~] # jmap-dump:live,format=b,file=heap.bin 8825

Dumping heap to / root/heap.bin...

Heap dump file created

This heap.bin can be opened using the jhat command and is displayed in the form of html.

Jhat

Jhat analyzes the Java heap command, which can display the objects in the heap in the form of html, and supports the object query language OQL. The command content is as follows:

Now execute jhat-port 9999 heap.bin to display the heap.bin you just saved in html:

[root@wupx ~] # jhat-port 9999 heap.bin

Reading from heap.bin...

Dump file created Tue May 12 22:31:55 CST 2020

Snapshot read, resolving...

Resolving 570997 objects...

Chasing references, expect 114 dots.

Eliminating duplicate references.

Snapshot resolved.

Started HTTP server on port 9999

Server is ready.

After execution, open http://localhost:9999/ and you can see the heap usage of instances of the class, which are grouped by package name:

There are many ways of Query at the bottom of the page:

Take OQL as an example. It opens with a window similar to SQL query. For example, enter select s from java.lang.String s where s.value.length > = 100 to query instances whose string length is greater than 100:

Jstack

Jstack is a stack trace tool, which is mainly used to print stack information of a given process pid. It is generally used to troubleshoot problems when deadlock or CPU 100% occurs. You can query the currently running thread and the stack information of the thread. The command content is as follows:

Let's execute the jstack-F 8825 > jstack.log command to save the thread's information:

Full thread dump Java HotSpot (TM) 64-Bit Server VM (25.161-b12 mixed mode):

"Attach Listener" # 51805777 daemon prio=9 os_prio=0 tid=0x00007f971c001000 nid=0x9cd6 waiting on condition [0x0000000000000000]

Java.lang.Thread.State: RUNNABLE

"DestroyJavaVM" # 55 prio=5 os_prio=0 tid=0x00007f9fc8009800 nid=0x227a waiting on condition [0x0000000000000000]

Java.lang.Thread.State: RUNNABLE

"http-nio-8111-Acceptor-0" # 52 daemon prio=5 os_prio=0 tid=0x00007f96c40c5800 nid=0x2653 runnable [0x00007f97c0df9000]

Java.lang.Thread.State: RUNNABLE

At sun.nio.ch.ServerSocketChannelImpl.accept0 (Native Method)

At sun.nio.ch.ServerSocketChannelImpl.accept (ServerSocketChannelImpl.java:422)

At sun.nio.ch.ServerSocketChannelImpl.accept (ServerSocketChannelImpl.java:250)

-locked (a java.lang.Object)

At org.apache.tomcat.util.net.NioEndpoint$Acceptor.run (NioEndpoint.java:455)

At java.lang.Thread.run (Thread.java:748)

"http-nio-8111-ClientPoller-0" # 50 daemon prio=5 os_prio=0 tid=0x00007f9fc8e7e000 nid=0x2651 runnable [0x00007f97c21fb000]

Java.lang.Thread.State: RUNNABLE

At sun.nio.ch.EPollArrayWrapper.epollWait (Native Method)

At sun.nio.ch.EPollArrayWrapper.poll (EPollArrayWrapper.java:269)

At sun.nio.ch.EPollSelectorImpl.doSelect (EPollSelectorImpl.java:93)

At sun.nio.ch.SelectorImpl.lockAndDoSelect (SelectorImpl.java:86)

-locked (a sun.nio.ch.Util$3)

-locked (a java.util.Collections$UnmodifiableSet)

-locked (a sun.nio.ch.EPollSelectorImpl)

At sun.nio.ch.SelectorImpl.select (SelectorImpl.java:97)

At org.apache.tomcat.util.net.NioEndpoint$Poller.run (NioEndpoint.java:787)

At java.lang.Thread.run (Thread.java:748)

"Service Thread" # 17 daemon prio=9 os_prio=0 tid=0x00007f9fc8379000 nid=0x229d runnable [0x0000000000000000]

Java.lang.Thread.State: RUNNABLE

"C1 CompilerThread10" # 15 daemon prio=9 os_prio=0 tid=0x00007f9fc8373800 nid=0x229b waiting on condition [0x0000000000000000]

Java.lang.Thread.State: RUNNABLE

"VM Thread" os_prio=0 tid=0x00007f9fc831c000 nid=0x228d runnable

"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x00007f9fc801e800 nid=0x227b runnable

"GC task thread#1 (ParallelGC)" os_prio=0 tid=0x00007f9fc8020800 nid=0x227c runnable

"VM Periodic Task Thread" os_prio=0 tid=0x00007f9fc837e000 nid=0x229e waiting on condition

JNI global references: 357

Because there is a lot of content, you can see that the thread information, status and stack will be printed, and the thread information of GC Task will also be printed (ParallelGC belongs to parallel collector, default is 2 threads), from which you can analyze what each thread is doing. If the server CPU occupies a high number of threads, you can see how many threads are in the RUNNABLE state. Generally, the CPU is too high because there are too many threads in the RUNNABLE state. If many threads are in the TIMED_WAITING state, the CPU footprint is theoretically not very high.

Thank you for your reading, the above is the content of "what JDK built-in commands", after the study of this article, I believe you have a deeper understanding of what JDK built-in commands have, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report