Serviceability in the J2SE Repository

This page describes the Serviceability technologies in the J2SE repository. These technologies use the following serviceability technologies in the HotSpot repository:

Please see HotSpot Serviceability for more information on these technologies in the HotSpot repository.

The following table shows where the Serviceability technologies reside in the J2SE repository and in the binary release, and contains links to user level information and building/implementation notes. The building/implementation notes are not intended to be complete documentation but just some high level notes that will help the reader get started understanding how these technologies work.
For JPDA, the reader is advised to read the User Guide to learn the architecture of JPDA before reading the build/implementation notes.

Notes:



Technology
Source Location
Binary Location
More Info
JPDA-Java Platform Debugger Architecture --- --- Home Page
Bugs
   JDI-Java Debug Interface j2se/src/share/classes/com/sun/jdi/
j2se/src/share/classes/com/sun/tools/jdi/
j2se/build/<arch>/gensrc/com/sun/tools/jdi/JDWP.java
j2se/test/com/sun/jdi/
j2se/make/jpda/front/
jdk/lib/tools.jar User Guide
Bugs | grep -i jdi
   JDWP-Java Debug Wire Protocol j2se/src/share/classes/com/sun/tools/jdwpgen/jdwp.spec
j2se/src/share/classes/com/sun/tools/jdwpgen/*.java
j2se/src/share/back/
j2se/src/share/javavm/export/jdwpTransport.h
j2se/build/<arch>/gensrc/com/sun/tools/jdi/JDWP.java
j2se/build/<arch>/tmp/jpda/com.sun.tools.jdwpgen/\
   jdwp/JDWPCommands.h j2se/make/jpda/back/
j2se/make/jpda/jdwp/
j2se/make/jpda/jdwpgen/
jre/lib/<arch>/libjdwp.so
jre/bin/jdwp.dll
User Guide
Bugs | grep -i jdwp
   Transports / Connectors j2se/src/solaris/transport/
j2se/src/windows/transport/
j2se/src/windows/classes/com/sun/tools/jdi/
j2se/src/share/transport/shmem/
j2se/src/share/transport/socket/
j2se/src/share/native/com/sun/tools/jdi/SharedMemory*
j2se/make/jpda/transport/
jre/lib/<arch>/libdt_socket.so
jre/bin/dt_shmem.dll
jre/bin/dt_socket.dll
User Guide
   JVM TI- Java Virtual Machine Tools Interface j2se/src/share/javavm/export/jvmti.h libjvm.so
jvm.dll
User Guide
Hotspot Info
Bugs
   jdb: See demo entry below --- --- ---
 
Other APIs
 
Profiling and Bytecode Instrumentation j2se/src/share/classes/java/lang/instrument/
j2se/src/share/classes/sun/instrument/
j2se/src/share/instrument/
j2se/make/java/lang/instrument/
j2se/test/java/lang/instrument/
j2se/test/sun/instrument/
jre/lib/<arch>/libinstrument.so
jre/bin/instrument.dll
User Guide
Bugs | grep -i instrument
Java Management Extension (JMX) j2se/src/share/classes/javax/management/
j2se/src/share/classes/com/sun/jmx/
jre/lib/rt.jar Home Page
Bugs
Monitoring and Management j2se/src/share/classes/java/lang/management/
j2se/src/share/classes/com/sun/management/
j2se/src/share/classes/sun/management/
j2se/src/share/lib/management/
j2se/src/share/native/sun/management/
j2se/src/solaris/classes/com/sun/management/
j2se/src/solaris/classes/sun/management/
j2se/src/solaris/native/com/sun/management/
j2se/src/solaris/native/sun/management/
j2se/src/windows/classes/com/sun/management/
j2se/src/windows/classes/sun/management/
j2se/src/windows/native/com/sun/management/
j2se/src/windows/native/sun/management/
j2se/src/share/javavm/export/jmm.h
j2se/make/java/lang/management/
j2se/test/java/lang/management/
j2se/test/com/sun/management/
j2se/test/sun/management/
jre/lib/rt.jar jre/lib/management-agent.jar
jre/lib/management
jre/lib/<arch>/libmanagement.so
jre/bin/management.dll
Home Page
Hotspot Info
Bugs
HotSpot Bugs
NPT - Native Platform Toolkit j2se/src/share/npt/
j2se/src/solaris/npt/
j2se/src/windows/npt/
j2se/make/java/npt/
jre/lib/<arch>/libnpt.so
jre/bin/npt.dll
j2se/src/share/npt/method.html
Dynamic Attach Mechanism j2se/src/share/classes/com/sun/tools/attach/
j2se/src/share/classes/sun/tools/attach/
j2se/src/solaris/classes/sun/tools/attach/
j2se/src/solaris/native/sun/tools/attach/LinuxVirtualMachine.c
j2se/src/solaris/native/sun/tools/attach/SolarisVirtualMachine.c
j2se/src/windows/classes/sun/tools/attach/
j2se/src/windows/native/sun/tools/attach/
j2se/test/com/sun/tools/attach/
jdk/lib/tools.jar
jdk/jre/lib/<arch>/libattach.so
jdk/jre/bin/attach.dll
User Guide
Hotspot Info
Bugs | grep -i attach
Jvmstat Performance Counters j2se/src/share/classes/sun/jvmstat/monitor/
j2se/src/share/classes/sun/jvmstat/perfdata/
jdk/lib/tools.jar
Javadoc
Hotspot Info
Bugs | grep -i jvmstat
HotSpot Bugs
ServiceabilityAgent All the SA code is currently in the HotSpot
repository, in the agent/ directory.
jre/lib/<arch>/libsaproc.so
jdk/lib/sa-jdi.jar
As of JDK 6, SA is not released on Windows
Hotspot Info
Bugs | grep SA
 
Demos and sample code
 
   jdb j2se/src/share/classes/com/sun/tools/example/debug/tty/
j2se/make/jpda/bdi/
j2se/make/jpda/expr/
j2se/make/jpda/tty/
j2se/make/jpda/gui/
jdk/bin/jdb
jdk/demo/jpda/examples.jar
User Guide
Bugs | grep -i tty
   hprof
j2se/src/*/demo/jvmti/hprof/
j2se/src/share/classes/sun/tools/hprof/Tracker.java
j2se/make/java/java_hprof_demo
jdk/demo/jvmti/hprof
jre/lib/<arch>/libhprof.so
jre/bin/hprof.dll
jre/lib/jvm.hprof.txt
jdk/demo/jvmti/hprof/src/manual.html Bugs
   java_crw_demo j2se/src/share/demo/jvmti/java_crw_demo/
