Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the class index, parent index, and interface index set of Class files in the JVM virtual machine?

2025-02-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you what the class index, parent class index and interface index set of Class files in JVM virtual machine are. The content is concise and easy to understand. It will definitely make you shine. I hope you can gain something through the detailed introduction of this article.

I. Overview

The class file was introduced earlier, including magic numbers, minor version numbers, major version numbers, constant pools, and access flags. The next three items are the class index, the superclass index, and the interfaces index set, which determine the inheritance relationship of the class.

The class index, the parent index, and the interface index set are arranged sequentially after the access token, the class index being used to determine the fully qualified name of the class, and the parent index being used to determine the fully qualified name of the parent of the class. Since the Java language does not allow multiple inheritance, there is only one parent class index. Except java.lang.Object, all Java classes have parent classes, so except Object, all Java classes have parent class indexes other than 0.

II. Detailed Description

The class index and parent class index are both data of type u2, each pointing to a constant of type CONSTANTClassinfo. The fully qualified name string defined in the constant of type CONSTANTClassinfo can be found by the index value in the constant of type CONSTANTClassinfo.

The interface index set is used to describe which interfaces this class implements. It is a collection of data of type u2. The first item in the collection is the interface counter, which indicates the capacity of the index table. If a class does not implement any interfaces, the counter value is 0.

The index location is shown in the following figure:

III. Case Study

New Interface:

public interface HelloWord {}

Here the class index value is 0x0001, which points to the first item in the constant pool. Looking up the constant pool shows that the fully qualified name of this class is com/csdn/reader/HelloWord.

The two bytes after the class index are the parent class index. As above, the parent class index is 0x0002, corresponding to the second item in the constant pool:

Because the number of interfaces implemented by a class is uncertain, the first part of the description of the interface index set is called the interface counter (interfaces_count). The interface counter takes up two bytes, and the value indicates how many interfaces the class implements. The part immediately following the interface counter is the interface index part. Each interface index takes up two bytes, and the value of the interface counter represents the number of interface indexes that follow.

The com.csdn.reader.HelloWord class does not implement any interfaces, the interface index value is 0.

A little more complicated:

public interface HelloWord extends StringBuilderFormattable, Serializable {}

Analysis via javap:

What is the class index, parent index and interface index set of Class files in JVM virtual machine? Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserves, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report