Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to tell if VM is running in server or client mode?

Tags:

java

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.

like image 769
Miserable Variable Avatar asked Aug 21 '09 11:08

Miserable Variable


People also ask

Is JVM a server?

A JVM server is a runtime environment that can handle many concurrent requests for different Java™ applications in a single JVM.

What is Javaclient?

A Java client is a Java application written to execute in a Java Virtual Machine (JVM) on a client device – typically a desktop, mobile device, or other endpoint.

What is Java HotSpot client?

The Java HotSpot Client Virtual Machine* serves as a replacement for both the "classic" virtual machine and the Just-in-time (JIT) compilers used by previous versions of the Java 2 SDK to offer improved runtime performance for applications and applets.


3 Answers

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".

like image 79
VonC Avatar answered Oct 09 '22 21:10

VonC


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

like image 37
Mark Avatar answered Oct 09 '22 19:10

Mark


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.

like image 30
Massimiliano Fliri Avatar answered Oct 09 '22 20:10

Massimiliano Fliri