j2se/src/share/javavm/export/classfile_constants.h
j2se/make/java/java_crw_demo/
jdk/demo/jvmti/java_crw_demo jdk/demo/jvmti/\
   java_crw_demo/README.txt
   JVM TI demos j2se/src/share/demo/jvmti/
j2se/make/mkdemo/jvmti/
jdk/demo/jvmti/ jdk/demo/NAME/README.txt
   JConsole plugin demo j2se/src/share/demo/scripting/jconsole-plugin/
jdk/demo/scripting/jconsole-plugin/
jdk/demo/jconsole-plugin/README.txt
   Management demos:
     FullThreadDump
     JTop
     MemoryMonitor
     VerboseGC
j2se/src/share/demo/management/* jdk/demo/nbproject/management/*
jdk/demo/management/*
jdk/demo/management/*/README.txt
 
Serviceability Tools
 
jconsole j2se/src/share/classes/sun/tools/jconsole/
j2se/src/share/classes/com/sun/tools/jconsole/
j2se/make/sun/jconsole/
j2se/make/netbeans/jconsole/
j2se/make/netbeans/jconsole/README
jdk/lib/jconsole.jar
jdk/bin/jconsole
Man page
Bugs
jdb - See jdb demo entry above --- --- ---
jhat jdk/src/share/classes/com/sun/tools/hat/
j2se/make/sun/hat/
jdk/bin/jhat Man page
Bugs | grep jhat
jinfo jdk/src/share/classes/sun/tools/jinfo/
j2se/make/sun/jinfo/
jdk/bin/jinfo Man page
Bugs | grep jinfo
jmap jdk/src/share/classes/sun/tools/jmap/
j2se/make/sun/jmap/
jdk/bin/jmap Man page
Bugs | grep jmap
jps jdk/src/share/classes/sun/tools/jps/
j2se/make/sun/jps/
jdk/bin/jps Man page
Bugs | grep jps
jcontrol deploy/src/plugin/solaris/controlpanel/ deploy/src/plugin/win32/controlpanel/ deploy/src/common/share/classes/com/sun/deploy/panel/ jre/bin/jcontrol
jre/lib/deploy.jar
jre/bin/javacpl.exe
jre/bin/javacpl.cpl
User Guide
jsadebugd hotspot/agent/src/share/classes/sun/jvm/hotspot/jdi/\
   SADebugServer.java
j2se/make/sun/jsadebugd/
jdk/bin/jsadebugd Man page
jstack jdk/src/share/classes/sun/tools/jstack/
j2se/make/sun/jstack/
jdk/bin/jstack Man page
Bugs | grep jstack
jstat j2se/src/share/classes/sun/tools/jstat/
j2se/make/sun/jstat/
jdk/bin/jstat Man page
Bugs | grep jstat
jstatd jdk/src/share/classes/sun/tools/jstatd/
j2se/make/sun/jstatd/
jdk/bin/jstatd Man page

