0

I understand that .class files contain line numbers associated to the byte code in order to facilitate the job of debuggers as described here.

I also understand that each thread has its own pc Register which points at the next instruction, as described here. By using these registers, debuggers are able to, for instance, stop at specific lines, by associating the instruction to the line number.

I also understand that Java threads are bound to OS threads, which are executed as native code.

However, the description of pc Registers says that

If the method currently being executed by the thread is native, the value of the Java Virtual Machine's pc register is undefined.

The question then is: if debuggers use line numbers associated with byte code instructions, and pc registers inform the next instruction, how is it possible (in case it actually is) to debug thread code if it is executed as native code and because of that pc registers values are undefined?

What am I getting wrong?

Felipe Martins Melo
  • 1,323
  • 11
  • 15
  • I think that the paragraph you quoted is about `native` methods, whose implementation is not managed by JVM (because it is written in some other language) and is not subject to Java debugger. Do not confuse "native method" with "native thread". – Danila Kiver Jul 16 '19 at 17:08
  • @DanilaKiver, but then how can a native thread execute a code that is non-native, i.e. JVM bytecode? Also, doesn't a native thread run native code? – Felipe Martins Melo Jul 16 '19 at 19:32
  • 2
    The interpreter *is* native code. Also, the JIT compiler produces native code, but code which it can retrace to its originating bytecode (in most cases). When not executing methods declared `native`, the native threads execute either, the interpreter code or JIT compiled code. – Holger Jul 17 '19 at 15:52

0 Answers0