APIdia Launch Partner
Top Inners Constructors Methods
jdk.tools.jlink.internal

public Class Snippets

extends Object
Class Inheritance
Imports
java.lang.classfile.ClassBuilder, .CodeBuilder, .TypeKind, java.lang.constant.ClassDesc, .MethodTypeDesc, .ConstantDesc, java.util.ArrayList, .Arrays, .Collection, .Objects, java.util.function.Function

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Snippets.ArraySnippetBuilder

Generate bytecode to load an array of the given referene type onto the operand stack.

public abstract static class
Snippets.CollectionSnippetBuilder

Generate bytecodes for loading a collection of elements, support using pagination to avoid overloading the 64k code limit.

public static interface
Snippets.IndexedElementSnippetBuilder<T>

Build a snippet for an element with a given index.

public static record
Snippets.Loadable

Describe an operand that can be load onto the operand stack.

public static record
Snippets.PagingContext

Some basic information about pagination.

public static class
Snippets.SetSnippetBuilder

Generate bytecodes to load a set onto the operand stack.

public static interface
Snippets.Snippet

Snippet of bytecodes

Constructor Summary

AccessConstructor and Description
public

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Snippetsback to summary
public Snippets()
jdk.tools.jlink.internal back to summary

public Class Snippets.ArraySnippetBuilder

extends CollectionSnippetBuilder
Class Inheritance
Known Direct Subclasses
jdk.tools.jlink.internal.Snippets.SetSnippetBuilder

Generate bytecode to load an array of the given referene type onto the operand stack. The generated code will create an array inline, and then populate the array either inline or by invoking the first pagination method if pagination is activated. If pagination is activated, pagination methods are generated with the given ClassBuilder with method name formatted with the methodNamePrefix appended with page numberand. Each pagination method will assign value to the corresponding page and chain calling next page. Effectively as methodNamePrefix_0(new T[elements.size()]); where T[] methodNamePrefix_0(T[] ar) { ar[0] = elements[0]; ar[1] = elements[1]; ... ar[pageSize-1] = elements[pageSize - 1]; methodNamePrefix_1(ar); return ar; } and the last page will stop the chain and can be partial instead of full page size.

Field Summary

Modifier and TypeField and Description
pack-priv final ClassDesc
pack-priv Snippets.Snippet[]
pack-priv final MethodTypeDesc
Inherited from jdk.tools.jlink.internal.Snippets.CollectionSnippetBuilder:
activatePagingThresholdclbDEFAULT_PAGE_SIZEDEFAULT_THRESHOLDelementTypeENUM_PAGE_SIZEmethodNamePrefixownerClassDescpageSizeSTRING_PAGE_SIZE

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Snippets.Loadable
build(Snippets.Snippet[] loadElementSnippets)

Implements abstract jdk.tools.jlink.internal.Snippets.CollectionSnippetBuilder.build.

Build the Loadable snippet to load the collection of elements onto the operand stack.

protected void
fill(CodeBuilder cob, int fromIndex, int toIndex)

private void
genFillPageHelper(int pageNo, boolean hasNextPage)

private void
private void
private void
setupHelpers()

Generate helper methods to fill each page

Inherited from jdk.tools.jlink.internal.Snippets.CollectionSnippetBuilder:
activatePagingThresholdclassBuilderdisablePaginationenablePaginationenablePaginationenablePaginationmethodNamePrefixownerClassDescpageSizeshouldPaginate

Field Detail

classDescback to summary
pack-priv final ClassDesc classDesc
loadElementSnippetsback to summary
pack-priv Snippets.Snippet[] loadElementSnippets
MTD_PageHelperback to summary
pack-priv final MethodTypeDesc MTD_PageHelper

Constructor Detail

ArraySnippetBuilderback to summary
public ArraySnippetBuilder(ClassDesc elementType)

Method Detail

buildback to summary
public Snippets.Loadable build(Snippets.Snippet[] loadElementSnippets)

Implements abstract jdk.tools.jlink.internal.Snippets.CollectionSnippetBuilder.build.

