Skip to content
Advertisement

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?

Advertisement

Answer

For example, the following code

JavaScript

compiles to

JavaScript

See, demo on Ideone

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement