编译器优化:Java 字节码 [英] Compiler optimization: Java bytecode

查看:35
本文介绍了编译器优化:Java 字节码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写一个针对 Java 字节码翻译的玩具编译器.

I'm currently writing a toy compiler targeting Java bytecode in the translation.

我想知道在编写 .class 文件之前是否可以在发出的字节码中进行各种简单的窥视孔优化的某种目录(可能是摘要).我实际上知道一些具有此功能的库,但我想自己实现它.

I would like to know if there is some kind of catalog, maybe a summary, of various simple peephole optimizations that can be made in the emitted bytecode before writing the .class file. I actually am aware of some libraries that have this functionality, but I'd like to implement that myself.

推荐答案

你知道Proguard吗?http://proguard.sourceforge.net/

You are aware of Proguard? http://proguard.sourceforge.net/

这是一个很棒的字节码优化器,它实现了很多优化.有关列表,请参阅常见问题解答:http://proguard.sourceforge.net/FAQ.html

This is a great bytecode optimizer which implements a lot of optimizations. See the FAQ for a list: http://proguard.sourceforge.net/FAQ.html

  • 计算常量表达式.
  • 删除不必要的字段访问和方法来电.
  • 删除不必要的分支.
  • 删除不必要的比较和实例测试.
  • 删除未使用的代码块.
  • 合并相同的代码块.
  • 减少变量分配.
  • 移除只写字段和未使用的方法参数.
  • 内联常量字段,方法参数和返回值.
  • 内联方法很短或只有调用一次.
  • 简化尾递归来电.
  • 合并类和接口.
  • 将方法设为私有、静态和尽可能最终.
  • 制作课程尽可能静态和最终.
  • 替换具有单个的接口实施.
  • 表演超过 200窥视孔优化,例如将 ...*2 替换为 ...<<1.
  • 可选删除日志记录代码.

我相信您可以进一步查看源代码以了解它们是如何实现的.

I'm sure you can further look into the source code to understand how they are implemented.

这篇关于编译器优化:Java 字节码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