This document describes changes to the Java Virtual Machine Specification to support Module Import Declarations, which is a preview feature of Java SE 24. See JEP 494 for an overview of the feature.
A companion document describes the changes needed to the Java Language Specification to support Module Import Declarations.
Changes are described with respect to existing sections of the JVMS.
New text is indicated like this and deleted text is
indicated like this. Explanation and discussion, as needed,
is set aside in grey boxes.
Changelog:
2024-10: First draft.
Chapter 4: The class File Format
4.7 Attributes
4.7.25 The Module Attribute
The Module attribute is a variable-length attribute in
the attributes table of a ClassFile structure
(4.1).
The Module attribute indicates the modules required by a
module; the packages exported and opened by a module; and the services
used and provided by a module.
There may be at most one Module attribute in the
attributes table of a ClassFile structure.
The Module attribute has the following format:
Module_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 module_name_index;
u2 module_flags;
u2 module_version_index;
u2 requires_count;
{ u2 requires_index;
u2 requires_flags;
u2 requires_version_index;
} requires[requires_count];
u2 exports_count;
{ u2 exports_index;
u2 exports_flags;
u2 exports_to_count;
u2 exports_to_index[exports_to_count];
} exports[exports_count];
u2 opens_count;
{ u2 opens_index;
u2 opens_flags;
u2 opens_to_count;
u2 opens_to_index[opens_to_count];
} opens[opens_count];
u2 uses_count;
u2 uses_index[uses_count];
u2 provides_count;
{ u2 provides_index;
u2 provides_with_count;
u2 provides_with_index[provides_with_count];
} provides[provides_count];
}
The items of the Module_attribute structure are as
follows:
- attribute_name_index
-
The value of the
attribute_name_indexitem must be a valid index into theconstant_pooltable. Theconstant_poolentry at that index must be aCONSTANT_Utf8_infostructure (4.4.7) representing the string "Module". - attribute_length
-
The value of the
attribute_lengthitem indicates the length of the attribute, excluding the initial six bytes. - module_name_index
-
The value of the
module_name_indexitem must be a valid index into theconstant_pooltable. Theconstant_poolentry at that index must be aCONSTANT_Module_infostructure (4.4.11) denoting the current module. - module_flags
-
The value of the
module_flagsitem is as follows:- 0x0020 (
ACC_OPEN) -
Indicates that this module is open.
- 0x1000 (
ACC_SYNTHETIC) -
Indicates that this module was not explicitly or implicitly declared.
- 0x8000 (
ACC_MANDATED) -
Indicates that this module was implicitly declared.
- 0x0020 (
- module_version_index
-
The value of the
module_version_indexitem must be either zero or a valid index into theconstant_pooltable. If the value of the item is zero, then no version information about the current module is present. If the value of the item is nonzero, then theconstant_poolentry at that index must be aCONSTANT_Utf8_infostructure representing the version of the current module. - requires_count
-
The value of the
requires_countitem indicates the number of entries in therequirestable.If the current module is
java.base, thenrequires_countmust be zero.If the current module is not
java.base, thenrequires_countmust be at least one. - requires[]
-
Each entry in the
requirestable specifies a dependence of the current module. The items in each entry are as follows:- requires_index
-
The value of the
requires_indexitem must be a valid index into theconstant_pooltable. Theconstant_poolentry at that index must be aCONSTANT_Module_infostructure denoting a module on which the current module depends.At most one entry in the
requirestable may specify a module of a given name with itsrequires_indexitem. - requires_flags
-
The value of the
requires_flagsitem is as follows:- 0x0020 (
ACC_TRANSITIVE) -
Indicates that any module which depends on the current module, implicitly declares a dependence on the module indicated by this entry.
- 0x0040 (
ACC_STATIC_PHASE) -
Indicates that this dependence is mandatory in the static phase, i.e., at compile time, but is optional in the dynamic phase, i.e., at run time.
- 0x1000 (
ACC_SYNTHETIC) -
Indicates that this dependence was not explicitly or implicitly declared in the source of the module declaration.
- 0x8000 (
ACC_MANDATED) -
Indicates that this dependence was implicitly declared in the source of the module declaration.
- 0x0020 (
- requires_version_index
-
The value of the
requires_version_indexitem must be either zero or a valid index into theconstant_pooltable. If the value of the item is zero, then no version information about the dependence is present. If the value of the item is nonzero, then theconstant_poolentry at that index must be aCONSTANT_Utf8_infostructure representing the version of the module specified byrequires_index.
Unless the current module is
java.base, exactly one entry in therequirestable must have all of the following:A
requires_indexitem that indicatesjava.base.A
requires_flagsitem that has theACC_SYNTHETICflag not set. (TheACC_MANDATEDflagandACC_TRANSITIVEflags may be set.)If the
classfile version number is 54.0 or above, arequires_flagsitem that hasboththeACC_TRANSITIVEandACC_STATIC_PHASEflagsflag not set.
- exports_count
-
The value of the
exports_countitem indicates the number of entries in theexportstable. - exports[]
-
Each entry in the
exportstable specifies a package exported by the current module, such thatpublicandprotectedtypes in the package, and theirpublicandprotectedmembers, may be accessed from outside the current module, possibly from a limited set of "friend" modules.The items in each entry are as follows:
- exports_index
-
The value of the
exports_indexitem must be a valid index into theconstant_pooltable. Theconstant_poolentry at that index must be aCONSTANT_Package_infostructure (4.4.12) representing a package exported by the current module.At most one entry in the
exportstable may specify a package of a given name with itsexports_indexitem. - exports_flags
-
The value of the
exports_flagsitem is as follows:- 0x1000 (
ACC_SYNTHETIC) -
Indicates that this export was not explicitly or implicitly declared in the source of the module declaration.
- 0x8000 (
ACC_MANDATED) -
Indicates that this export was implicitly declared in the source of the module declaration.
- 0x1000 (
- exports_to_count
-
The value of the
exports_to_countindicates the number of entries in theexports_to_indextable.If
exports_to_countis zero, then this package is exported by the current module in an unqualified fashion; code in any other module may access the types and members in the package.If
exports_to_countis nonzero, then this package is exported by the current module in a qualified fashion; only code in the modules listed in theexports_to_indextable may access the types and members in the package. - exports_to_index[]
-
The value of each entry in the
exports_to_indextable must be a valid index into theconstant_pooltable. Theconstant_poolentry at that index must be aCONSTANT_Module_infostructure denoting a module whose code can access the types and members in this exported package.For each entry in the
exportstable, at most one entry in itsexports_to_indextable may specify a module of a given name.
- opens_count
-
The value of the
opens_countitem indicates the number of entries in theopenstable.opens_countmust be zero if the current module is open. - opens[]
-
Each entry in the
openstable specifies a package opened by the current module, such that all types in the package, and all their members, may be accessed from outside the current module via the reflection libraries of the Java SE Platform, possibly from a limited set of "friend" modules.The items in each entry are as follows:
- opens_index
-
The value of the
opens_indexitem must be a valid index into theconstant_pooltable. Theconstant_poolentry at that index must be aCONSTANT_Package_infostructure representing a package opened by the current module.At most one entry in the
openstable may specify a package of a given name with itsopens_indexitem. - opens_flags
-
The value of the
opens_flagsitem is as follows:- 0x1000 (
ACC_SYNTHETIC) -
Indicates that this opening was not explicitly or implicitly declared in the source of the module declaration.
- 0x8000 (
ACC_MANDATED) -
Indicates that this opening was implicitly declared in the source of the module declaration.
- 0x1000 (
- opens_to_count
-
The value of the
opens_to_countindicates the number of entries in theopens_to_indextable.If
opens_to_countis zero, then this package is opened by the current module in an unqualified fashion; code in any other module may reflectively access the types and members in the package.If
opens_to_countis nonzero, then this package is opened by the current module in a qualified fashion; only code in the modules listed in theopens_to_indextable may reflectively access the types and members in the package. - opens_to_index[]
-
The value of each entry in the
opens_to_indextable must be a valid index into theconstant_pooltable. Theconstant_poolentry at that index must be aCONSTANT_Module_infostructure denoting a module whose code can access the types and members in this opened package.For each entry in the
openstable, at most one entry in itsopens_to_indextable may specify a module of a given name.
- uses_count
-
The value of the
uses_countitem indicates the number of entries in theuses_indextable. - uses_index[]
-
The value of each entry in the
uses_indextable must be a valid index into theconstant_pooltable. Theconstant_poolentry at that index must be aCONSTANT_Class_infostructure (4.4.1) representing a service interface which the current module may discover viajava.util.ServiceLoader.At most one entry in the
uses_indextable may specify a service interface of a given name. - provides_count
-
The value of the
provides_countitem indicates the number of entries in theprovidestable. - provides[]
-
Each entry in the
providestable represents a service implementation for a given service interface.The items in each entry are as follows:
- provides_index
-
The value of the
provides_indexitem must be a valid index into theconstant_pooltable. Theconstant_poolentry at that index must be aCONSTANT_Class_infostructure representing a service interface for which the current module provides a service implementation.At most one entry in the
providestable may specify a service interface of a given name with itsprovides_indexitem. - provides_with_count
-
The value of the
provides_with_countindicates the number of entries in theprovides_with_indextable.provides_with_countmust be nonzero. - provides_with_index[]
-
The value of each entry in the
provides_with_indextable must be a valid index into theconstant_pooltable. Theconstant_poolentry at that index must be aCONSTANT_Class_infostructure representing a service implementation for the service interface specified byprovides_index.For each entry in the
providestable, at most one entry in itsprovides_with_indextable may specify a service implementation of a given name.