APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.internal.jimage

public final Class ModuleLink

extends Object
implements Comparable<ModuleLink>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable
Imports
java.nio.IntBuffer, java.util.Comparator, .Iterator, .List, .NoSuchElementException, .Objects, java.util.function.Function

Represents links to modules stored in the buffer of "/packages/xxx" image locations (package subdirectories).

Package subdirectories store their data differently to all other jimage entries. Instead of storing a sequence of offsets to their child entries, they store a flattened representation of the child's data in an interleaved buffer. These entries also use flags which are similar to, but distinct from, the ImageLocation flags.

This class encapsulates that complexity to help avoid confusion.

Implementation Note

This class needs to maintain JDK 8 source compatibility. It is used internally in the JDK to implement jimage/jrtfs access, but also compiled and delivered as part of the jrtfs.jar to support access to the jimage file provided by the shipped JDK by tools running on JDK 8.

Field Summary

Modifier and TypeField and Description
private final int
private static final int
FLAGS_PKG_HAS_NORMAL_VERSION

If set, this package exists in non-preview mode.

private static final int
FLAGS_PKG_HAS_PREVIEW_VERSION

If set, this package exists in preview mode.

private static final int
FLAGS_PKG_HAS_RESOURCES

If set, the associated module has resources (in normal or preview mode).

private final String
private static final Comparator<ModuleLink>
PREVIEW_FIRST

Links are ordered with preview versions first, which permits early exit when processing preview entries (it's reversed because the default order for a boolean is false < true).

Constructor Summary

AccessConstructor and Description

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public static ModuleLink
forEmptyPackage(String
the name of the module in which this package exits.
moduleName
,
boolean
whether the associated package is defined for preview mode.
isPreview
)

Returns a link for empty packages in a given module.

public static ModuleLink
forPackage(String
the name of the module in which this package exits.
moduleName
,
boolean
whether the associated package is defined for preview mode.
isPreview
)

Returns a link for non-empty packages (those with resources) in a given module.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean
hasPreviewVersion()

Returns whether the package associated with this module link has a preview version (empty or otherwise) in this link's module.

public boolean
hasResources()

Returns whether the package associated with this link contains resources in its module.

public boolean
isPreviewOnly()

Returns whether this module link exists only in preview mode.

public String
name()

Returns the module name of this link.

private static int
previewFlag(boolean isPreview)

Returns the appropriate FLAGS_PKG_HAS_XXX_VERSION constant according to whether the associated package is defined for preview mode.

public static Iterator<Integer>

Returns:

an iterator of module name offsets.
readNameOffsets
(IntBuffer
the content buffer of an ImageLocation with type PACKAGES_DIR.
buffer
,
boolean
whether to include name offsets for modules present in normal (non-preview) mode.
includeNormal
,
boolean
whether to include name offsets for modules present in preview mode.
includePreview
)

Reads the content buffer of a package subdirectory to return a sequence of module name offsets in the jimage.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public static void
write(List<ModuleLink>
the module links to write, correctly ordered.
links
,
IntBuffer
destination buffer.
buffer
,
Function<String, Integer>
encoder for module names.
nameEncoder
)

Writes a list of module links to a given buffer.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

flagsback to summary
private final int flags
FLAGS_PKG_HAS_NORMAL_VERSIONback to summary
private static final int FLAGS_PKG_HAS_NORMAL_VERSION

If set, this package exists in non-preview mode.

FLAGS_PKG_HAS_PREVIEW_VERSIONback to summary
private static final int FLAGS_PKG_HAS_PREVIEW_VERSION

If set, this package exists in preview mode.

FLAGS_PKG_HAS_RESOURCESback to summary
private static final int FLAGS_PKG_HAS_RESOURCES

If set, the associated module has resources (in normal or preview mode).

nameback to summary
private final String name
PREVIEW_FIRSTback to summary
private static final Comparator<ModuleLink> PREVIEW_FIRST

Links are ordered with preview versions first, which permits early exit when processing preview entries (it's reversed because the default order for a boolean is false < true).

Constructor Detail

Method Detail

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
forEmptyPackageback to summary
public static ModuleLink forEmptyPackage(String moduleName, boolean isPreview)

Returns a link for empty packages in a given module.

The same link can be used for multiple packages in the same module.

Parameters
moduleName:String

the name of the module in which this package exits.

isPreview:boolean

whether the associated package is defined for preview mode.

forPackageback to summary
public static ModuleLink forPackage(String moduleName, boolean isPreview)

Returns a link for non-empty packages (those with resources) in a given module.

The same link can be used for multiple packages in the same module.

Parameters
moduleName:String

the name of the module in which this package exits.

isPreview:boolean

whether the associated package is defined for preview mode.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
hasPreviewVersionback to summary
public boolean hasPreviewVersion()

Returns whether the package associated with this module link has a preview version (empty or otherwise) in this link's module.

hasResourcesback to summary
public boolean hasResources()

Returns whether the package associated with this link contains resources in its module.

An invariant of the module system is that while a package may exist under many modules, it only has resources in one.

isPreviewOnlyback to summary
public boolean isPreviewOnly()

Returns whether this module link exists only in preview mode.

nameback to summary
public String name()

Returns the module name of this link.

previewFlagback to summary
private static int previewFlag(boolean isPreview)

Returns the appropriate FLAGS_PKG_HAS_XXX_VERSION constant according to whether the associated package is defined for preview mode.

readNameOffsetsback to summary
public static Iterator<Integer> readNameOffsets(IntBuffer buffer, boolean includeNormal, boolean includePreview)

Reads the content buffer of a package subdirectory to return a sequence of module name offsets in the jimage.

Package subdirectories store their entries using pairs of integers in an interleaved buffer:

    ...
    [ entry-N flags ]
    [ entry-N name offset ]
    [ entry-(N+1) flags ]
    [ entry-(N+1) name offset ]
    ...

Entry flags control whether an entry name should be included by the returned iterator, depending on the given include-flags.

Parameters
buffer:IntBuffer

the content buffer of an ImageLocation with type PACKAGES_DIR.

includeNormal:boolean

whether to include name offsets for modules present in normal (non-preview) mode.

includePreview:boolean

whether to include name offsets for modules present in preview mode.

Returns:Iterator<Integer>

an iterator of module name offsets.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
writeback to summary
public static void write(List<ModuleLink> links, IntBuffer buffer, Function<String, Integer> nameEncoder)

Writes a list of module links to a given buffer. The given entry list is checked carefully to ensure the written buffer will be valid.

Entries are written in order, taking two integer slots per entry as [<flags>, <encoded-name>].

Parameters
links:List<ModuleLink>

the module links to write, correctly ordered.

buffer:IntBuffer

destination buffer.

nameEncoder:Function<String, Integer>

encoder for module names.

Exceptions
IllegalArgumentException:
in the link entries are invalid in any way.