14

While debugging with jdb on the command line, it shows me a status line after each step that looks like this:

Step completed: "thread=main", [class name].[method], line=10 bci=20

What is bci and how can it be useful to me?

Anukool
  • 338
  • 3
  • 6

1 Answers1

20

It means byte code index . A single line, even a single Java statement, may translate to several bytecode instructions. The byte code index tells you which bytecode instruction was executed.

Madhawa Priyashantha
  • 9,633
  • 7
  • 33
  • 60
Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720
  • I don't quite understand, are you saying that each bci # maps to a specific bytecode instruction (i.e aaload)? Or are you saying that you can tell how many bytecode instructions were run for a certain statement by comparing the deltas between the last two steps? – coderrick Feb 16 '16 at 18:28
  • @coderrick: each bci maps to a specific bytecode instruction, and from what I can tell the index starts from 0 for each method, as displayed by the javap command. – Michael Borgwardt Feb 16 '16 at 20:54
  • Uhhh...I'm sorry but I still can't wrap my head around this. I need an example or a reference. What is instruction 0? When I look at the op-code (bci) reference on Oracle docs or Wikipedia I don't see the instructions in any order. Where can I find more information about this? – coderrick Feb 17 '16 at 00:19
  • @coderrick: Ahh, we have a misunderstanding. bci is an *index*. bci=0 is the first byte code instruction in a method, bci=1 is the second, etc. – Michael Borgwardt Feb 17 '16 at 08:26
  • Okay, but still where could I find more info about this in particular? In addition the jdb tool only has one Oracle doc page that only lists a couple of commands, so I just want few links so I can read up on it. – coderrick Feb 19 '16 at 18:01
  • @MichaelBorgwardt Hello, I am a newbie to java, may I ask, what can I do with this bci code? Or what did it tell me? Thank you – 时间只会一直走 Nov 12 '18 at 07:43
  • 2
    @时间只会一直走: it would only be relevant if you need to examine the behaviour of code at the level of individual bytecode instructions. Most Java programmers will never need this, probably only people who develop compilers or tools that manipulate bytecode do. – Michael Borgwardt Nov 12 '18 at 08:23
  • @MichaelBorgwardt I understand, thank you for your answer. – 时间只会一直走 Nov 12 '18 at 09:11