18

I am working on a bytecode manipulation/generation in Java and I was just wondering if there is an easy way I could check the bytecode. I do not want to decompile the file, I would like to actually look at the compiled bytecode. I do not need to edit it. Any links or programs for doing this would be acceptable answers.

informatik01
  • 15,174
  • 9
  • 67
  • 100
Popgalop
  • 717
  • 2
  • 9
  • 24

4 Answers4

48

Since you wanted to be guided to some program that can easily show you the byte code then my suggestion is to use IntelliJ IDEA since it has built-in support for viewing byte code.

Here's an example how to do it (it can also be mapped to some keys of your choice):

enter image description here

enter image description here

It is very easy, and it can surely be done in eclipse or NetBeans as well.

maba
  • 43,790
  • 10
  • 103
  • 113
  • where's line numbers? What are L0,L1.. mean ???? – voipp Aug 23 '15 at 15:57
  • Is this also available in Android studio? At least for classes compield for the JVM (like local Unit Tests etc). – Igor Čordaš Sep 16 '16 at 12:03
  • @PSIXO I don't know, I only use IntelliJ as-is. – maba Sep 16 '16 at 12:07
  • 1
    note that this requires the _ByteCode Viewer_ plugin – Ciprian Tomoiagă May 12 '17 at 15:33
  • 1
    @voipp `LINENUMBER 10 L2` means that the code on line number 10 is located at label `L2`. So `L0`, `L1` etc are labels, i.e. jump points in your program. In bytecode there are no functions or loops, there are only jumps (which can be conditional). So the whole program is a bunch of `IF this GO there_1; IF that GO there_2` – Ciprian Tomoiagă May 12 '17 at 15:39
  • `javap -c` outputs something completely different, something much simpler. Is there a way to view that as well? – Nearoo Mar 08 '18 at 17:16
6

Not sure what exactly you need, but apart from javap, which is a command-line tool for displaying the bytecode, you can take a look at javassist, asm and cglib - they allow you to parse the bytecode with java code.

Bozho
  • 554,002
  • 136
  • 1,025
  • 1,121
2

The javap command-line tool, which is bundled with Oracle's JDK, gives a detailed textual dump of .class files along with the constant pool and all functions' bytecode content. Just run it with -v to get a full dump.

Oak
  • 24,536
  • 5
  • 83
  • 146
  • but i want to see what the compiler reads when it reads the file so that i can create my own synthetic classes. – Popgalop May 27 '13 at 22:23
  • @Popgalop what the compiler reads in is the actual bytecode, which is not a textual format. I guess you could open it in a hex editor and use [this reference](http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html) to parse it by yourself, but if you want a human-readable dump, `javap -v` is the answer. – Oak May 28 '13 at 07:15
2

I've been working on a decompiler that has a color-coded bytecode output mode (which I find far more readable than javap). It can also output Java code or an intermediate 'bytecode AST'.

Mike Strobel
  • 23,622
  • 51
  • 65