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

查看:207
本文介绍了编译器优化: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


  • 评估常数表达式。

  • 删除不必要的字段访问和方法
    调用。 / li>
  • 删除不必要的分支。

  • 删除不必要的比较和
    instanceof测试。

  • 删除未使用的代码

  • 合并相同的代码块。

  • 减少变量分配。

  • 删除
    只写字段和未使用的方法
    参数。

  • 内联常数字段,
    方法参数和返回值。

  • 简短或仅
    调用一次。

  • 简化尾递归
    调用。

  • 合并类和接口。

  • 尽可能使方法为private,static和
    final。

  • 在可能的情况下创建类
    static和final。

  • 替换具有单个
    实现的接口。

  • 执行超过200
    个窥视孔优化,例如
    替换... * 2由...<< 1。

  • (可选)
    删除日志记录代码。

  • Evaluate constant expressions.
  • Remove unnecessary field accesses and method calls.
  • Remove unnecessary branches.
  • Remove unnecessary comparisons and instanceof tests.
  • Remove unused code blocks.
  • Merge identical code blocks.
  • Reduce variable allocation.
  • Remove write-only fields and unused method parameters.
  • Inline constant fields, method parameters, and return values.
  • Inline methods that are short or only called once.
  • Simplify tail recursion calls.
  • Merge classes and interfaces.
  • Make methods private, static, and final when possible.
  • Make classes static and final when possible.
  • Replace interfaces that have single implementations.
  • Perform over 200 peephole optimizations, like replacing ...*2 by ...<<1.
  • Optionally remove logging code.

请查看源代码以了解如何实现它们。

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

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

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