Question

Dalvik operation for Thread.sleep(100); is produced like below:

invoke-static {v2, v3}, Ljava/lang/Thread;.sleep:(J)V

It's a static method and takes one argument but two given: v2 and v3. Isn't it strange? Does anyone have an idea about this situation?

Was it helpful?

Solution

No, it only takes one argument which is a long. However the long is passed using two registers v2 and v3. This is due to the fact that a long is a 64 bit value and thus it needs to be represented by two registers on Dalvik which considers registers to be 32 bit wide. The Dalvik VM technical guide mentions this in the bytecode format guide:

When used for bit values (such as integers and floating point numbers), registers are considered 32 bits wide. Adjacent register pairs are used for 64-bit values. There is no alignment requirement for register pairs.

You can tell that the static method is taking a long argument from the method signature. The (J)V means it is a method that takes a long parameter (J) and returns void (V).

To read more about method descriptors have a look at the JVM specification, specifically section-4.3.3 and section-4.3.2

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top