What Java code will force javac 1.6 to use the "swap" and "nop" codes?

I am working on an amateur JVM implementation and I am trying to make sure that I have coverage for testing all opcodes in the specification. I got to the last, but nop and swap eluded me. For example, here is a simple function that can use swap :

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

But the bytecode created by javac 1.6 avoids the replacement instead 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 

Any ideas?

+7
java jvm bytecode javac opcode
Mar 15 '12 at 15:00
source share
1 answer

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

+6
Mar 15 2018-12-15T00:
source share
— -



All Articles