Search code examples
jvmbytecode.class-filejvm-bytecode

How can I distinguish attribute_info in JVM ClassFile?


I'm digging into The ClassFile Structure.

According to the document mentioned above, attribute_info can be appeared in various position.

My question is how can I distinguish the type of attribute_infos?

I know I can distinguish constant_infos by their tags.

And How can I distinguish attribute_infos?

All attribute_info look like this.

attribute_info {
    u2 attribute_name_index;
    u4 attribute_length;
    u1 info[attribute_length];
}

And Fields seems have attribute_info of ConstantValue, Synthetic, and so on.

How can I distinguish their types?


Solution

  • I got it.

    The constant_pool entry at attribute_name_index must be a CONSTANT_Utf8_info structure (§4.4.7) representing the name of the attribute.