Class Indexer
The Indexer operates on input streams that point to class file data. Input streams do not need to be buffered, as the indexer already does this. There is also no limit to the number of class file streams the indexer can process, other than available memory.
The Indexer attempts to minimize the final memory state of the index, but to do this it must maintain additional in-process state (intern tables etc) until the index is complete.
Numerous optimizations are taken during indexing to attempt to minimize the CPU and I/O cost, however, the Java class file format was not designed for partial searching, which ultimately limits the efficiency of processing them.
Thread-Safety This class is not thread-safe can not be shared between threads. The index it produces however is thread-safe.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
private static class
private static class
private static class
private static class
private static class
private static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final byte[]
private static final int
private HashMap
<DotName, List<AnnotationInstance>> private int
private static final byte[]
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private byte[]
private byte[]
private int[]
private ClassInfo
private byte[][]
private ArrayList
<AnnotationInstance> private static final byte[]
private static final int
private static final byte[]
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final byte[]
private static final byte[]
private static final int
private Map
<DotName, Indexer.InnerClassInfo> private static final byte[]
private static final int
private Map
<DotName, List<AnnotationInstance>> private static final byte[]
private static final int
private byte[][]
private List
<MethodInfo> private static final byte[]
private static final int
private static final byte[]
private static final int
private static final byte[]
private static final int
private Map
<DotName, ModuleInfo> private NameTable
private static final byte[]
private static final int
private List
<RecordComponentInfo> private static final byte[]
private static final int
private static final byte[]
private static final int
private static final byte[]
private static final int
private static final byte[]
private static final int
private GenericSignatureParser
private IdentityHashMap
<AnnotationTarget, Object> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addImplementor
(DotName interfaceName, ClassInfo currentClass) private void
addSubclass
(DotName superName, ClassInfo currentClass) private void
private int
bitsToInt
(byte[] pool, int pos) private long
bitsToLong
(byte[] pool, int pos) private ArrayDeque
<Indexer.InnerClassInfo> buildClassesQueue
(DotName name) buildOwnerMap
(Type type) complete()
Completes, finalizes, and returns the index after zero or more calls to index.private static String
convertClassFieldDescriptor
(String descriptor) private ParameterizedType
convertParameterized
(Type oType) private static Type[]
copyTypeParameters
(AnnotationTarget target) private DotName
decodeClassEntry
(int index) private DotName
decodeDotNameEntry
(int index, int constantType, String typeName, char delim) private double
decodeDoubleEntry
(int index) private float
decodeFloatEntry
(int index) private int
decodeIntegerEntry
(int index) private long
decodeLongEntry
(int index) private DotName
decodeModuleEntry
(int index) private Indexer.NameAndType
decodeNameAndTypeEntry
(int index) private String
decodeOptionalUtf8Entry
(int index) private DotName
decodePackageEntry
(int index) private String
decodeUtf8Entry
(int index) private byte[]
decodeUtf8EntryAsBytes
(int index) private static Type[]
getTypeParameters
(AnnotationTarget target) private boolean
hasAnonymousEncloser
(Indexer.TypeAnnotationState typeAnnotationState) index
(InputStream stream) Analyze and index the class file data present in the passed input stream.indexClass
(Class<?> clazz) Analyze and index the class file data present in the passed class.private void
private void
private byte[]
intern
(byte[] bytes) private String
private Type
private Type[]
private boolean
isBridge
(MethodInfo methodInfo) private static boolean
isInnerConstructor
(MethodInfo method) private boolean
isJDK11OrNewer
(DataInputStream stream) private static boolean
match
(byte[] target, int offset, byte[] expected) private void
parseClassSignature
(String signature, ClassInfo clazz) private void
parseFieldSignature
(String signature, FieldInfo field) private Type[]
parseMethodArgs
(String descriptor, Indexer.IntegerHolder pos) private void
parseMethodSignature
(String signature, MethodInfo method) private void
parseRecordComponentSignature
(String signature, RecordComponentInfo recordComponent) private Type
private Type
parseType
(String descriptor, Indexer.IntegerHolder pos) private int
popNestedDepth
(Indexer.PathElementStack elements) private AnnotationInstance
processAnnotation
(DataInputStream data, AnnotationTarget target) private void
processAnnotationDefault
(DataInputStream data, MethodInfo target) private AnnotationValue
processAnnotationElementValue
(String name, DataInputStream data) private void
processAnnotations
(DataInputStream data, AnnotationTarget target) private void
processAttributes
(DataInputStream data, AnnotationTarget target) private void
private void
processCode
(DataInputStream data, MethodInfo target) private boolean
processConstantPool
(DataInputStream stream) private void
processEnclosingMethod
(DataInputStream data, ClassInfo target) private void
processExceptions
(DataInputStream data, MethodInfo target) private void
private void
processInnerClasses
(DataInputStream data, ClassInfo target) private void
processLocalVariableTable
(DataInputStream data, MethodInfo target) private void
private void
processMethodParameters
(DataInputStream data, MethodInfo target) private void
processModule
(DataInputStream data, ClassInfo target) private List
<ModuleInfo.ExportedPackageInfo> private void
processModuleMainClass
(DataInputStream data, ClassInfo target) private List
<ModuleInfo.OpenedPackageInfo> private void
processModulePackages
(DataInputStream data, ClassInfo target) private List
<ModuleInfo.ProvidedServiceInfo> private List
<ModuleInfo.RequiredModuleInfo> private void
private void
processSignature
(DataInputStream data, AnnotationTarget target) private ArrayList
<Indexer.PathElement> processTargetPath
(DataInputStream data, Indexer.BooleanHolder genericsRequired, Indexer.BooleanHolder bridgeIncompatible) private Indexer.TypeAnnotationState
processTypeAnnotation
(DataInputStream data, AnnotationTarget target) private void
processTypeAnnotations
(DataInputStream data, AnnotationTarget target) private Type
rebuildNestedType
(Type type, int depth, Indexer.TypeAnnotationState typeAnnotationState) private void
recordAnnotation
(Map<DotName, List<AnnotationInstance>> classAnnotations, DotName annotation, AnnotationInstance instance) private void
resolveTypeAnnotation
(AnnotationTarget target, Indexer.TypeAnnotationState typeAnnotationState) private void
private Type
resolveTypePath
(Type type, Indexer.TypeAnnotationState typeAnnotationState) private void
private Type
searchNestedType
(Type type, int depth, Indexer.TypeAnnotationState typeAnnotationState) private Type
searchTypePath
(Type type, Indexer.TypeAnnotationState typeAnnotationState) private void
setTypeParameters
(AnnotationTarget target, Type[] typeParameters) private static byte[]
sizeToFit
(byte[] buf, int needed, int offset, int remainingEntries) private boolean
skipBridge
(Indexer.TypeAnnotationState typeAnnotationState, MethodInfo method) private static void
skipFully
(InputStream s, long n) private void
private boolean
targetsArray
(Indexer.TypeAnnotationState typeAnnotationState) private void
updateTypeTarget
(AnnotationTarget enclosingTarget, Indexer.TypeAnnotationState typeAnnotationState) private void
private void
verifyMagic
(DataInputStream stream)
-
Field Details
-
CONSTANT_CLASS
private static final int CONSTANT_CLASS- See Also:
-
CONSTANT_FIELDREF
private static final int CONSTANT_FIELDREF- See Also:
-
CONSTANT_METHODREF
private static final int CONSTANT_METHODREF- See Also:
-
CONSTANT_INTERFACEMETHODREF
private static final int CONSTANT_INTERFACEMETHODREF- See Also:
-
CONSTANT_STRING
private static final int CONSTANT_STRING- See Also:
-
CONSTANT_INTEGER
private static final int CONSTANT_INTEGER- See Also:
-
CONSTANT_FLOAT
private static final int CONSTANT_FLOAT- See Also:
-
CONSTANT_LONG
private static final int CONSTANT_LONG- See Also:
-
CONSTANT_DOUBLE
private static final int CONSTANT_DOUBLE- See Also:
-
CONSTANT_NAMEANDTYPE
private static final int CONSTANT_NAMEANDTYPE- See Also:
-
CONSTANT_UTF8
private static final int CONSTANT_UTF8- See Also:
-
CONSTANT_INVOKEDYNAMIC
private static final int CONSTANT_INVOKEDYNAMIC- See Also:
-
CONSTANT_METHODHANDLE
private static final int CONSTANT_METHODHANDLE- See Also:
-
CONSTANT_METHODTYPE
private static final int CONSTANT_METHODTYPE- See Also:
-
CONSTANT_MODULE
private static final int CONSTANT_MODULE- See Also:
-
CONSTANT_PACKAGE
private static final int CONSTANT_PACKAGE- See Also:
-
CONSTANT_DYNAMIC
private static final int CONSTANT_DYNAMIC- See Also:
-
RUNTIME_ANNOTATIONS
private static final byte[] RUNTIME_ANNOTATIONS -
RUNTIME_PARAM_ANNOTATIONS
private static final byte[] RUNTIME_PARAM_ANNOTATIONS -
RUNTIME_TYPE_ANNOTATIONS
private static final byte[] RUNTIME_TYPE_ANNOTATIONS -
ANNOTATION_DEFAULT
private static final byte[] ANNOTATION_DEFAULT -
SIGNATURE
private static final byte[] SIGNATURE -
EXCEPTIONS
private static final byte[] EXCEPTIONS -
INNER_CLASSES
private static final byte[] INNER_CLASSES -
ENCLOSING_METHOD
private static final byte[] ENCLOSING_METHOD -
METHOD_PARAMETERS
private static final byte[] METHOD_PARAMETERS -
LOCAL_VARIABLE_TABLE
private static final byte[] LOCAL_VARIABLE_TABLE -
CODE
private static final byte[] CODE -
MODULE
private static final byte[] MODULE -
MODULE_PACKAGES
private static final byte[] MODULE_PACKAGES -
MODULE_MAIN_CLASS
private static final byte[] MODULE_MAIN_CLASS -
RECORD
private static final byte[] RECORD -
RUNTIME_ANNOTATIONS_LEN
private static final int RUNTIME_ANNOTATIONS_LEN -
RUNTIME_PARAM_ANNOTATIONS_LEN
private static final int RUNTIME_PARAM_ANNOTATIONS_LEN -
RUNTIME_TYPE_ANNOTATIONS_LEN
private static final int RUNTIME_TYPE_ANNOTATIONS_LEN -
ANNOTATION_DEFAULT_LEN
private static final int ANNOTATION_DEFAULT_LEN -
SIGNATURE_LEN
private static final int SIGNATURE_LEN -
EXCEPTIONS_LEN
private static final int EXCEPTIONS_LEN -
INNER_CLASSES_LEN
private static final int INNER_CLASSES_LEN -
ENCLOSING_METHOD_LEN
private static final int ENCLOSING_METHOD_LEN -
METHOD_PARAMETERS_LEN
private static final int METHOD_PARAMETERS_LEN -
LOCAL_VARIABLE_TABLE_LEN
private static final int LOCAL_VARIABLE_TABLE_LEN -
CODE_LEN
private static final int CODE_LEN -
MODULE_LEN
private static final int MODULE_LEN -
MODULE_PACKAGES_LEN
private static final int MODULE_PACKAGES_LEN -
MODULE_MAIN_CLASS_LEN
private static final int MODULE_MAIN_CLASS_LEN -
RECORD_LEN
private static final int RECORD_LEN -
HAS_RUNTIME_ANNOTATION
private static final int HAS_RUNTIME_ANNOTATION- See Also:
-
HAS_RUNTIME_PARAM_ANNOTATION
private static final int HAS_RUNTIME_PARAM_ANNOTATION- See Also:
-
HAS_RUNTIME_TYPE_ANNOTATION
private static final int HAS_RUNTIME_TYPE_ANNOTATION- See Also:
-
HAS_SIGNATURE
private static final int HAS_SIGNATURE- See Also:
-
HAS_EXCEPTIONS
private static final int HAS_EXCEPTIONS- See Also:
-
HAS_INNER_CLASSES
private static final int HAS_INNER_CLASSES- See Also:
-
HAS_ENCLOSING_METHOD
private static final int HAS_ENCLOSING_METHOD- See Also:
-
HAS_ANNOTATION_DEFAULT
private static final int HAS_ANNOTATION_DEFAULT- See Also:
-
HAS_METHOD_PARAMETERS
private static final int HAS_METHOD_PARAMETERS- See Also:
-
HAS_LOCAL_VARIABLE_TABLE
private static final int HAS_LOCAL_VARIABLE_TABLE- See Also:
-
HAS_CODE
private static final int HAS_CODE- See Also:
-
HAS_MODULE
private static final int HAS_MODULE- See Also:
-
HAS_MODULE_PACKAGES
private static final int HAS_MODULE_PACKAGES- See Also:
-
HAS_MODULE_MAIN_CLASS
private static final int HAS_MODULE_MAIN_CLASS- See Also:
-
HAS_RECORD
private static final int HAS_RECORD- See Also:
-
INIT_METHOD_NAME
private static final byte[] INIT_METHOD_NAME -
constantPool
private byte[] constantPool -
constantPoolOffsets
private int[] constantPoolOffsets -
constantPoolAnnoAttrributes
private byte[] constantPoolAnnoAttrributes -
currentClass
-
classAnnotations
-
elementAnnotations
-
signaturePresent
-
signatures
-
classSignatureIndex
private int classSignatureIndex -
innerClasses
-
typeAnnotations
-
methods
-
fields
-
recordComponents
-
debugParameterNames
private byte[][] debugParameterNames -
methodParameterNames
private byte[][] methodParameterNames -
masterAnnotations
-
subclasses
-
implementors
-
classes
-
modules
-
users
-
names
-
signatureParser
-
-
Constructor Details
-
Indexer
public Indexer()
-
-
Method Details
-
match
private static boolean match(byte[] target, int offset, byte[] expected) -
sizeToFit
private static byte[] sizeToFit(byte[] buf, int needed, int offset, int remainingEntries) -
skipFully
- Throws:
IOException
-
initIndexMaps
private void initIndexMaps() -
initClassFields
private void initClassFields() -
processMethodInfo
- Throws:
IOException
-
processFieldInfo
- Throws:
IOException
-
processRecordComponents
- Throws:
IOException
-
processAttributes
- Throws:
IOException
-
processModule
- Throws:
IOException
-
processModuleRequires
private List<ModuleInfo.RequiredModuleInfo> processModuleRequires(DataInputStream data) throws IOException - Throws:
IOException
-
processModuleExports
private List<ModuleInfo.ExportedPackageInfo> processModuleExports(DataInputStream data) throws IOException - Throws:
IOException
-
processModuleOpens
private List<ModuleInfo.OpenedPackageInfo> processModuleOpens(DataInputStream data) throws IOException - Throws:
IOException
-
processModuleUses
- Throws:
IOException
-
processModuleProvides
private List<ModuleInfo.ProvidedServiceInfo> processModuleProvides(DataInputStream data) throws IOException - Throws:
IOException
-
processModulePackages
- Throws:
IOException
-
processModuleMainClass
- Throws:
IOException
-
processCode
- Throws:
IOException
-
processAnnotationDefault
- Throws:
IOException
-
processAnnotations
- Throws:
IOException
-
processInnerClasses
- Throws:
IOException
-
processMethodParameters
- Throws:
IOException
-
processLocalVariableTable
- Throws:
IOException
-
processEnclosingMethod
- Throws:
IOException
-
processTypeAnnotations
private void processTypeAnnotations(DataInputStream data, AnnotationTarget target) throws IOException - Throws:
IOException
-
processTypeAnnotation
private Indexer.TypeAnnotationState processTypeAnnotation(DataInputStream data, AnnotationTarget target) throws IOException - Throws:
IOException
-
resolveTypeAnnotations
private void resolveTypeAnnotations() -
resolveUsers
- Throws:
IOException
-
updateTypeTargets
private void updateTypeTargets() -
getTypeParameters
-
copyTypeParameters
-
setTypeParameters
-
isInnerConstructor
-
resolveTypeAnnotation
private void resolveTypeAnnotation(AnnotationTarget target, Indexer.TypeAnnotationState typeAnnotationState) -
skipBridge
-
isBridge
-
targetsArray
-
resolveTypePath
-
popNestedDepth
-
updateTypeTarget
private void updateTypeTarget(AnnotationTarget enclosingTarget, Indexer.TypeAnnotationState typeAnnotationState) -
searchTypePath
-
rebuildNestedType
private Type rebuildNestedType(Type type, int depth, Indexer.TypeAnnotationState typeAnnotationState) -
convertParameterized
-
searchNestedType
private Type searchNestedType(Type type, int depth, Indexer.TypeAnnotationState typeAnnotationState) -
hasAnonymousEncloser
-
buildClassesQueue
-
buildOwnerMap
-
processTargetPath
private ArrayList<Indexer.PathElement> processTargetPath(DataInputStream data, Indexer.BooleanHolder genericsRequired, Indexer.BooleanHolder bridgeIncompatible) throws IOException - Throws:
IOException
-
skipTargetPath
- Throws:
IOException
-
processExceptions
- Throws:
IOException
-
processSignature
- Throws:
IOException
-
parseClassSignature
-
applySignatures
private void applySignatures() -
parseFieldSignature
-
parseMethodSignature
-
parseRecordComponentSignature
-
processAnnotation
private AnnotationInstance processAnnotation(DataInputStream data, AnnotationTarget target) throws IOException - Throws:
IOException
-
recordAnnotation
private void recordAnnotation(Map<DotName, List<AnnotationInstance>> classAnnotations, DotName annotation, AnnotationInstance instance) -
intern
-
intern
private byte[] intern(byte[] bytes) -
intern
-
intern
-
processAnnotationElementValue
private AnnotationValue processAnnotationElementValue(String name, DataInputStream data) throws IOException - Throws:
IOException
-
processClassInfo
- Throws:
IOException
-
addSubclass
-
addImplementor
-
isJDK11OrNewer
- Throws:
IOException
-
verifyMagic
- Throws:
IOException
-
decodeClassEntry
- Throws:
IOException
-
decodeModuleEntry
- Throws:
IOException
-
decodePackageEntry
- Throws:
IOException
-
decodeDotNameEntry
private DotName decodeDotNameEntry(int index, int constantType, String typeName, char delim) throws IOException - Throws:
IOException
-
decodeOptionalUtf8Entry
- Throws:
IOException
-
decodeUtf8Entry
- Throws:
IOException
-
decodeUtf8EntryAsBytes
private byte[] decodeUtf8EntryAsBytes(int index) -
decodeNameAndTypeEntry
- Throws:
IOException
-
bitsToInt
private int bitsToInt(byte[] pool, int pos) -
bitsToLong
private long bitsToLong(byte[] pool, int pos) -
decodeIntegerEntry
private int decodeIntegerEntry(int index) -
decodeLongEntry
private long decodeLongEntry(int index) -
decodeFloatEntry
private float decodeFloatEntry(int index) -
decodeDoubleEntry
private double decodeDoubleEntry(int index) -
convertClassFieldDescriptor
-
parseMethodArgs
-
parseType
-
parseType
-
processConstantPool
- Throws:
IOException
-
indexClass
Analyze and index the class file data present in the passed class. Each call adds information to the final complete index; however, to aid in processing a per-class index (ClassInfo) is returned on each call.- Parameters:
clazz
- a previously-loaded class- Returns:
- a class index containing all annotations on the passed class stream
- Throws:
IOException
- if the class file data is corrupt or the underlying stream failsIllegalArgumentException
- if clazz is null
-
index
Analyze and index the class file data present in the passed input stream. Each call adds information to the final complete index; however, to aid in processing a per-class index (ClassInfo) is returned on each call.- Parameters:
stream
- a stream pointing to class file data- Returns:
- a class index containing all annotations on the passed class stream
- Throws:
IOException
- if the class file data is corrupt or the underlying stream failsIllegalArgumentException
- if stream is null
-
complete
Completes, finalizes, and returns the index after zero or more calls to index. Future calls to index will result in a new index.- Returns:
- the master index for all scanned class streams
-