APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.classfile.impl

public final Class Util

extends Object
Class Inheritance
Imports
java.lang.classfile.*, java.lang.classfile.attribute.CodeAttribute, jdk.internal.classfile.components.ClassPrinter, java.lang.classfile.constantpool.ClassEntry, .ModuleEntry, .PoolEntry, .Utf8Entry, java.lang.constant.ClassDesc, .MethodTypeDesc, .ModuleDesc, java.lang.reflect.AccessFlag, java.util.AbstractList, .Collection, .List, java.util.function.Consumer, .Function, jdk.internal.access.SharedSecrets, jdk.internal.constant.ClassOrInterfaceDescImpl, jdk.internal.vm.annotation.ForceInline, .Stable

Helper to create and manipulate type descriptors, where type descriptors are represented as JVM type descriptor strings and symbols are represented as name strings

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static interface
Util.Writable

A generic interface for objects to write to a buf writer.

pack-priv static interface

Field Summary

Modifier and TypeField and Description
private static final int
pack-priv static final int
pack-priv static final int[]
powers

The code below is as if:

int[] powers = new int[7 * SIGNIFICANT_OCTAL_DIGITS]; for (int i = 1, k = 31; i <= 7; i++, k *= 31) { int t = powers[powersIndex(i, 0)] = k; for (int j = 1; j < SIGNIFICANT_OCTAL_DIGITS; j++) { t *= t; t *= t; t *= t; powers[powersIndex(i, j)] = t; } }
int[] powers = new int[7 * SIGNIFICANT_OCTAL_DIGITS];

for (int i = 1, k = 31; i <= 7; i++, k *= 31) {
   int t = powers[powersIndex(i, 0)] = k;
   for (int j = 1; j < SIGNIFICANT_OCTAL_DIGITS; j++) {
       t *= t;
       t *= t;
       t *= t;
       powers[powersIndex(i, j)] = t;
   }
}
pack-priv static final int

Constructor Summary

AccessConstructor and Description
private
Util()

Method Summary

Modifier and TypeMethod and Description
public static IllegalArgumentException
public static Consumer<MethodBuilder>
buildingCode(Consumer<? super CodeBuilder> codeHandler)

public static Consumer<FieldBuilder>
buildingFlags(int flags)

public static char
checkFlags(int mask)

Ensures the given mask won't be truncated when written as an access flag

public static void
public static int
checkU1(int incoming, String valueName)

Ensures the given value won't be truncated when written as a u1

public static char
checkU2(int incoming, String valueName)

Ensures the given value won't be truncated when written as a u2

public static int
descriptorStringHash(int length, int hash)

Returns the hash code of a class or interface L descriptor given the internal name.

public static void
dumpBytesHex(Consumer<String> dump, byte[] bytes, int length)

public static void
dumpMethod(SplitConstantPool cp, ClassDesc cls, String methodName, MethodTypeDesc methodDesc, int acc, RawBytecodeHelper.CodeRange bytecode, Consumer<String> dump)

public static List<ClassEntry>
entryList(List<? extends ClassDesc> list)

public static ClassDesc
public static int
public static int
public static boolean
has(AccessFlag.Location location, int flagsMask, AccessFlag flag)

public static boolean
isAttributeAllowed(final Attribute<?> attr, final ClassFileImpl context)

public static boolean
public static <T, U> List<U>
mappedList(List<? extends T> list, Function<T, U> mapper)

public static int
maxLocals(int flags, MethodTypeDesc mDesc)

public static MethodTypeDesc
public static List<ModuleEntry>
moduleEntryList(List<? extends ModuleDesc> list)

public static IllegalArgumentException
outOfRangeException(int value, String fieldName, String typeName)

public static int
public static int
public static int[]
public static int
pow31(int k)

private static int
powerOctal(int digit, int index)

pack-priv static int
powersIndex(int digit, int index)

public static List<List<Annotation>>
sanitizeParameterAnnotations(List<List<Annotation>> input)

Sanitizes an input nested list of parameter annotations.

public static <T> List<T>
sanitizeU1List(List<T> input)

Sanitizes an input list to make it immutable, and verify its size can be represented with U1, throwing IAE otherwise.

public static <T> List<T>
sanitizeU2List(Collection<T> input)