Doc from jdk.tools.jlink.internal.Snippets.CollectionSnippetBuilder.build.

Build the Loadable snippet to load the collection of elements onto the operand stack. When pagination is enabled and needed as the total count of elements is larger than the given threshold, missing required field will lead to NullPointerException.

Annotations
@Override
fillback to summary
protected void fill(CodeBuilder cob, int fromIndex, int toIndex)
genFillPageHelperback to summary
private void genFillPageHelper(int pageNo, boolean hasNextPage)
invokePageHelperback to summary
private void invokePageHelper(CodeBuilder cob)
newArrayback to summary
private void newArray(CodeBuilder cob)
setupHelpersback to summary
private void setupHelpers()

Generate helper methods to fill each page

jdk.tools.jlink.internal back to summary

public abstract Class Snippets.CollectionSnippetBuilder

extends Object
Class Inheritance
Known Direct Subclasses
jdk.tools.jlink.internal.Snippets.ArraySnippetBuilder

Generate bytecodes for loading a collection of elements, support using pagination to avoid overloading the 64k code limit.

Field Summary

Modifier and TypeField and Description
protected int
protected ClassBuilder
public static final int
DEFAULT_PAGE_SIZE

Good enough for average ~30 bytes per element

protected static final int
DEFAULT_THRESHOLD

Default threshold based on 15K code size on ~30 bytes per element

protected ClassDesc
public static final int
ENUM_PAGE_SIZE

Default page size of enum array

protected String
protected ClassDesc
protected int
public static final int
STRING_PAGE_SIZE

Default page size of string array

Constructor Summary

AccessConstructor and Description
protected
CollectionSnippetBuilder(ClassDesc
The element type
elementType
)

Method Summary

Modifier and TypeMethod and Description
public Snippets.CollectionSnippetBuilder
activatePagingThreshold(int
Use pagination methods if the count of elements is larger than the given value
activatePagingThreshold
)

Set the threshold of element count to enable pagination.

public abstract Snippets.Loadable

Returns:

The Loadable snippet
build
(Snippets.Snippet[]
The array of Snippets used to load individual element in the collection.
loadElementSnippets
)

Build the Loadable snippet to load the collection of elements onto the operand stack.

public Snippets.CollectionSnippetBuilder
classBuilder(ClassBuilder clb)

Set the class builder used to generate the pagination methods.

public Snippets.CollectionSnippetBuilder
disablePagination()

Disable pagination.

public Snippets.CollectionSnippetBuilder
enablePagination(String
The method name prefix for generated paging helper methods
methodNamePrefix
,
int
The page size
pageSize
,
int
The element count to actiave the pagination
threshold
)

Enable pagination if the count of elements is larger than the given threshold.

public Snippets.CollectionSnippetBuilder
enablePagination(String methodNamePrefix, int pageSize)

Enable pagination if the count of elements is larger than pageSize or DEFAULT_THRESHOLD

public Snippets.CollectionSnippetBuilder
enablePagination(String methodNamePrefix)

Enable pagination if the count of elements is larger than pageSize or DEFAULT_THRESHOLD with page size DEFAULT_PAGE_SIZE.

public Snippets.CollectionSnippetBuilder
methodNamePrefix(String
The method name prefix. Generated method will have the name of this value appended with page number
methodNamePrefix
)

Set the method name prefix for the pagination methods.

public Snippets.CollectionSnippetBuilder
ownerClassDesc(ClassDesc
The owner class for the pagination methods
ownerClassDesc
)

Set the owner class host the pagination methods.

public Snippets.CollectionSnippetBuilder
pageSize(int
The count of elements per page*
pageSize
)

Set the page size.

protected boolean
shouldPaginate(int length)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

activatePagingThresholdback to summary
protected int activatePagingThreshold
clbback to summary
protected ClassBuilder clb
DEFAULT_PAGE_SIZEback to summary
public static final int DEFAULT_PAGE_SIZE

Good enough for average ~30 bytes per element

