Question

I am trying to understand the java command jstack by going through the online document for jstack where it says:

jstack prints Java stack traces of Java threads for a given Java process or core file or a remote debug server. For each Java frame, the full class name, method name, 'bci' (byte code index) and line number, if available, are printed. With the -m option, jstack prints both Java and native frames of all threads along with the 'pc' (program counter). For each native frame, the closest native symbol to 'pc', if available, is printed. C++ mangled names are not demangled. To demangle C++ names, the output of this command may be piped to c++filt.

I have some doubts, please help me in understanding this command.

1) Is core file is just the name of the file where I want to print the stack trace or is it different? What is remote debug server here and how can we use it or configure?

2) What is Java Frame in this context and what is native frame of a thread?

3) I learnt about program counter earlier when I was learning microprocessors but is the same concept application for Java also?

4) What does it mean by closest native symbol to pc? Also how c++ is used in Java, I never came across c++ when I was learning Java.

Please clarify, Thanks in advance.

Était-ce utile?

La solution

  1. The core file is the core dump of a running (or formerly running) Java program, usually after it crashed or you killed it. jstack can either attach to a live, running program, or read from a core dump.

  2. A frame is the state associated with a function call. Every time you call a function, there is a new frame containing the local state of that function (e.g. local variables). Frames form a stack: Calling a function pushes a new frame onto the stack, and returning from a function pops that frame off the stack and you continue in the frame below, which belongs to the caller. The top frame holds the data to which the current point of execution of the program has direct access. Conceptually, frames are similar to "scopes" in block-structured programming languages.

  3. The Java Virtual Machine is a machine, too, and it has a program counter. It's just not one you can touch with your hands or spill coffee over.

  4. Because the JVM is virtual, it is actually executed by real machine code, which is called "native". So then you have the same entire consideration about frames and function calls and points of execution again for the native code.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top