Sanitizes an input list to make it immutable, and verify its size can be represented with U2, throwing IAE otherwise.

public static int
public static String
toBinaryName(ClassDesc cd)

Converts a descriptor of classes or interfaces into a binary name.

public static ClassDesc
toClassDesc(String classInternalNameOrArrayDesc)

public static String
public static <T extends Attribute<T>> void
public static void
writeAttributes(BufWriterImpl buf, List<? extends Attribute<?>> list)

pack-priv static void
writeList(BufWriterImpl buf, Util.Writable[] array, int size)

public static void
writeListIndices(BufWriter writer, List<? extends PoolEntry> list)

public static boolean
public static <T> Consumer<Consumer<T>>
writingAll(Iterable<T> container)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ATTRIBUTE_STABILITY_COUNTback to summary
private static final int ATTRIBUTE_STABILITY_COUNT
INVERSE_31back to summary
pack-priv static final int INVERSE_31
powersback to summary
pack-priv static final int[] powers

The code below is as if:

int[] powers = new int[7 * SIGNIFICANT_OCTAL_DIGITS]; for (int i = 1, k = 31; i <= 7; i++, k *= 31) { int t = powers[powersIndex(i, 0)] = k; for (int j = 1; j < SIGNIFICANT_OCTAL_DIGITS; j++) { t *= t; t *= t; t *= t; powers[powersIndex(i, j)] = t; } }
int[] powers = new int[7 * SIGNIFICANT_OCTAL_DIGITS];

for (int i = 1, k = 31; i <= 7; i++, k *= 31) {
   int t = powers[powersIndex(i, 0)] = k;
   for (int j = 1; j < SIGNIFICANT_OCTAL_DIGITS; j++) {
       t *= t;
       t *= t;
       t *= t;
       powers[powersIndex(i, j)] = t;
   }
}
This is converted to explicit initialization to avoid bootstrap overhead. Validated in UtilTest.
Annotations
@Stable
SIGNIFICANT_OCTAL_DIGITSback to summary
pack-priv static final int SIGNIFICANT_OCTAL_DIGITS

Constructor Detail

Utilback to summary
private Util()

Method Detail

badOpcodeKindExceptionback to summary
public static IllegalArgumentException badOpcodeKindException(Opcode op, Opcode.Kind k)
buildingCodeback to summary
public static Consumer<MethodBuilder> buildingCode(Consumer<? super CodeBuilder> codeHandler)
buildingFlagsback to summary
public static Consumer<FieldBuilder> buildingFlags(int flags)
checkFlagsback to summary
public static char checkFlags(int mask)

Ensures the given mask won't be truncated when written as an access flag

checkKindback to summary
public static void checkKind(Opcode op, Opcode.Kind k)
checkU1back to summary
public static int checkU1(int incoming, String valueName)

Ensures the given value won't be truncated when written as a u1

checkU2back to summary
public static char checkU2(int incoming, String valueName)

Ensures the given value won't be truncated when written as a u2

descriptorStringHashback to summary
public static int descriptorStringHash(int length, int hash)

Returns the hash code of a class or interface L descriptor given the internal name.

