How to use jmap remotelly without SSL?

1.7k views Asked by At

I've configured my linux remote machine (with JRE 1.7) to execute the java application with the necessary properties for jmx:

java -Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=5005 \
-Dcom.sun.management.jmxremote.local.only=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-jar myapplication.jar

Now in my windows local machine (where I have JDK 1.7) I want to use the tool jmap, for example to print the histogram:

jmap -histo 10.218.72.227:5005

But it's faling with the following error:

Picked up _JAVA_OPTIONS: -Djava.net.preferIPv4Stack=true
Attaching to remote server 10.218.72.227:5005, please wait...
Error attaching to remote server: java.rmi.NotBoundException: Not bound: "SARemoteDebugger" (only bound name is "jmxrmi")

The weird thing is that I can connect using the jconsole successfully, but first it prompts me with a message to Retry the connection insecurely (without SSL):

enter image description here

Therefore, it seems like it should be some sort-of a flag for jmap in order to work, do you know how to overcome this problem?

1

There are 1 answers

0
SubOptimal On

Following the man page of jsadebugd - Serviceability Agent Debug Daemon you need first to attach it to your process to be able to use jmap remotely.

The below steps show how it works.

The used Java version for all java processes (local and remote).

java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) Server VM (build 24.80-b11, mixed mode)

execute on remote host

  1. start your application
    java -jar myapplication.jar
  2. start the rmiregistry
    rmiregistry -J-Xbootclasspath/p:$JAVA_HOME/lib/sajdi.jar &
  3. get the PID of your application using jps (e.g.12345)
  4. attach the debug demon to your application
    jsadebugd 12345 42

execute on local host

  1. execute jmap
    jmap -heap [email protected]

output on local host

Attaching to remote server [email protected], please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.80-b11
Iterating over heap. This may take a while...
Object Histogram:

num       #instances    #bytes  Class description
--------------------------------------------------------------------------
1:      5575    527488  * ConstMethodKlass
2:      5575    493168  * MethodKlass
...

Additional notes: The man page states This utility is unsupported and may or may not be available in future versions of the JDK.

Maybe running jmap on the remote machine (e.g. via ssh) would be a better approach.