什么Java代码会强制javac 1.6使用'swap'和'nop'操作码? [英] What Java code will force javac 1.6 to use the 'swap' and 'nop' opcodes?

查看:195
本文介绍了什么Java代码会强制javac 1.6使用'swap'和'nop'操作码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在进行业余JVM实现,我正在努力确保我对规范中的所有操作码都有测试覆盖率。我已经把它归结为最后几个,但是 nop swap 一直在逃避我。例如,这是一个简单的函数,可能使用 swap

I'm working on an amateur JVM implementation, and I'm trying to make sure I have test coverage for all of the opcodes in the spec. I've gotten it down to the last few, but nop and swap have been eluding me. For example, here's a simple function that might use swap:

static int do_swap() {
  int a = 56;
  int b = 32;
  return b%a;
}

javac 1.6生成的字节码避免交换代替本地存储:

But the bytecode produced by javac 1.6 avoids swapping in lieu of local storage:

static int do_swap();
  Code:
   0:   bipush  56
   2:   istore_0
   3:   bipush  32
   5:   istore_1
   6:   iload_1
   7:   iload_0
   8:   irem
   9:   ireturn

任何想法?

推荐答案

无。 Java语言规范不提供此类保证。您可以使用 Jasmin (字节码汇编程序)编写自己的Java字节码。

None. The Java Language Specification does not provide such guarantees. You can just write your own Java bytecode using Jasmin (a bytecode assembler).

这篇关于什么Java代码会强制javac 1.6使用'swap'和'nop'操作码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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