dumpBytesHexback to summary
public static void dumpBytesHex(Consumer<String> dump, byte[] bytes, int length)
dumpMethodback to summary
public static void dumpMethod(SplitConstantPool cp, ClassDesc cls, String methodName, MethodTypeDesc methodDesc, int acc, RawBytecodeHelper.CodeRange bytecode, Consumer<String> dump)
entryListback to summary
public static List<ClassEntry> entryList(List<? extends ClassDesc> list)
fieldTypeSymbolback to summary
public static ClassDesc fieldTypeSymbol(Utf8Entry utf8)
flagsToBitsback to summary
public static int flagsToBits(AccessFlag.Location location, Collection<AccessFlag> flags)
flagsToBitsback to summary
public static int flagsToBits(AccessFlag.Location location, AccessFlag... flags)
hasback to summary
public static boolean has(AccessFlag.Location location, int flagsMask, AccessFlag flag)
isAttributeAllowedback to summary
public static boolean isAttributeAllowed(final Attribute<?> attr, final ClassFileImpl context)
isDoubleSlotback to summary
public static boolean isDoubleSlot(ClassDesc desc)
mappedListback to summary
public static <T, U> List<U> mappedList(List<? extends T> list, Function<T, U> mapper)
maxLocalsback to summary
public static int maxLocals(int flags, MethodTypeDesc mDesc)
methodTypeSymbolback to summary
public static MethodTypeDesc methodTypeSymbol(Utf8Entry utf8)
moduleEntryListback to summary
public static List<ModuleEntry> moduleEntryList(List<? extends ModuleDesc> list)
outOfRangeExceptionback to summary
public static IllegalArgumentException outOfRangeException(int value, String fieldName, String typeName)
parameterSlotsback to summary
public static int parameterSlots(MethodTypeDesc mDesc)
paramSlotSizeback to summary
public static int paramSlotSize(ClassDesc desc)
parseParameterSlotsback to summary
public static int[] parseParameterSlots(int flags, MethodTypeDesc mDesc)
pow31back to summary
public static int pow31(int k)
powerOctalback to summary
private static int powerOctal(int digit, int index)
powersIndexback to summary
pack-priv static int powersIndex(int digit, int index)
sanitizeParameterAnnotationsback to summary
public static List<List<Annotation>> sanitizeParameterAnnotations(List<List<Annotation>> input)

Sanitizes an input nested list of parameter annotations.

sanitizeU1Listback to summary
public static <T> List<T> sanitizeU1List(List<T> input)

Sanitizes an input list to make it immutable, and verify its size can be represented with U1, throwing IAE otherwise.

sanitizeU2Listback to summary
public static <T> List<T> sanitizeU2List(Collection<T> input)

Sanitizes an input list to make it immutable, and verify its size can be represented with U2, throwing IAE otherwise.

slotSizeback to summary
public static int slotSize(ClassDesc desc)
toBinaryNameback to summary
public static String toBinaryName(ClassDesc cd)

Converts a descriptor of classes or interfaces into a binary name. Rejects primitive types or arrays. This is an inverse of ClassDesc#of(String).

toClassDescback to summary
public static ClassDesc toClassDesc(String classInternalNameOrArrayDesc)
toInternalNameback to summary
public static String toInternalName(ClassDesc cd)
writeAttributeback to summary
public static <T extends Attribute<T>> void writeAttribute(BufWriterImpl writer, Attribute<?> attr)
Annotations
@SuppressWarnings:unchecked
writeAttributesback to summary
public static void writeAttributes(BufWriterImpl buf, List<? extends Attribute<?>> list)
Annotations
@ForceInline
writeListback to summary
pack-priv static void writeList(BufWriterImpl buf, Util.Writable[] array, int size)
Annotations
@ForceInline
writeListIndicesback to summary
public static void writeListIndices(BufWriter writer, List<? extends PoolEntry> list)
writeLocalVariableback to summary
public static boolean writeLocalVariable(BufWriterImpl buf, PseudoInstruction lvOrLvt)
writingAllback to summary
public static <T> Consumer<Consumer<T>> writingAll(Iterable<T> container)
jdk.internal.classfile.impl back to summary

pack-priv Interface Util.Writable

Known Direct Implementers
jdk.internal.classfile.impl.BoundAttribute, jdk.internal.classfile.impl.DirectFieldBuilder, jdk.internal.classfile.impl.DirectMethodBuilder, jdk.internal.classfile.impl.FieldImpl, jdk.internal.classfile.impl.MethodImpl, jdk.internal.classfile.impl.UnboundAttribute

A generic interface for objects to write to a buf writer. Do not implement unless necessary, as this writeTo is public, which can be troublesome.

Method Summary

Modifier and TypeMethod and Description
public void

Method Detail

writeToback to summary
public void writeTo(BufWriterImpl writer)
jdk.internal.classfile.impl back to summary

pack-priv Interface Util.WritableLocalVariable

Known Direct Implementers
jdk.internal.classfile.impl.AbstractBoundLocalVariable, jdk.internal.classfile.impl.AbstractPseudoInstruction.AbstractLocalPseudo

Method Summary

Modifier and TypeMethod and Description
public boolean

Method Detail

writeLocalToback to summary
public boolean writeLocalTo(BufWriterImpl buf)