DEFAULT_THRESHOLDback to summary
protected static final int DEFAULT_THRESHOLD

Default threshold based on 15K code size on ~30 bytes per element

elementTypeback to summary
protected ClassDesc elementType
ENUM_PAGE_SIZEback to summary
public static final int ENUM_PAGE_SIZE

Default page size of enum array

methodNamePrefixback to summary
protected String methodNamePrefix
ownerClassDescback to summary
protected ClassDesc ownerClassDesc
pageSizeback to summary
protected int pageSize
STRING_PAGE_SIZEback to summary
public static final int STRING_PAGE_SIZE

Default page size of string array

Constructor Detail

CollectionSnippetBuilderback to summary
protected CollectionSnippetBuilder(ClassDesc elementType)
Parameters
elementType:ClassDesc

The element type

Method Detail

activatePagingThresholdback to summary
public Snippets.CollectionSnippetBuilder activatePagingThreshold(int activatePagingThreshold)

Set the threshold of element count to enable pagination.

Parameters
activatePagingThreshold:int

Use pagination methods if the count of elements is larger than the given value

buildback to summary
public abstract Snippets.Loadable build(Snippets.Snippet[] loadElementSnippets)

Build the Loadable snippet to load the collection of elements onto the operand stack. When pagination is enabled and needed as the total count of elements is larger than the given threshold, missing required field will lead to NullPointerException.

Parameters
loadElementSnippets:Snippets.Snippet[]

The array of Snippets used to load individual element in the collection.

Returns:Snippets.Loadable

The Loadable snippet

classBuilderback to summary
public Snippets.CollectionSnippetBuilder classBuilder(ClassBuilder clb)

Set the class builder used to generate the pagination methods. This value must be set if pagination is needed, otherwise the build would lead to NullPointerException.

disablePaginationback to summary
public Snippets.CollectionSnippetBuilder disablePagination()

Disable pagination. Generated bytecode will always try to construct the collection inline.

enablePaginationback to summary
public Snippets.CollectionSnippetBuilder enablePagination(String methodNamePrefix, int pageSize, int threshold)

Enable pagination if the count of elements is larger than the given threshold.

Parameters
methodNamePrefix:String

The method name prefix for generated paging helper methods

pageSize:int

The page size

threshold:int

The element count to actiave the pagination

enablePaginationback to summary
public Snippets.CollectionSnippetBuilder enablePagination(String methodNamePrefix, int pageSize)

Enable pagination if the count of elements is larger than pageSize or DEFAULT_THRESHOLD

enablePaginationback to summary
public Snippets.CollectionSnippetBuilder enablePagination(String methodNamePrefix)

Enable pagination if the count of elements is larger than pageSize or DEFAULT_THRESHOLD with page size DEFAULT_PAGE_SIZE.

methodNamePrefixback to summary
public Snippets.CollectionSnippetBuilder methodNamePrefix(String methodNamePrefix)

Set the method name prefix for the pagination methods.

Parameters
methodNamePrefix:String

The method name prefix. Generated method will have the name of this value appended with page number

ownerClassDescback to summary
public Snippets.CollectionSnippetBuilder ownerClassDesc(ClassDesc ownerClassDesc)

Set the owner class host the pagination methods.

Parameters
ownerClassDesc:ClassDesc

The owner class for the pagination methods

pageSizeback to summary
public Snippets.CollectionSnippetBuilder pageSize(int pageSize)

Set the page size. The max page size is STRING_PAGE_SIZE.

Parameters
pageSize:int

The count of elements per page*

shouldPaginateback to summary
protected boolean shouldPaginate(int length)
jdk.tools.jlink.internal back to summary

public Interface Snippets.IndexedElementSnippetBuilder<T>

Known Direct Implementers
jdk.tools.jlink.internal.plugins.ModuleDescriptorBuilder
Annotations
@FunctionalInterface

Build a snippet for an element with a given index. Typically used for elements in a collection to identify the specific element.

Method Summary

Modifier and TypeMethod and Description
public Snippets.Snippet

