避免使用getfield操作码 [英] Avoiding getfield opcode

查看:160
本文介绍了避免使用getfield操作码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java的String类中, trim 方法包含:

In Java's String class, the trim method contains this:

int off = offset;      /* avoid getfield opcode */
char[] val = value;    /* avoid getfield opcode */

我对评论有点困惑 getfield操作码 ...

这是什么意思? (我认为这可以避免在字节码中使用 getfield ,但为什么这是一个好东西[TM]?)

What does this mean? (I take it this avoids the use of getfield in the bytecode but why is this a Good Thing [TM]?)

是不是如果 trim 没有做任何事情(因此返回这个)或者?

Is it to prevent object creation in case trim doesn't do anything (and hence this is returned) or?

推荐答案

我的 guess 的意思是将值复制到局部变量一次,以避免在循环的每次迭代中不得不从堆中重复获取字段值在接下来的几行中。

My guess is that the point is to copy the values into local variables once, to avoid having to fetch the field value repeatedly from the heap for each iteration of the loop in the next few lines.

当然,这引出了为什么同样的评论没有应用于len局部变量的问题。 (我还希望JIT无论如何都要避免重新获取,特别是因为变量是最终的。)

Of course, that begs the question as to why the same comment hasn't been applied on the "len" local variable. (I'd also expect the JIT to avoid refetching anyway, especially as the variables are final.)

这篇关于避免使用getfield操作码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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