在Myeclipse下查看Java字節碼指令信息

     在實際項目開發中,有時爲了瞭解Java編譯器內部的一些工做,須要查看Java文件對應的具體的字節碼指令集,這裏提供兩種方式供參考。
1、使用javap命令
     javap是JDK提供的一個原生工具,它能夠反彙編class文件獲得對應的字節碼信息,經過調節命令參數,能夠獲取類的package、fileds和methods等的字節碼信息,用的最多的參數也就是-verbose了:
  
2、Bytecode Outline插件
      javap當然能夠實現反編譯字節碼的效果,可是每次都要在命令行中執行,顯得有點麻煩,並且經過反編譯生成的指令簡直就不是給人看的,基本看不懂。這裏推薦一款工具Bytecode Outline,它是專門爲Eclipse打造的反編譯插件,不只能夠查看反編譯生成字節碼指令集,還提供了全部指令的詳細說明。首先在Myeclipse安裝該插件須要知道Myeclipse對應的Eclipse版本號,能夠查看下面的文件獲取:
     D:\MyEclipse\MyEclipse 10\readme\readme_eclipse.html
    而後是下載安裝插件,這裏就不介紹了,若是是手動安裝,這裏提供插件下載地址: http://andrei.gmxhome.de/bytecode/links.html
關於插件的使用,官方文檔說的很清楚了,我就不翻譯了:
 
Usage:
1) Window -> Show View -> Other -> Java -> Bytecode

to see bytecode of current Java editor/ Class file view. The automatic build for projects should be enabled in order to see generated class files.html

If "Link with editor" is on, then any selection in Java editor will be followed with selection of appropriated bytecode label, and vice - versa.java

Note: this bi-directional selection could only works, if your bytecode contains source lines/local variables information. Check your compiler setings, if you are not sure that your compiler generates debug information.node

If "show raw bytecode" is off, than local variable names will be shown instead of indexes, full qualified names replaced with simply class names, and primitive type abbreviations decoded to readable names.web

If "show current element only" is on, then only bytecode of current field/method node will be shown (if cursor is placed inside field/method name or body).app

2.1) Select two *.class/*.java files -> right click -> Compare with -> Each Other Bytecodeless

2.2) Select one *.class/*.java file -> right click -> Compare with -> Another Class Bytecodeeclipse

to compare bytecode of selected class files. Compare works also for *.class files included in any referenced *.jar library.ide

"Toggle ASMifier mode on/off" button on both Bytecode Outline and Compare View shows ASMifier java code, that generates selected bytecode. More information about how to use ASMifier you can find here.工具

Note: if ASMifier mode is "on", then selection of java code cannot be folowed by selection of appropriated bytecode instruction, and vice - versa; the "show raw bytecode" action is also meaningless.ui

3) Window -> Show View -> Other -> Java -> Bytecode reference

to see reference documentation to selected bytecode instruction in the bytecode view. This documentation is taken from "Java Virtual Machine" by Jon Meyer & Troy Downing Copyright (c) 1997 by O'Reilly & Associates, and provided with permission of O'Reilly Media, Inc. Packaging, cleanup, reformatting and XSL transformation completed by Eugene Kuleshov (eu@javatx.org).

4) Help -> Help contents -> JVM Instruction Reference

to see the entire bytecode reference documentation, provided with BCO plugin.
 
最後的效果以下所示:
相關文章
相關標籤/搜索