Returns:

A snippet of bytecodes to process the element
build
(T
The element
element
,
int
The index of the element in the containing collection
index
)

Build a snippet for the element at the index.

public default Snippets.Snippet[]
buildAll(Collection<T> elements)

Method Detail

buildback to summary
public Snippets.Snippet build(T element, int index)

Build a snippet for the element at the index.

Parameters
element:T

The element

index:int

The index of the element in the containing collection

Returns:Snippets.Snippet

A snippet of bytecodes to process the element

buildAllback to summary
public default Snippets.Snippet[] buildAll(Collection<T> elements)
jdk.tools.jlink.internal back to summary

public final Record Snippets.Loadable

extends Record
implements Snippet
Class Inheritance
All Implemented Interfaces
jdk.tools.jlink.internal.Snippets.Snippet
Record Components
classDesc:ClassDesc
The type of the operand
load:Snippets.Snippet
The snippet to load the operand onto the operand stack

Describe an operand that can be load onto the operand stack. For example, an array of string can be described as a Loadable.

Field Summary

Modifier and TypeField and Description
private final ClassDesc
classDesc

Record Component accessed by classDesc().

The type of the operand
private final Snippets.Snippet
load

Record Component accessed by load().

The snippet to load the operand onto the operand stack

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public ClassDesc
classDesc()

Record Component getter of classDesc.

Record Component The type of the operand

public void
emit(CodeBuilder
The CodeBuilder to add the bytecode for loading
cob
)

Implements jdk.tools.jlink.internal.Snippets.Snippet.emit.

Generate the bytecode to load the Loadable onto the operand stack.

public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

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

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public Snippets.Snippet
load()

Record Component getter of load.

Record Component The snippet to load the operand onto the operand stack

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

classDescback to summary
private final ClassDesc classDesc

Record Component accessed by classDesc().

The type of the operand

loadback to summary
private final Snippets.Snippet load

Record Component accessed by load().

The snippet to load the operand onto the operand stack

Constructor Detail

Loadableback to summary
public Loadable(ClassDesc classDesc, Snippets.Snippet load)

Method Detail

classDescback to summary
public ClassDesc classDesc()

Record Component getter of classDesc.

Record Component
The type of the operand
emitback to summary
public void emit(CodeBuilder cob)

Implements jdk.tools.jlink.internal.Snippets.Snippet.emit.

Generate the bytecode to load the Loadable onto the operand stack.

Parameters
cob:CodeBuilder

The CodeBuilder to add the bytecode for loading

Annotations
@Override
equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

loadback to summary
public Snippets.Snippet load()

Record Component getter of load.

Record Component
The snippet to load the operand onto the operand stack
toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

jdk.tools.jlink.internal back to summary

public final Record Snippets.PagingContext

extends Record
Class Inheritance
Record Components
total:int
The total count of elements
pageSize:int
the number or elements to be included in a page

Some basic information about pagination.

Field Summary

Modifier and TypeField and Description
private final int
pageSize

Record Component accessed by pageSize().

the number or elements to be included in a page
private final int
total

Record Component accessed by total().

The total count of elements

Constructor Summary

AccessConstructor and Description
public
PagingContext(int total, int pageSize)

Method Summary

Modifier and TypeMethod and Description
public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

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

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public boolean
isLastPagePartial()

If the last page has less elements than given page size.

public int
lastPageSize()

The number of elements in the last page.

public int
pageCount()

The number of pages.

public int
pageSize()

Record Component getter of pageSize.

Record Component the number or elements to be included in a page

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

public int
total()

Record Component getter of total.

Record Component The total count of elements

Field Detail

pageSizeback to summary
private final int pageSize

Record Component accessed by pageSize().

the number or elements to be included in a page

totalback to summary
private final int total

Record Component accessed by total().

The total count of elements

Constructor Detail

PagingContextback to summary
public PagingContext(int total, int pageSize)

Method Detail

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

isLastPagePartialback to summary
public boolean isLastPagePartial()

