Skip to main content
session.jvm is a JVMSessionProxy — available on every NSPSession attached to a Java application. It provides direct, runtime-level access to the JVM through JVMTI and JNI: read static and instance fields, invoke methods, and enumerate loaded classes — all without modifying the target application or adding any Java code.

When to Use session.jvm

The high-level state on session.state reflects the semantic model that the NSP JVM probe has already extracted. session.jvm lets you reach below that model to read raw Java fields and call arbitrary methods that are not yet surfaced in the semantic layer.
  • Start with session.get_int(...), session.get_str(...), etc. for values already in the semantic state.
  • Use session.jvm when you need internal Java fields, collection contents, or method return values not present in the semantic model.
JVM probe attachment via JVMTI takes longer on first connect than CLR or v8 probes — typically 2–15 seconds. If you call session.jvm methods immediately after client.attach(), you may receive NSPActionError with code jvm_not_attached. Wait for session.confidence >= 0.85 or use client.attach("AppName", fresh=True) to ensure the probe is ready before issuing JVM calls.

Prerequisites

read_field(class_name, field_name, *, timeout_ms)

Read the value of a static or instance field from a loaded Java class.
class_name
str
required
The fully-qualified Java class name, e.g. "com.ardupilot.GCS". Use dots as separators (not slashes).
field_name
str
required
Field name, case-sensitive, exactly as declared in the Java source.
timeout_ms
int
default:"10000"
Maximum time in milliseconds to wait for the JVMTI agent to respond.
Python types returned by read_field():

invoke(class_name, method_name, args, *, timeout_ms)

Invoke a Java method by name and return its result. Arguments are automatically coerced to the JVM types expected by the method’s signature.
class_name
str
required
Fully-qualified Java class name.
method_name
str
required
Method name, case-sensitive.
args
list[Any]
default:"None"
Positional arguments. Each value is coerced to the JVM type expected by the method signature.
timeout_ms
int
default:"10000"
Maximum time to wait for the method to return.

Type Coercion Reference

list_classes(*, prefix, timeout_ms)

Enumerate all classes currently loaded in the JVM, optionally filtered to a package prefix.
prefix
str
default:"\"\""
Return only classes whose fully-qualified name starts with this prefix.
timeout_ms
int
default:"10000"
Maximum time to wait for the class enumeration.
Use list_classes() once during development to discover the exact class names and field spellings you need. Once you have them, use read_field() and invoke() in production code — list_classes() is slower than targeted field reads.

Error Reference

Full Example: ArduPilot GCS Telemetry Monitor