Structure of class file

Source: Internet
Author: User
Tags field table

The program storage format---bytecode (bytecode), which is used uniformly by virtual machines of various platforms and all platforms, is the cornerstone of platform independence. The class file is a set of binary streams that are based on 8-bit bytes, and each data item is tightly arranged in the class file in order, with no delimiters added, which makes the content stored in the entire class file almost all the necessary data for the program to run, with no gaps present.

Magic number : The first 4 bytes of a class file, the only action is to determine whether the file is a class file that can be accepted by the virtual machine. A higher version of the JDK can be backwards compatible with the previous version of the class file, but it cannot run a later version of the class file.

constant Pool : A resource repository in class files, the data type that is most associated with other projects in the class file structure, and is one of the largest data items that occupy the class file space, Constant. It is also the first table-type data item that appears in a class file. The capacity count for a constant pool starts at 1 , and the capacity count for other collection types, including interface index collections, Field table collections, Method table collections, and so on, starts at 0. The constant pool is dominated by literal (Literal) and symbolic references (symbolic References) (symbolic references include the fully qualified name of the class and interface (Fully qualified name), the name and descriptor of the field (descriptor), The name and descriptor of the method).

Access Flags: takes up to two bytes to identify access information at some class or interface level. If the class or interface is defined as a public type, whether it is defined as an abstract type, if it is a class, is declared final, and so on.

class index (this_class), parent index (SUPER_CLASS), and Interface index collection (interfaces): The class index is used to determine the fully qualified name of this class, and the parent class index is used to determine the fully qualified name of the parent class of the class. The interface index collection is used to describe which interfaces this class implements.

Field table collection (field_info): Used to describe an interface or a variable declared in a class. Fields include class-level variables and instance-level variables, but do not include local variables declared inside a method.

Method table Collection : Almost identical to the description of the field, the structure is like the field table, including the Access flag (access_flags), the name Index (NAME_INDEX), the descriptor Index (DESCRIPTOR_INDEX), The property sheet collection (attributes).

property Sheet Collections : You can bring your own collection of property sheets in class files, field tables, and method tables to describe information that is proprietary to certain scenarios. The property sheet collection does not require that the individual properties be in strict order, as long as the Java virtual Runtime ignores properties that it does not know if it does not duplicate the existing property name. Key Common properties are: Code property, exceptions property, Linenumbertable property, Localvariabletable property, SourceFile property, Constantvalue property, Innerclasses property , deprecated and synthetic properties, stackmaptable properties, Signature properties, Bootstrapmethods properties.

  public design and private implementations : Public design refers to a defined Java Virtual machine specification; a private implementation modifies and optimizes a specific implementation under the constraints of the virtual machine specification to achieve an excellent virtual machine. As long as the optimized class file can still be read correctly, and the semantics contained therein can be kept intact, the implementation can choose to implement the semantics in any way. There are two main ways to implement a virtual machine : (1) Translating the input Java Virtual machine code into another set of virtual machines when it is loaded or executed ; (2) Translate the input Java Virtual machine code into the local instruction set of the Cheng host CPU (that is, JIT code generation technology) when it is loaded or executed.

Structure of class file

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.