Sign in to follow this  

Java VM specification question

This topic is 3592 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am reading Chapter 4 from the JVM specification which concerns classfile structure, and have a question regarding attributes. First of all I'm a little confused as to what purpose attributes serve to begin with, whereas I understand the purpose behind field and method access flags, etc. But beyond purpose, the specification seems to be a little ambiguous. It starts off by saying that all attributes have the following format:
// NOTE: u2 = 2 bytes unsigned, u4 = 4 bytes unsigned
attribute_info {
    u2 attrib_name_index;
    u4 attrib_length;
    u2 info[attrib_length];
}

However about two paragraphs later the specification begins describing a completely different struct format for the Exceptions attribute:
Exceptions_attribute {
    u2 attrib_name_index;
    u4 attrib_length;
    u2 number_of_exceptions;
    u2 exception_index_table[number_of_exceptions];
}

Beyond that there are about 8 other attributes, each of which has an entirely different format that the originally-proposed attribute_info struct... How do each of these specific variations of attributes (e.g. Exceptions, Code, ConstantValue) "tie in" with the attribute_info struct? And again what purpose do they serve for the JVM? Thanks for any help here, ply

Share this post


Link to post
Share on other sites
You'll notice that every attribute starts with the same two headers:

u2 attrib_name_index;
u4 attrib_length;

In the general attribute_info case the u2 info[attrib_length] acts as a placeholder for the rest of the attribute data for the individual attribute types.

Share this post


Link to post
Share on other sites

This topic is 3592 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this