Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Probing Java Methods with SystemTap

January 10, 2014
Lukas Berk

    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

    • Federated identity across the hybrid cloud using zero trust workload identity manager

    • Confidential virtual machine storage attack scenarios

    • Introducing virtualization platform autopilot

    • Integrate zero trust workload identity manager with Red Hat OpenShift GitOps

    • Best Practice Configuration and Tuning for Linux and Windows VMs

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    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
    © 2026 Red Hat

    Red Hat legal and privacy links

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

    Chat Support

    Please log in with your Red Hat account to access chat support.