From version 53.0 (Java SE 9), a module is declared in module-info.java,
which compiles to module-info.class. That file uses the class file format
but holds no class. Its class flags are just ACC_MODULE (0x8000), its
this_class names module-info, super_class is 0,
and it has no interfaces, fields or methods. Everything is in its attributes: a Module
attribute, and usually ModulePackages and ModuleMainClass. Its constant pool may hold
Module and Package entries, which no other class file may. The language side is on the
Java packages and modules
page.
Module
The module declaration: its name, flags and version, then five tables, one for each kind of directive.
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 6 | 2 | u2 | module_name_index | A Module entry: this module’s name |
| 8 | 2 | u2 | module_flags | ACC_OPEN, ACC_SYNTHETIC, ACC_MANDATED |
| 10 | 2 | u2 | module_version_index | A Utf8 entry: the version, or 0 for none |
| 12 | varies | requires | u2 requires_count and the requires entries | |
| … | varies | exports | u2 exports_count and the exports entries | |
| … | varies | opens | u2 opens_count and the opens entries | |
| … | varies | uses | u2 uses_count and the uses indexes | |
| … | varies | provides | u2 provides_count and the provides entries |
requires
One 6-byte entry per requires directive. Every module except
java.base must have exactly one entry for java.base; javac
adds it, marked ACC_MANDATED, when the source does not say so.
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 2 | u2 | requires_index | A Module entry: the module depended on |
| 2 | 2 | u2 | requires_flags | ACC_TRANSITIVE, ACC_STATIC_PHASE, ACC_SYNTHETIC, ACC_MANDATED |
| 4 | 2 | u2 | requires_version_index | A Utf8 entry: the version of the module compiled against, or 0 |
exports
One entry per exports directive: a package whose public types other
modules may use.
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 2 | u2 | exports_index | A Package entry |
| 2 | 2 | u2 | exports_flags | ACC_SYNTHETIC, ACC_MANDATED |
| 4 | 2 | u2 | exports_to_count | 0 to export to every module; otherwise the number of modules that follow |
| 6 | 2 × n | u2[] | exports_to_index | Module entries: the only modules it is exported to (exports … to …) |
opens
One entry per opens directive: a package whose types, private members
included, are open to reflection at run time. The layout is the same as exports, with
opens_index, opens_flags, opens_to_count and
opens_to_index. An open module (ACC_OPEN) has no opens entries.
uses
The services this module looks up with java.util.ServiceLoader.
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 2 | u2 | uses_count | The number of services |
| 2 | 2 × n | u2[] | uses_index | Class entries: the service interfaces or classes |
provides
One entry per provides … with … directive: implementations of a service
that this module offers.
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 2 | u2 | provides_index | A Class entry: the service |
| 2 | 2 | u2 | provides_with_count | The number of implementations, at least 1 |
| 4 | 2 × n | u2[] | provides_with_index | Class entries: the implementing classes |
ModulePackages
Every package of the module, exported, opened or not. The compiler or the
jar tool writes it, so the JVM need not scan the module’s files.
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 6 | 2 | u2 | package_count | The number of packages |
| 8 | 2 × n | u2[] | package_index | Package entries |
ModuleMainClass
The class java --module runs when no class is named. The length is
always 2.
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 6 | 2 | u2 | main_class_index | A Class entry: the main class |
The JDK’s own attributes
The JDK’s build tools write three more attributes into the module-info files of the JDK’s own modules. They are not in the JVM Specification, and other module-info files do not normally have them. The layouts below are the ones the explorer reads, from the OpenJDK sources; they were not checked against real files for this page. The explorer reads them but never turns a file down because of them.
ModuleHashes
Hashes of other modules that this one is tied to, so that they can be checked when the modules are linked.
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 6 | 2 | u2 | algorithm_index | A Utf8 entry: the hash algorithm, such as SHA-256 |
| 8 | 2 | u2 | hashes_table_length | The number of modules |
| … | 2 | u2 | module_name_index | A Module entry |
| … | 2 | u2 | hash_length | The length of the hash |
| … | hash_length | u1[] | hash | The hash |
The last three fields repeat for each module.
ModuleResolution
How the module is treated when modules are resolved. The length is always 2.
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 6 | 2 | u2 | resolution_flags | 0x0001 DO_NOT_RESOLVE_BY_DEFAULT, 0x0002 WARN_DEPRECATED, 0x0004 WARN_DEPRECATED_FOR_REMOVAL, 0x0008 WARN_INCUBATING |
Incubator modules, such as those named jdk.incubator.…, carry
DO_NOT_RESOLVE_BY_DEFAULT and WARN_INCUBATING.
ModuleTarget
The platform a module with native code was built for. The length is always 2.
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 6 | 2 | u2 | target_platform_index | A Utf8 entry: the platform, such as macos-aarch64 or linux-x64 |