1

Possible Duplicate:
Is it possible to view bytecode of Class file?

I wanted to write some Java in eclipse, compile and then look at the resultant "assembly language" to see which code compiles to the fewest "instructions". I realise Java is different to C++, but is it possible to study some output from the compilation and compare to check for fastest code?

Community
  • 1
  • 1
user997112
  • 29,025
  • 43
  • 182
  • 361
  • 3
    Bear in mind that "fewest instructions" != "fastest", and that the JIT will play a large role in what is *ultimately* fastest. Profiling is the best way to determine what's *fastest* under actual application execution. – Dave Newton Nov 25 '11 at 19:53

4 Answers4

2

You can look at the bytecode with the javap command.
But you must take into account, that the JVM performs JIT. Which means that depending on several things including command line arguments and runtime statistics, it will optimize the code on the fly.

zeller
  • 4,904
  • 2
  • 22
  • 40
1

Check out javap.

jdouglas71
  • 21
  • 3
0

The Java toolset comes with the Java class file disassembler, which you can use to du just that.

rsp
  • 23,135
  • 6
  • 55
  • 69
0

You have to look at the bytecode produced by the compilation, exist an eclipse plugin (Bytecode Outline) that let you view the bytecode directly in eclipse.

aleroot
  • 71,077
  • 30
  • 176
  • 213