JVM Knowledge

The ModulePackages attribute is a variable-length attribute in the attributes table of a ClassFile structure (§4.1). The ModulePackages attribute indicates all the packages of a module that are exported or opened by the Module attribute, as well as all the packages of the service implementations recorded in the Module attribute. The ModulePackages attribute may also indicate packages in the module that are neither exported nor opened nor contain service implementations.

There may be at most one ModulePackages attribute in the attributes table of a ClassFile structure.

The ModulePackages attribute has the following format:

ModulePackages_attribute {
    u2 attribute_name_index;
    u4 attribute_length;
    u2 package_count;
    u2 package_index[package_count];
}

The items of the ModulePackages_attribute structure are as follows:

  • attribute_name_index

    The value of the attribute_name_index item must be a valid index into the constant_pool table. The constant_pool entry at that index must be a CONSTANT_Utf8_info structure (§4.4.7) representing the string "ModulePackages".

  • attribute_length

    The value of the attribute_length item indicates the length of the attribute, excluding the initial six bytes.

  • package_count

    The value of the package_count item indicates the number of entries in the package_index table.

  • package_index[]

    The value of each entry in the package_index table must be a valid index into the constant_pool table. The constant_pool entry at that index must be a CONSTANT_Package_info structure (§4.4.12) representing a package in the current module.

    At most one entry in the package_index table may specify a package of a given name.