Question

In the DVM source code you can see methodIdx used as Method ID in a lot of functions. This attribute isn't in the Method Class and I didin't find a good description about it.

So my question is, is an absolut identifier, it's allways the same for a process, can change, when can change, etc... And how or where is generated.

Thanks

Was it helpful?

Solution

methodIdx is generally the "method reference index".

It's an index into the method_ids table, described in the file format docs. The index is relative to a single DEX file, which is why functions like dvmResolveMethod() take the referring class as well as the method reference index. It's mentioned in the invoke-kind explanation in the Dalvik bytecode doc.

Each method_id_item identifies a method by the class in which it was defined, and the function's prototype (name, arguments, return type). There is one method_id_item for every method declared in or referenced from a DEX file. The indices are established when the DEX file is generated by dx.

So... methodIdx gets you to a table entry with a bunch of strings. From there a symbolic lookup gets you to the actual method implementation, i.e. Method*. See dvmResolveMethod() in dalvik/vm/oo/Resolve.cpp for the details.

Because the invoke instructions only have room for a 16-bit method reference index, you can't refer to more than 65535 methods in a single DEX file. (This is a well known problem.)

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