If the last page has less elements than given page size.

lastPageSizeback to summary
public int lastPageSize()

The number of elements in the last page.

pageCountback to summary
public int pageCount()

The number of pages.

pageSizeback to summary
public int pageSize()

Record Component getter of pageSize.

Record Component
the number or elements to be included in a page
toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

totalback to summary
public int total()

Record Component getter of total.

Record Component
The total count of elements
jdk.tools.jlink.internal back to summary

public Class Snippets.SetSnippetBuilder

extends ArraySnippetBuilder
Class Inheritance

Generate bytecodes to load a set onto the operand stack. The Set is constructed with Set::of method. When there are more than 2 elements in the set, an array is constructed.

Field Summary

Inherited from jdk.tools.jlink.internal.Snippets.ArraySnippetBuilder:
classDescloadElementSnippetsMTD_PageHelper

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Snippets.Loadable
build(Snippets.Snippet[] loadElementSnippets)

Overrides jdk.tools.jlink.internal.Snippets.ArraySnippetBuilder.build.

Build the Loadable snippet to load the collection of elements onto the operand stack.

private void
Inherited from jdk.tools.jlink.internal.Snippets.ArraySnippetBuilder:
fill

Constructor Detail

SetSnippetBuilderback to summary
public SetSnippetBuilder(ClassDesc elementType)

Method Detail

buildback to summary
public Snippets.Loadable build(Snippets.Snippet[] loadElementSnippets)

Overrides jdk.tools.jlink.internal.Snippets.ArraySnippetBuilder.build.

Doc from jdk.tools.jlink.internal.Snippets.CollectionSnippetBuilder.build.

Build the Loadable snippet to load the collection of elements onto the operand stack. When pagination is enabled and needed as the total count of elements is larger than the given threshold, missing required field will lead to NullPointerException.

Annotations
@Override
buildTinySetback to summary
private void buildTinySet(CodeBuilder cob)
jdk.tools.jlink.internal back to summary

public Interface Snippets.Snippet

Known Direct Implementers
jdk.tools.jlink.internal.Snippets.Loadable, jdk.tools.jlink.internal.plugins.ModuleDescriptorBuilder.ModuleDescriptorSnippet
Annotations
@FunctionalInterface

Snippet of bytecodes

Method Summary

Modifier and TypeMethod and Description
public static <T> Snippets.Snippet[]

Returns:

Snippets
buildAll
(Collection<T>
The elements to be processed
elements
,
Function<T, Snippets.Snippet>
The snippet building function for a given element
fn
)

Build snippets each to process the corresponding element.

public void
emit(CodeBuilder
The CodeBuilder
cob
)

Emit the bytecode snippet to the CodeBuilder.

public static <T extends ConstantDesc> Snippets.Snippet
loadConstant(T v)

Load a constant onto the operand stack.

public static Snippets.Snippet
loadEnum(Enum<?> e)

Load an enum constant onto the operand stack.

public static Snippets.Snippet
loadInteger(int value)

Load an Integer, boxed int value onto the operand stack.

Method Detail

buildAllback to summary
public static <T> Snippets.Snippet[] buildAll(Collection<T> elements, Function<T, Snippets.Snippet> fn)

Build snippets each to process the corresponding element.

Parameters
elements:Collection<T>

The elements to be processed

fn:Function<T, Snippets.Snippet>

The snippet building function for a given element

Returns:Snippets.Snippet[]

Snippets

emitback to summary
public void emit(CodeBuilder cob)

Emit the bytecode snippet to the CodeBuilder.

Parameters
cob:CodeBuilder

The CodeBuilder

loadConstantback to summary
public static <T extends ConstantDesc> Snippets.Snippet loadConstant(T v)

Load a constant onto the operand stack.

loadEnumback to summary
public static Snippets.Snippet loadEnum(Enum<?> e)

Load an enum constant onto the operand stack.

loadIntegerback to summary
public static Snippets.Snippet loadInteger(int value)

Load an Integer, boxed int value onto the operand stack.