Reputation: 99536
On Ubuntu, man jps
says
jps - Lists the instrumented Java Virtual Machines (JVMs) on the target system.
What does a "instrumented Java Virtual Machine" mean?
$ jps -v
29584 Jps -Dapplication.home=/usr/lib/jvm/java-11-openjdk-amd64 -Xms8m -Djdk.module.main=jdk.jcmd
Is a jps process a JVM process, by definition?
jps is an ELF file, not a JVM bytecode program compiled from a Java program:
$ file /usr/lib/jvm/java-11-openjdk-amd64/bin/jps
/usr/lib/jvm/java-11-openjdk-amd64/bin/jps: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/l, for GNU/Linux 3.2.0, BuildID[sha1]=3f48c70ab711b493ee793c92c19b3a884896bb4d, stripped
$ jps -v
16462 Jps -Dapplication.home=/usr/lib/jvm/java-11-openjdk-amd64 -Xms8m -Djdk.module.main=jdk.jcmd
Upvotes: 2
Views: 2006
Reputation: 719446
What does a "instrumented Java Virtual Machine" mean?
An instrumented JVM is a JVM that is instrumented.
However, that is a fatuous definition, and I have not been able to find a clearly documented definition of what "instrumented" really means.
In fact, it potentially applies to (at least) any HotSpot JVM since Java 5.0. The current implementation of jps
looks for instrumented JVMs as follows:
If you specify a hostid
, jps
attempts to contact an RMI service (jstatd
) on the host to find out about the Java processes.
If you don't specify a hostid
, jps
finds Java processes by looking for /tmp/hsperfdata_<username>
directories that are readable by the current user; see How do jps, jinfo, jstat, jmap and jstack get information about local Java processes?. A JVM will create one of these directories unless you launch the JVM with -XX:-UsePerfData
or -XX:-PerfDisableSharedMem
. (Thanks to @apangin for this information.)
But ultimately we still have a circular (working) definition: an "instrumented JVM" is one that jps
is able to find.
Is a jps process a JVM process, by definition?
The current implementation of jps
is a Java class that runs in a JVM created by a generic launcher (the jps
executable). However, there is no "definition" that says that is has to be implemented this way.
Note that since jps
without any arguments will find itself (at least on my system) that strongly (IMO) suggests that the current implementation uses an instrumented JVM.
jps is an ELF file, not a JVM bytecode program compiled from a Java program
That actually has nothing to do with it. A JVM is a thing (a virtual machine) that is executing a Java program. It is not relevant to "JVM-ness" how the program is launched, or even whether the program was represented as bytecodes at launch time.
With jlink
(or older 3rd-party products) an ordinary Java (bytecode) program can be turned into a native executable. On Linux, jlink
will produce an ELF file. Yet, when you run the ELF file, you will still have a JVM.
Upvotes: 8
Reputation: 533820
Most of the commands which come with the JVM are actually implemented using Java. In this case, jps
starts a JVM to run a class sun.tools.jps.Jps
http://www.docjar.com/html/api/sun/tools/jps/Jps.java.html
Similarly javac
actually runs com.sun.tools.javac.Main
https://docs.oracle.com/javase/9/docs/api/com/sun/tools/javac/Main.html
Upvotes: 2