首页 > java > 什么是const-class和const-method-type操作码?什么java代码生成它们?

什么是const-class和const-method-type操作码?什么java代码生成它们? (What are const-class and const-method-type opcodes for? What java code generates them?)

问题

我正在创建一个用于dalvik应用程序后期处理的工具。对于测试,我想创建包含每个操作码的代码。我在理解const-class和const-method-type操作码的作用时遇到了问题。dalvik官方文档中的定义并没有为我澄清问题。

常量级

将对给定索引指定的类的引用移动到指定的寄存器中。在指示的类型是原始的情况下,这将存储对原始类型的简并类的引用。

什么是班级?据我所知,这不是对象的引用。

与...相同

常量法型

将对给定索引指定的方法原型的引用移动到指定的寄存器中。

据我所知,这不是函数指针。函数指针由。处理

常量-方法手柄

将对给定索引指定的方法句柄的引用移动到指定的寄存器中。

我的问题是:

什么是const-class和const-method-type用于?什么样的Java代码会在Dalvik中生成那些操作码?

也许值得一提的是我的java经验相当低 - 我是c ++那种人。

解决方法

const-class可以在引用对象的class属性时生成。例如Class cls = MyObject.class

据我所知,方法句柄和类型不是由java代码生成的。您可以使用反射来引用它们,但我不认为这样做会实际生成const-method-typeconst-method-handle指令

它们支持强制转换invoke-custom,主要用于被编译为java字节码并最终编译为dalvik字节码的其他语言。

问题

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.

解决方法

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.

相似信息