简体   繁体   English

有什么命令可以获取Java代码编译的中间文件吗?

[英]Are there any commands to get the intermediate files of Compilation for Java Code?

Similar to C or C++ where you can get the intermediate files are there any commands to get same for Java Code?类似于 C 或 C++,您可以在其中获取中间文件,是否有任何命令可以为 Java 代码获取相同的文件?

For example, C file can generate,例如,C文件可以生成,

Preprocessed File (Hello.i)
Compilation file (Hello.s)
Assembly File (Hello.o)
Executable File through Linker (Hello.exe)

In java we do,在 Java 中,我们这样做,

Executing --> Filename.java
we obtain --> Filename.class

and then we run this class file for output.然后我们运行这个类文件进行输出。

Is there a way to generate Preprocessed, compiled and assembly files for Java code?有没有办法为 Java 代码生成预处理、编译和汇编文件?

No. The Java compiler generates bytecode (contained in .class ), there are no intermediary steps.不会。Java 编译器生成字节码(包含在.class中),没有中间步骤。

The JIT compiler(s) then generate assembly and machine code, and those can be seen with suitable flags given while running the program . JIT 编译器随后生成汇编代码和机器代码,在运行程序时可以通过给出适当的标志来查看这些代码。

The .class file is already an 'intermediate' file. .class文件已经是一个“中间”文件。 The Java Virtual Machine then takes this and executes it (interpreting or compiling as it sees fit, often both!)然后 Java 虚拟机接受它并执行它(解释或编译它认为合适的,通常两者兼而有之!)

If the class file is not obfuscated , you can easily disassemble the contents with a decompiler, as all/most symbols are preserved ( like debug symbols in C/C++).如果类文件未被混淆,您可以使用反编译器轻松反汇编内容,因为所有/大多数符号都被保留(如 C/C++ 中的调试符号)。 Some IDEs allow you to open a.class file and see the disassembled code (IntelliJ and NetBeans come to mind)一些 IDE 允许您打开一个 .class 文件并查看反汇编代码(想到 IntelliJ 和 NetBeans)

IntelliJ shows the decompiled code as if you're looking at a regular.java file, although with no comments and sometimes 1-letter variables. IntelliJ 显示反编译的代码,就像您正在查看 regular.java 文件一样,尽管没有注释,有时只有 1 个字母的变量。 You can view the bytecode (disassembly) using a menu option (even of your own source code as long as it's compiled).您可以使用菜单选项查看字节码(反汇编)(即使是您自己的源代码,只要它已编译)。

NetBeans shows it, afaik, only as byte code, but still grouped by method. NetBeans 仅将其显示为字节代码,但仍按方法分组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM