for 循环在编译的类文件中转换为 do while 循环

发布于 2025-01-08 17:25:08 字数 207 浏览 4 评论 0原文

在我的团队中,我们使用的是 java 1.4.2 大部分机器的 for 循环都是按照 only.ie 进行编译的。如果我反编译类文件,我只能看到 for 循环,但某些开发人员的某些机器上它会变成 do while 循环。即当我反编译某些类时,它会变成 do,而

它怎么会发生?任何可能的原因,任何人都可以想到的java版本或配置,这样我就可以重现这个缺陷并在所有开发人员的机器上修复它

In my team we are using java 1.4.2 Most of the machine for loop is getting compiled as for only.ie. if i decompile the class file I can get see for loop only but certain machines of certain developer's it becomes do while loop. ie when i decompile certain classes it becomes do while

How can it happen? Any possible reason, java version or configuration any body can think so i can reproduce this defect and fix it in all developers machines

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

ㄖ落Θ余辉 2025-01-15 17:25:08

我不会称其为缺陷。将 Java 编译为字节码时,一些信息会丢失。当您随后反编译字节码时,无法保证生成的 Java 源代码与您开始时的代码非常匹配。

特别是,字节码语言对于不同类型的循环没有具体的指令。 Java 循环被编译成使用比较指令和跳转的字节码。在决定使用哪种类型的循环来生成给定的字节码时,反编译器必须做出有根据的猜测。

不同机器之间的行为差​​异可能与这些机器上安装的编译器和反编译器的确切版本的差异有关,或者可能与这些工具的配置方式有关。

I would not call this a defect. When you compile Java to bytecodes, some information is lost. When you subsequently decompile the bytecodes, there is no guarantee that the resulting Java source will closely match what you've started with.

In particular, the bytecode language has no specific instructions for different types of loop. Java loops get compiled into bytecodes that use comparison instructions and jumps. The decompiler has to make an educated guess when deciding which type of loop was used to produce the given bytecodes.

The difference in behaviour across machines probably has to do with differences in the exact versions of the compiler and the decompiler installed on those machines, or perhaps with how those tools are configured.

或十年 2025-01-15 17:25:08

whilefor 的代码是可以互换的,并且无法从字节码中判断使用了哪一个(您可以推断出来)您无法重现注释字节码,您无法可靠地区分 for 和 while 循环之间的区别。

例如

while(condition)

for(;condition;)

while(true) {
   if(!condition) break;

}

是相同的。

The code for while and for are interchangable and there is no way to tell from the byte code which one was used (you could infer it) You can't reproduce comments from byte code and you cannot reliably tell the different between a for and while loop.

e.g.

while(condition)

and

for(;condition;)

and

while(true) {
   if(!condition) break;

}

are the same.

倾听心声的旋律 2025-01-15 17:25:08

在字节码中,没有循环,只有条件和无条件跳转(又名 goto)。因此,反编译器会尽力重建基于跳转结构的循环。

In the bytecode, there are no loops, there are only conditional and unconditional jumps (aka gotos). So the decompiler does its best to reconstruct what loop that was based on jumps' structure.

開玄 2025-01-15 17:25:08

编译器优化永远不会改变代码的实际用途。

即使不同的编译器对代码进行不同的优化,程序的语义也永远不会有任何差异:用户将始终得到相同的结果。

这不是需要修复的错误。没有解决办法。没有错误。

Compiler optimizations will never change what the code actually does.

Even if different compilers are making different optimizations to your code, there will never be any difference in the program's semantics: the user will always get the same results.

This is not a bug in need of a fix. There is no fix. There is no bug.

铁轨上的流浪者 2025-01-15 17:25:08

这可能是由编译器的优化设置引起的。检查不同机器上的优化设置。尝试禁用所有优化或等于优化级别。

it's probably caused by the compiler's optimization settings. check optimization settings on different machines. try to disable all optimizations or equal the optimization level.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文