Class BinaryStubData
annotated-jdk.bin.gz)
or the binary form of a built-in checker stub file (*.astub.bin.gz). The binary format
stores annotation information extracted from the stub sources in a compact, pre-parsed form that
is faster to load than the original text stubs.
Instances are immutable after construction and contain no javac objects (only strings and
primitives), so they are cached per JVM and shared across compilations; see
AnnotationFileElementTypes#loadedBinaryStubData.
The binary format consists of a GZIP-compressed stream containing:
- A 4-byte magic number (
0xCF4A444B). - A 2-byte version number.
- A source fingerprint: a 4-byte source length (
-1if none was recorded, as for the annotated JDK and other stub files generated byJavaStubifier), followed, when non-negative, by the 32-byte SHA-256 digest of the source.astubfile's raw bytes. Used only to detect a stale binary for a user-supplied-Astubsfile; seematchesSource(byte[]). - A constant pool of UTF-8 strings (class names, field names, signatures, string literals).
- An annotation pool of structural annotation records.
- A sequence of
BinaryStubData.ClassRecordentries, one per class, interface, enum, annotation type, or record. - Package and module annotation records.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAnnotation data containing its class name and structural element value pairs.static classRepresents a Class literal value.static classAnnotation data for a single class or interface, including its members.static classAnnotation data for a single record component (i.e., one entry in arecord Foo(A a, B b)header).static classRepresents an Enum constant value.static classAnnotation data for a single field.static classAnnotation data for a single method or constructor.static classA simple name that refers to a constant, written'n'.static classAn operation in a constant expression, evaluated where the stub file is read, byAnnotationConstants: a unary operation (written'u'), a binary operation ('b'), a conditional expression ('?'), or a cast ('x').static classRepresents a type annotation with its type path, or a marker for a plain wildcard?(seeBinaryStubData.TypeAnno.UNBOUNDED_WILDCARD).static classAnnotation data for a single type parameter (class-level or method-level).static classA single step in a type-annotation path, describing how to navigate from a base type to the component type that carries the annotation. -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal BinaryStubData.AnnotationRecord[]Pre-parsed structural annotations referenced by indices in the records.static final StringFile-name suffix appended to a source stub file's name to name its binary form (e.g.static final StringFully-qualified name ofCFComment, which is never written to the binary format.final Map<String, BinaryStubData.ClassRecord> Map from fully-qualified class name to its annotation record.static final StringPrefix of the simple signature of a constructor, asElementUtils.getSimpleSignaturewrites it:<init>(...).static final StringFile name of the binary stub file.static final intMagic number identifying the Checker Framework binary stub format.Map from module name to annotation-pool indices of its declaration annotations.Map from fully-qualified package name to annotation-pool indices of its declaration annotations.final byte @Nullable []final intLength in bytes of the source.astubfile this binary was generated from, or-1if no fingerprint was recorded (the annotated JDK, and other binariesJavaStubifierproduces, are never checked for staleness this way: they are regenerated by the same build that packages their text source).final String[]All strings referenced by the binary data.static final shortFormat version of the binary stub file. -
Constructor Summary
ConstructorsConstructorDescriptionReads binary stub data from the given stream. -
Method Summary
Modifier and TypeMethodDescriptionbooleanmatchesSource(byte[] sourceBytes) Returns true if this binary was generated from source bytes identical tosourceBytes.static BinaryStubDataread(InputStream in) Reads binary stub data from the given stream, reporting a damaged file as anIOExceptionregardless of how the damage surfaces.
-
Field Details
-
MAGIC
public static final int MAGICMagic number identifying the Checker Framework binary stub format. Defined once inBinaryStubWriter.MAGIC.- See Also:
-
VERSION
public static final short VERSIONFormat version of the binary stub file. Defined once inBinaryStubWriter.VERSION.- See Also:
-
BIN_SUFFIX
File-name suffix appended to a source stub file's name to name its binary form (e.g.jdk.astub→jdk.astub.bin.gz). Defined once inBinaryStubWriter.BIN_SUFFIX.- See Also:
-
FILENAME
File name of the binary stub file. Defined once inBinaryStubWriter.OUTPUT_FILENAME.- See Also:
-
CONSTRUCTOR_SIG_PREFIX
Prefix of the simple signature of a constructor, asElementUtils.getSimpleSignaturewrites it:<init>(...). Defined once inBinaryStubWriter.CONSTRUCTOR_SIG_PREFIX.- See Also:
-
CF_COMMENT
Fully-qualified name ofCFComment, which is never written to the binary format. Defined once inBinaryStubWriter.CF_COMMENT.Re-exported here so that
BinaryStubDiffChecker, which must filter the same annotation out of the text-parsed side, can name it without depending on the stubifier source set:framework-test, where that class lives, does not have the stubifier on its classpath. This is a compile-time constant, so reading it creates no runtime dependency.- See Also:
-
stringPool
All strings referenced by the binary data.These are not interned. Nothing compares them by reference: class names and signatures are only ever used as map keys or compared with
equals, and the one identity comparison on an annotation name (BinaryStubReader.isAnnotatedForThisChecker) compares the result ofAnnotationUtils.annotationName, which is interned by its own contract, not a string from this pool.Interning them bought nothing and cost most of the load: interning this pool's ~24,000 strings took the annotated JDK's binary stub file from about 20 ms to about 130 ms to load (measured; the cost is the cold string-table insertions). That is once per JVM, since the parsed data is cached in
AnnotationFileElementTypes#loadedBinaryStubData. -
annotationPool
Pre-parsed structural annotations referenced by indices in the records. -
classes
Map from fully-qualified class name to its annotation record. The key uses'.'as separator and covers both top-level classes and inner classes (e.g."com.sun.tools.javac.code.Symbol.Completer"). -
packages
Map from fully-qualified package name to annotation-pool indices of its declaration annotations. -
modules
Map from module name to annotation-pool indices of its declaration annotations. -
sourceLength
public final int sourceLengthLength in bytes of the source.astubfile this binary was generated from, or-1if no fingerprint was recorded (the annotated JDK, and other binariesJavaStubifierproduces, are never checked for staleness this way: they are regenerated by the same build that packages their text source). SeematchesSource(byte[]). -
sourceDigest
-
-
Constructor Details
-
BinaryStubData
Reads binary stub data from the given stream. The stream must supply the GZIP-compressed binary format written byBinaryStubWriter. Preferread(java.io.InputStream), which additionally reports a damaged file's out-of-range pool index as anIOException.- Parameters:
in- the input stream to read from; the stream is closed when this constructor returns- Throws:
IOException- if the stream cannot be read or contains an invalid/unsupported format
-
-
Method Details
-
read
Reads binary stub data from the given stream, reporting a damaged file as anIOExceptionregardless of how the damage surfaces. A damaged file can hold an index that points outside a pool, which this class does not validate (unlike a count; seereadCount(java.io.DataInputStream, java.lang.String)) and which surfaces asArrayIndexOutOfBoundsException; converting it lets the caller fall back to text parsing instead of crashing the compilation.- Parameters:
in- the input stream to read from; the stream is closed when this method returns- Returns:
- the binary stub data read from
in - Throws:
IOException- if the stream cannot be read or contains an invalid/unsupported format
-
matchesSource
public boolean matchesSource(byte[] sourceBytes) Returns true if this binary was generated from source bytes identical tosourceBytes. Always false if no fingerprint was recorded (seesourceLength).- Parameters:
sourceBytes- the current raw bytes of the.astubfile this binary is claimed to correspond to- Returns:
- true if
sourceBytesmatches the fingerprint this binary was generated from
-