Build and Implementation Notes

JDI-Java Debug Interface and the Front-end

The Java Debug Interface consists of the API in com.sun.jdi and the implementation in com.sun.tools.jdi. The API is an optional part of the Java platform. Please refer to the JPDA documentation for more information about how JDI and its implementation fits into JPDA, and how requests and events flow through JPDA. Please see JPDA Front-end Threads for information about the thread structure of the front-end.

The front-end can register to receive events on its own. It currently needs to keep track of classes that are loaded so it registers to receive class prepare events and class unload events. These events are handled by the front-end's Internal Event Handler thread.

The front-end uses a class named JDWP whose .java file is generated by the jdwpgen program, see below. JDWP contains all the methods that the front-end calls to create JDWP command packets. These methods then call transport methods to actually send the packets down the wire to the back-end.

The front-end also contains the code for the default connectors and contains the Java code for the socket transport. The socket transport uses the socket support in the JDK libraries so no native code is needed in the front-end.

This is not true of the shared memory transport, so it is implemented in native code which executes as part of the front-end. Note that the shared memory transport is only available on Windows, and so its code is in a Windows specific directory. See the Transports and Connectors section for more information.
up arrow

JDWP-Java Debug Wire Protocol and the Back-end

File jdwp.spec contains the base definition of JDWP. During the build of JPDA, the jdwpgen program is built and is then called to process jdwp.spec. This creates three files:

JDWP and JDI are generally isomorphic, but there are exceptions. In addition, for each front-end file, eg, VirtualMachineImpl.java, there tends to be a back-end file, eg, VirtualMachineImpl.c that contains the code that handles the JDWP commands that originate from the JDI methods defined in the corresponding front-end file.

The structure of the JDWP packets for the various commands is embedded in the back-end files. For example to read the redefineClasses command, back-end file VirtualMachineImpl.c does this:

