Skip to content
Advertisement

Tag: jvm-bytecode

What is the use of the “dup2_x2” instruction in JVM bytecode?

Java has a dup2_x2 instruction which, according to the documentation, has the following behavior: Duplicate the top one or two values on the operand stack and insert the duplicated values, in the original order, into the operand stack. Does javac produce bytecode with this instruction? What are its potential use cases? Answer For example, the following code compiles to See,

I don’t understand this opcode in JVM Implementation

I am writing a JVM. I was implementing all opcodes one by one, until I faced dup2. The oracle instruction set https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.dup2 says Duplicate the top one or two values on the operand stack and push the duplicated value or values back onto the operand stack in the original order How am I supposed to choose which operation to perform?

short -> int -> long type promotion: is there any overhead?

If, for example, I define method’s return type/parameter as char, but both the caller and implementation actually immediately use it as an int, is there any overhead? If I understand correctly, the values on the stack are 32-bits aligned anyway, as are the ‘registers’ (I’m sorry, I’m not well versed in the byte code). A word of explanation: I am

Advertisement