Marcin K.
Marcin K.

Reputation: 843

What are const-class and const-method-type opcodes for? What java code generates them?

I'm creating a tool for post processing of dalvik applications. For tests I want to create code that will contain every opcode. I'm having problems understanding what const-class and const-method-type opcodes do. The definitions in dalvik's official documentation are not clarifying the issue for me.

const-class

Move a reference to the class specified by the given index into the specified register. In the case where the indicated type is primitive, this will store a reference to the primitive type's degenerate class.

What is reference to the class? This is not reference to an object as far as I know.

Same with

const-method-type

Move a reference to the method prototype specified by the given index into the specified register.

As far as I understand this is not function pointer. Function pointer is handled by

const-method-handle

Move a reference to the method handle specified by the given index into the specified register.

My question is:

What are const-class and const-method-type used for? What kind of java code would generate those opcodes in Dalvik?

Maybe it's worth mentioning that my java experience is rather low - I'm c++ kind of guy.

Upvotes: 1

Views: 318

Answers (1)

JesusFreke
JesusFreke

Reputation: 20282

const-class can be generated when you refer to a the class property of an object. e.g. Class cls = MyObject.class.

As far as I know, method handles and types aren't generated by java code. You can reference them using reflection, but I don't think doing so will actually generate the const-method-type or const-method-handle instructions

They are supporting cast for invoke-custom, which is primarily intended for use by other languages that get compiled to java bytecode and eventually dalvik bytecode.

Upvotes: 4

Related Questions