tags:

views:

254

answers:

4

The Java hotspot vpm can be run with -client or -server argument. If neither is specified then it chooses one according to some rules.

Is it possible to tell whether a running VM is running in client or server mode when the mode is not specified on command line? I need this on a Windows box outside the running process.

I realize this is not a programming question, but I hope it is ok because it is programming related. Thanks in advance.

A: 

In Java, you could check this with this code:

String s = System.getProperty("java.vm.name");
// s = Java HotSpot(TM) Server VM

But this will be highly vendor specific.

From the command line, you could use jinfo (used to check a value of a given HotSpot VM option)

C:\>"c:\Program Files\Java\jdk1.6.0_16\bin\jps.exe" -l -m
21812 sun.tools.jps.Jps -l -m
19244 (eclipse)

C:\>"c:\Program Files\Java\jdk1.6.0_16\bin\jinfo.exe" -flag NewRatio 19244
-XX:NewRatio=12

Since:

  • it is rare to actually set the NewRatio Hotpot option and
  • the documentation specifies: Ratio of new/old generation sizes. [x86 -server: 8; x86 -client: 12]

12 means "Client".

VonC
I do need this on the command line, but unfortunately jinfo does not support this on Windows, which is where I need it.
Hemal Pandya
the return string is vendor specific, but the whole Client vs Server VM issue is vendor specific as well.
beetstra
@Hemal: if you can copy a JDK6, you can call jinfo on Windows
VonC
@VonC: I am using JDK6, but on Windows jinfo only supports the -flag option of a running process. http://java.sun.com/javase/6/docs/technotes/tools/share/jinfo.html#options
Hemal Pandya
@Hemal hence my usage of jinfo, strictly limited to the -flag: it works
VonC
+4  A: 

Connect to the running Java process with jvisualvm. This will let you see the JVM arguments that have been used.

Mark
A: 

If the jvm is started with -debug, you can connect to it using jdb, and use eval ...

eval System.getProperty("java.vm.name");

that or jinfo

Jean
+1  A: 

You can retrieve this information connecting to the MBean server. If you are running a Sun VM, you have an MBean with name "java.lang:type=Runtime" which exposes the attribute "VmName", whose value is the same as system property "java.vm.name". In example, for a server vm the value will be something like "Java HotSpot(TM) Server VM". VM's from other vendors may use a similar mechanism.

You can connect to the MBean server either using the tools included in the JDK, like jconsole or jvisualvm, or by writing your own tool using JMX if you need programmatic access.

Massimiliano Fliri