static jboolean 
redefineClasses(PacketInputStream *in, PacketOutputStream *out) 
{
    jvmtiClassDefinition *classDefs;
    jboolean ok = JNI_TRUE;
    jint classCount;
    jint i;
    JNIEnv *env;

    if (gdata->vmDead) {
        /* quietly ignore */                
        return JNI_TRUE;
    }

    classCount = inStream_readInt(in);
    if (inStream_error(in)) {
        return JNI_TRUE;
    }
    if ( classCount == 0 ) {
        return JNI_TRUE;
    }
    /*LINTED*/
    classDefs = jvmtiAllocate(classCount*(int)sizeof(jvmtiClassDefinition));
    if (classDefs == NULL) {
        outStream_setError(out, JDWP_ERROR(OUT_OF_MEMORY));
        return JNI_TRUE;
    }
    /*LINTED*/
    (void)memset(classDefs, 0, classCount*sizeof(jvmtiClassDefinition));
  
    env = getEnv();

    for (i = 0; i < classCount; ++i) {
        int byteCount;
        unsigned char * bytes;
        jclass clazz;
        
        clazz = inStream_readClassRef(env, in);
        if (inStream_error(in)) {
            ok = JNI_FALSE;
            break;
        }
        byteCount = inStream_readInt(in);
        if (inStream_error(in)) {
            ok = JNI_FALSE;
            break;
        }
        if ( byteCount <= 0 ) {
            outStream_setError(out, JDWP_ERROR(INVALID_CLASS_FORMAT));
            ok = JNI_FALSE;
            break;
        }
        bytes = (unsigned char *)jvmtiAllocate(byteCount);
        if (bytes == NULL) {
            outStream_setError(out, JDWP_ERROR(OUT_OF_MEMORY));
            ok = JNI_FALSE;
            break;
        }        
        (void)inStream_readBytes(in, byteCount, (jbyte *)bytes);
        if (inStream_error(in)) {
            ok = JNI_FALSE;
            break;
        }

    

The back-end calls JVM TI functions to actually interrogate the JVM. To do this, it uses file jvmti.h which defines JVM TI. See JVM TI for more information on jvmti.h

See JPDA Back-end Threads for information about the threads used in the back-end.
up arrow

JPDA Transports and Connectors

Currently, each JPDA transport is wrapped in a JDPA connector. These all reside in .jar files and are discovered by the VirtualMachineManagerImpl constructor which is called from class com.sun.jdi.Bootstrap during front-end initialization. See Service Provider Interfaces for information on adding custom connectors/transports to a JPDA installation.
up arrow

JVM TI

The code for JVM TI is in the HotSpot repository; please see JVM TI.

The HotSpot build process creates interface file jvmti.h which is used by JVM TI agents such as the JPDA back-end. jvmti.h is copied from the HotSpot build area and checked into the J2SE repository whenever changes are made to the interface. This file contains a JVM TI version number which is compiled into the back-end and is checked against the JVM TI version that is compiled into HotSpot during back-end startup.
up arrow

Profiling and Instrumentation

java.lang.instrument uses a native JVM TI agent called the JPLISAgent. The JPLISAgent manages the initialization of all the Java programming language Agents. It also supports the native method bridge between the JPLIS and the JVM TI. It maintains a single JVMTI Env that all JPL agents share. It parses command line requests and creates individual Java agents. The code for this agent is contained in j2se/src/share/instrument. At runtime, it resides in libinstrument.so/instrument.dll and is dynamically loaded by code in sun.instrument.InstrumentationImpl.
up arrow

Monitoring and Management

Java SE contains a JMX MBean Server called the Platform MBean Server (see java.lang.management.ManagementFactory.getPlatformMBeanServer) which can be used to make MBeans available for remote access. The Platform MBean Server is started by code in j2se/src/share/classes/sun/management/Agent.java. This class is named as the Premain-class and Agent-class in JPLIS agent jre/lib/management-agent.jar which allows the agent (and thus the Platform MBean Server) to be started dynamically via the loadAgent method of Dynamic Attach. The agent can also be started at JVM startup time by use of the -Dcom.sun.management.jmxremote or the -Dcom.sun.management.snmp command line options on the java command.

The classes in java.lang.managment define a set of MBeans that are used to access information from the JVM and the operating system upon which it is running. These MBeans are registered with the Platform MBean Server when it is started.

The platform MBeans are implemented by classes in sun.management. These classes contain native methods that call functions defined in jmm.h to extract the required information from the JVM. jmm.h is implemented by the Java Virtual Machine.

See Monitoring and Management in HotSpot for more information.
See JMX- Java Management Extensions API for information about JMX.
up arrow

Dynamic Attach Mechanism

This is a Sun extension that allows a tool to 'attach' to another process running Java code and launch a JVM TI agent or a java.lang.instrument agent in that process. This also allows the system properties to be obtained from the target JVM.

The Sun implementation of this API also includes some HotSpot specific methods that allow additional information to be obtained from HotSpot:

See j2se/src/share/classes/sun/tools/attach/HotSpotVirtualMachine.java for more information.

Dynamic attach is used by jconsole jstack jmap jinfo
up arrow

Jvmstat Performance Counters

Hotspot exports the performance counters to a memory area that is mapped to a file. The jvmstat classes in the J2SE repository use java.io to read this data and make it available to callers. For examples of the use of the sun.jvmstat API, see:

This data is used by Dynamic Attach, jconsole, jps, jstat
up arrow

Serviceability Agent

Serviceability Agent components are built as part of the standard build of the HotSpot repository. These components are:

These two files are copied from the HotSpot build area to the JDK build area during a control build (a control build is a build of the control repository which first builds HotSpot and then builds the J2SE repository, so that the files built by the HotSpot build are available to the J2SE build.)

SA is used by jinfo, jmap, jstack

NOTE: The Serviceability Agent and the technologies that use it are not currently included in JDK releases on the Windows platforms.
up arrow

jconsole

JConsole uses dynamic attach to show monitorable Java processes, and to attach to them. It uses JMX to obtain information from a monitored JVM. Please see the jconsole tool page for more information on JConsole.
up arrow

jhat

jhat was derived from hat.java.net. The jhat source directory contains a build.xml file that can be used by ant to just build jhat.
up arrow

jinfo

jinfo uses dynamic attach for the -flag option and uses Serviceability Agent for the -flags and -sysprops options.
up arrow

jmap

jmap uses dynamic attach for the -dump and -histo options and Serviceability Agent for the other options. However, the -F option causes jmap to use SA for -dump and -histo also.
up arrow

jps

jps uses the jvmstat mechanism to obtain the list of monitorable Java processes.
up arrow

jcontrol

Note that the source for jcontrol is in the deploy respository instead of the J2SE repository.
up arrow

jsadebugd

jsadebugd is a Serviceability Agent 'server' that allows SA based tools to observe processes on remote machines. The code for jsadebugd resides in the HotSpot repository with the rest of the SA code. The J2SE repository just contains a makefile that creates the wrapper script that runs the sun.jvm.hotspot.jdi.SADebugServer class.
up arrow

jstack

jstack uses dynamic attach to print a non-mixed mode stack trace (ie, no native frames) and Serviceability Agent to do the rest.
up arrow

jstat

jstat (formerly jvmstat) is the primary user interface to the jvmstat performance counters. You can find the mapping between the options shown by 'jstat -options' and the names of the performance counters in the file j2se/src/share/classes/sun/tools/jstat/resources/jstat_options

jstat contains several unpublished features:

up arrow

jstatd

jstatd starts a server that allows jstat to access performance counters from a remote machine via Java Remote Method Invocation.
up arrow

Last Modified: 06/29/07