2

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?

Ricardo Cristian Ramirez
  • 1,194
  • 3
  • 20
  • 42

1 Answers1

6

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

cyon
  • 9,340
  • 4
  • 22
  • 26
  • 1
    Here's the corresponding dalvik-specific info: http://s.android.com/tech/dalvik/dex-format.html – JesusFreke Sep 25 '13 at 20:30
  • @JesusFreke Can the low/high halves of a parameter register pair be separately addressed in the callee body? I have been unable to tell from the specs. – MEE May 02 '19 at 14:08
  • No, the values in the 2 registers cannot be separately referenced. e.g. if you have a wide value in v0 and v1, trying to pass either v0 or v1 to anything expecting a non-wide value is invalid. Or trying to pass v1 to something that expects a wide value will fail. – JesusFreke May 02 '19 at 18:07
  • You can still set either v0 or v1 to a different non-wide value. But in that case, the other half of the wide value becomes unusable. – JesusFreke May 02 '19 at 18:07