JVM-class index, parent index and index set, and jvm-class index set

Source: Internet
Author: User

JVM-class index, parent index and index set, and jvm-class index set
Class index, parent class index and interface index set the class file is introduced before, starting from scratch magic number, minor version number, main version number, constant pool entry, constant pool, access flag. the next step is the class index used to determine the inheritance relationship of this class. The parent class index and interface index set are three items.

Let's take a look at these three items.

Both this_class and super_class are of the u2 type, while interfaces is a set of u2 data, the three data items in the class file determine the inheritance relationship of the class.

The class index is used to determine the full qualified name of the class, and the parent class index is used to determine the full qualified name of the class's parent class. the interface index set describes the interfaces implemented by this class. These Implemented interfaces are arranged from left to right in the interface index set following the implements statement.

The parent index and interface are arranged in sequence after the access flag. The class index and parent index are represented by two u2 index values, each of them points to a class description constant of the CONSTANT_Class_info type. The fully qualified name string defined in the constant of the CONCTANT_Class_info type can be found through the index value in the constant of the CONCTANT_Class_info type.

For the interface index set, the first entry of the u2 type data is the interface counter (interface_count), which indicates the index table capacity. if this class does not implement any interface, the counter value is 0, and the index table of the subsequent interface no longer occupies any bytes.

Next we will continue with the class file analyzed above, and continue to analyze the above three items:

Class file and analysis:

 

Now let's take these values and check the content of the constant pool when we use the javap tool to analyze the constant pool when introducing the constant pool to verify whether it is correct.

  

 

Because 0x00 03 and 0x00 04 hexadecimal correspond to 3 and 4 in decimal format, the class index and the parent class index correspond to the third and fourth constant pools. the third and fourth constant pools correspond to TestClass and Object classes respectively. Let's look at the source code and we will know that the result is correct. (Because my class name is TestClass, it does not show that it inherits any class, that is, it inherits the Object parent class by default)

Source code:

 

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.