Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to see JVM opcodes from class file? [duplicate]

Tags:

java

This is actually not about decompiling, I don't want to see the source, instead I want to see JVM instructions like invoke some/package/method()V.

Is there a tool for this purpose?

like image 602
Ricardo Cristian Ramirez Avatar asked Aug 22 '14 08:08

Ricardo Cristian Ramirez


People also ask

What is opcodes in Java?

A Java Virtual Machine instruction consists of an opcode specifying the operation to be performed, followed by zero or more operands embodying values to be operated upon. This chapter gives details about the format of each Java Virtual Machine instruction and the operation it performs.

How do I find bytecode?

Open the necessary . class file in the editor in IntelliJ IDEA and then select View | Show Bytecode from the main menu.

Is .class file a bytecode?

The . class file is the byte-code. It is the result of compiling java source code (text) into the intermediate format, byte-code. The byte-code is then interpreted by the JVM and compiled into a language understandable by your CPU.


2 Answers

suppose you have a class file named MyClass.class

you can easily see what JVM instructions constitute your classfile by using a program shipped by jdk itself,in the same bin directory where java and javac exist.

 javap -c MyClass.class

The above command will provide you with what you be be looking for.

like image 103
Abhishek Avatar answered Sep 28 '22 09:09

Abhishek


I am using Eclipse + Bytecode Outline plugin for Eclipse http://andrei.gmxhome.de/bytecode/index.html. THis is how bytecode looks like

  public static main([Ljava/lang/String;)V throws java/io/IOException 
   L0
    LINENUMBER 11 L0
    INVOKESTATIC test/Test.x ()V
   L1
    LINENUMBER 12 L1
    RETURN
...
like image 39
Evgeniy Dorofeev Avatar answered Sep 28 '22 10:09

Evgeniy Dorofeev