Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Probing Java Methods with SystemTap

January 10, 2014
Lukas Berk

Share:

    Today we'll be looking at systemtap's latest native java probing capabilities.
    These go beyond systemtap's existing hotspot-based probe points to actual entry,
    exit, and line number specific to the relevant java method.  This allows for pinpoint probing of a java application, without the need to place probes on the underlying JVM itself.

    How to install (if running RHEL 7 Beta)

    # yum install systemtap systemtap-runtime-java

    Basic Usage

    How do I use systemtap to probe a java method?

    Below we have a simple threaded java program, which waits for our input on the command line.  Given the input 'int' or 'long', the program will print out a predetermined
    variable (that we would like to know the value).

    package foo.bar;
    
    import java.lang.*;
    import java.io.DataInputStream;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    
    class ThreadedExample
    {
    
        public static void printMessage(int message)
        {
        System.out.println("message: " + message);
        }
    
        public static void printMessage(long message)
        {
        System.out.println("message: " + message);
        }
    
        public static void main(String[] args)
        {
        try
            {
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            String next = in.readLine();
            while(next != null && next.length() > 0 && !next.contains("end"))
                {
                final String arg = next;
                final int i = 42;
                final long j = 987234864;
                Thread thread = new Thread(arg)
                    {
                    public void run()
                    {
                        if(arg.equals("int"))
                            printMessage(i);
                        else if(arg.equals("long"))
                             printMessage(j);
                        else
                        System.out.println("Neither of the types");
                    }
                    };
                thread.start();
                try
                    {
                    thread.join();
                    } catch (Exception e){}
                next = in.readLine();
                }
            } catch (Exception e){}
        }
    }

    compile and run the java program in the typical way;

    lberk:]$ javac foo/bar/ThreadedExample.java
    lberk:]$ java foo.bar.ThreadedExample
    int
    message: 42
    test
    Neither of the types
    long
    message: 987234864

    Good, now to run a systemtap script which will probe both printMessage methods
    and display the parameter passed.

    Java probe points in systemtap follow the basic syntax of
    probe java("PNAME").class("CLASS").method("METHOD") { handler }

    where PNAME is either the string of the java program as listed by jps -l or the
    specific PID of the java program.  It should be noted that the java program must
    be already running at the time of script invocation.  The CLASS parameter is the
    fully qualified class, and the METHOD parameter is the method name with parameter
    types.

    An example of a systemtap script written for ThreadedExample.java is below:

    ThreadExample.stp

    #!/usr/bin/env stap
    probe java("foo.bar.ThreadedExample").class("ThreadedExample").method("printMessage(int)")
    {
        printf("Hit printMessage(int): %dn", $arg1)
    }
    probe java("foo.bar.ThreadedExample").class("ThreadedExample").method("printMessage(long)")
    {
        printf("Hit printMessage(long): %dn", $arg1)
    }

    Running the systemtap script in another terminal (and specifying "int", "long" respectively);

    lberk:]$ stap ThreadedExample.stp
    
    Hit printMessage(int): 42                                          
    Hit printMessage(long): 987234864

    JBoss-EAP Example

    A common method for running java programs is on an application server.  One of the popular choices is JBoss, and Systemtap is able to probe java methods running on JBoss as well!

    This example will use the JBoss Enterprise Application Platform, using the helloworld example which can be obtained by running:

    git clone git://github.com/jboss-jdf/jboss-as-quickstart.git --branch jdf-2.1.2.Final

    In order to probe a standalone server, we need to ensure both the byteman and systemtap packages are visible for the target's class loaders.  We can do this by either editing the configuration file directly, or by modifying the environment variable on server startup to list org.jboss.byteman and org.systemtap.byteman.helper package in the
    JBOSS_MODULES_SYSTEM_PKGS option.  For our example we've launched the startup server using the environment variable.

    lberk:]$ JBOSS_MODULES_SYSTEM_PKGS="org.jboss.byteman,org.systemtap.byteman.helper" $HOME/jboss-as-user-instance/bin/standalone.sh

    We then deploy the helloworld example by running the following command in the
    jboss-as-quickstart/helloworld directory:

    lberk:]$ mvn clean package jboss-as:deploy

    At this point, we have a running hello world example that displays a "Hello World!" at
    http://localhost:8080/jboss-as-helloworld/HelloWorld

    We can tell when this web page is requested, and how many times by writing a simple
    systemtap script that targets the "doGet" method.

    stap jboss-example.stp
    ----------------------

    #!/usr/bin/env stap
    global counter
    
    probe
    
    java("/usr/share/jbossas/jboss-modules.jar").class("org.jboss.as.quickstarts.helloworld.HelloWorldServlet").method("doGet")
    {
        counter++
        printf("%s, %dn", ctime(gettimeofday_s()), counter)
    }

    This will provide output similar to the following for each webpage request:

    Mon Jun 17 02:37:05 2013, 1
    Mon Jun 17 02:37:06 2013, 2
    Mon Jun 17 02:37:07 2013, 3
    Mon Jun 17 02:37:08 2013, 4
    Mon Jun 17 02:37:08 2013, 5
    Mon Jun 17 02:37:09 2013, 6
    Mon Jun 17 02:37:09 2013, 7

    Recent Posts

    • Why some agentic AI developers are moving code from Python to Rust

    • Confidential VMs: The core of confidential containers

    • Benchmarking with GuideLLM in air-gapped OpenShift clusters

    • Run Qwen3-Next on vLLM with Red Hat AI: A step-by-step guide

    • How to implement observability with Python and Llama Stack

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue