← ART image
ART·Format guide
All tools

ART images (.art)

An ART image is a snapshot of part of the Android runtime's heap, written by dex2oat when it compiles code ahead of time. At start-up the runtime maps it instead of loading, linking and initializing the classes again. It goes with an OAT file (.oat or .odex, an ELF holding the compiled code) and a VDEX file (verification data, and in older releases the DEX files themselves).

Contents

  1. The image header
  2. Blocks, compression and the version-120 trailer
  3. Sections
  4. Objects: mirror::Object, Class, String, arrays, DexCache
  5. Native data: ArtMethod, ArtField, IMTs, tables, the bitmap
  6. Image roots and image methods
  7. Versions and what was checked
  8. What to look for
  9. What the tool shows, and its limits
  10. The ArtImage library

2Blocks, compression and the version-120 trailer

The data after the header is stored in blocks, each described by 20 bytes: storage_mode (0 uncompressed, 1 LZ4, 2 LZ4HC), data_offset and data_size in the file, image_offset and image_size in the image. LZ4 and LZ4HC are the same raw block format (HC searches harder); each block is decompressed on its own, so the runtime can do it in parallel. The block table follows the data, aligned to 4. An uncompressed image has no blocks: the file is mapped as is. Boot images in the samples are one LZ4HC block, app images one LZ4 block.

After the data, aligned to 16 KB (the ELF segment alignment), comes the image bitmap. The file ends there.

Version 120. The samples have a 29-byte trailer right after the block table, at the offset the header gives at 0x40: a 32-bit 1 and the byte 0x2a (not understood), then 32-bit words: a base (0x90) to add to the blocks' data offsets to get file offsets, the block table's offset and count, the data size, the bitmap's file offset and its size. The header's bitmap section has offset 0. Decompressed, the block starts at image offset 0x78, so the objects start there; the first 0x78 bytes of the image (the header's place in memory) are not stored, and the tool leaves them as zeros.

3Sections

SectionWhat it holds
Objectsthe Java objects, from offset 0 (the header's place) to the end of the last object
ArtFieldsthe classes' field arrays
ArtMethodsthe classes' method arrays (clean ones first, then those the runtime writes to)
ImTablesinterface method tables: 43 method pointers each
IMTConflictTablesfor IMT slots shared by several interface methods: (interface method, implementation) pairs ending with a null pair
RuntimeMethodsArtMethods the runtime makes (the image methods, one IMT conflict method per conflict table)
JniStubMethodsJNI stubs shared by native methods with the same shorty
InternedStringsthe intern table: a serialized HashSet of String references
ClassTablethe class table: a serialized HashSet of class references (low 3 bits: hash bits)
StringReferenceOffsetsapp images: (object offset, field offset) pairs of references to strings, to intern at load
DexCacheArraysempty in the images dex2oat writes
Metadataapp images: GC roots referred to by compiled code
ImageBitmapin the file, after the data: one bit for each 8 bytes of the objects section, set where an object starts

The order changed over time: Android 10 and 11 put RuntimeMethods before ImTables and have DexCacheArrays after IMTConflictTables; Android 12 and 13 have no DexCacheArrays; Android 14 puts it after StringReferenceOffsets; Android 15 and later have the order above, with JniStubMethods.

4Objects: mirror::Object, Class, String, arrays, DexCache

Every object starts with an 8-byte mirror::Object header: a 32-bit reference to its class and a 32-bit lock word; objects are 8-byte aligned. Fields follow in the order of ClassLinker::LinkFields: references first, then 64-, 32-, 16- and 8-bit fields, each alphabetically.

ObjectLayout (byte offsets)
String8 count_: the length shifted left by one, the low bit 0 when the characters are compressed (one Latin-1 byte each) and 1 for UTF-16; 12 hash_code_; 16 the characters
arrays8 the length; the elements at 12, or 16 for 8-byte elements
DexCache8 class loader, 12 location (a String: the JAR or APK, with !1, !2… for its other DEX files), then 64-bit native pointers (dex file, resolved arrays)
Class8 class_loader_, 12 component_type_, 16 dex_cache_, 20 ext_data_, 24 iftable_, 28 name_, 32 super_class_, 36 vtable_, 40 fields_ (64-bit pointer to an ArtField array), 48 methods_ (an ArtMethod array), 56 access_flags_, 60 class_flags_, 64 class_size_, 68 clinit_thread_id_or_hash_, 72 dex_class_def_idx_, 76 dex_type_idx_, then (v119) 80 num_reference_instance_fields_, 84 num_reference_static_fields_, 88 object_size_, 92 object_size_alloc_fast_path_, 96 primitive_type_ (low 16 bits the type, high 16 the size shift), 100 reference_instance_offsets_, 104 status_ (the class status in its top 4 bits); then the embedded vtable length, the IMT pointer, the vtable and the static fields

Version 120 has one more 32-bit word at 80 (its meaning is not known: small numbers, often 0xffffffff); the fields after it move by 4, so the status is at 108. This was checked on the samples: reference counts, object sizes, the status of every class and the primitive types of the class roots come out right. The class status: 0 not ready … 7 resolved, 8 verifying, 9 retry verification at runtime, 10 verified needing access checks, 11 verified, 12 superclass validated, 13 initializing, 14 initialized, 15 visibly initialized.

A class's name is rarely in the image: name_ is set only when the runtime computed it. Otherwise the class is named by its dex cache (which DEX file) and dex_type_idx_ (which type of it), and the DEX file is needed — in the APK or the JAR, since the samples' .vdex files hold no DEX section.

5Native data: ArtMethod, ArtField, IMTs, tables, the bitmap

StructureLayout
LengthPrefixedArraya 32-bit length, then the elements, aligned to their alignment (4 for ArtField, the pointer size for ArtMethod)
ArtField (16 bytes)0 declaring class, 4 access flags, 8 field index in the DEX file, 12 offset in the object (or in the class, for static fields)
ArtMethod (16 + 2 pointers)0 declaring class, 4 access flags, 8 method index in the DEX file, 12 method index (vtable slot), 14 hotness count or IMT index, then two pointers: data_ (a native method's JNI function, else the code item's offset in the DEX file) and the entry point of compiled code
HashSet (intern table, class table)three 64-bit counts (elements, buckets, elements until it grows), two doubles (load factors), then one 32-bit entry per bucket (0 = empty)
bitmapbit n of byte k marks an object at offset (8·k + n)·8

Entry points shared by thousands of methods are stubs: the interpreter and nterp bridges, the resolution trampoline (for static methods of classes not yet initialized), the generic JNI trampoline. They are in the boot image's OAT file. A method whose entry point is elsewhere in its own OAT data was compiled ahead of time.

6Image roots and image methods

The image roots are an Object[] of three: the dex caches (one per DEX file of the component), the class roots (an array of the classes the runtime needs by index: java.lang.Class, Object, String, DexCache, the reflection and invoke classes, the primitive arrays and primitive types — 54 in android17-release, 55 in version 120, where the extra one is at index 44, a core-libart class whose name isn't in the samples), and a third root: in a boot image, the objects kept alive (pre-allocated OutOfMemoryErrors, NoClassDefFoundError, the cleared-weak-reference sentinel, then the boxed values of the intrinsics' caches), in an app image, the class loader (a PathClassLoader).

The image methods are the resolution method, the IMT conflict and unimplemented methods, and the callee-save methods (save-all, save-refs-only, save-refs-and-args, save-everything, for clinit and for suspend checks) that describe the frames of runtime calls. Extensions and app images point to the boot image's.

7Versions and what was checked

VersionReleaseHow it is read
043, 056Android 8, 9not read (one storage mode in the header, no blocks)
074, 085Android 10, 11header, blocks, bitmap, strings and tables from AOSP source; no sample
099, 106, 108, 111, 118Android 12 / 12L, 13, 14, 15, 16the same; versions between the tags (ART module updates) take the layout of the release before
119Android 17 (AOSP android-17.0.0_r1)header from source; object layouts from source (android17-release); no sample
120Android 17 (a newer ART module; API 37 emulator)header, trailer and object layouts observed on 15 boot image components and 2 app images (arm64)

Checks on the version-120 samples: every block decompresses to its size; the method and field arrays of the classes cover their sections to the byte; the hash sets hold the number of elements they declare; the OAT checksums match the .oat / .odex files; the boot image checksum of the extension and of the app images equals the XOR of the primary images' checksums. Not checked: the image checksum (the exact bytes it covers in v120 are not known), 32-bit images, and every version but 120.

8What to look for

9What the tool shows, and its limits

The overview (kind, version and release, component, addresses, storage, what deserves attention, a map of the file and one of the decompressed image), the header and the v120 trailer, the sections, the blocks, the image methods, the roots, the classes (searchable, with status and counts, and their methods and fields), the ArtMethods (searchable: class, name, flags, entry point), the ArtFields, every String (searchable, with a filter for addresses, hosts, keys and paths) and the objects by class. Buttons open the decompressed image or the file in the Hex tool, and the paired .oat / .odex in the OAT tool.

Drop several files at once: the boot image's .art files (an app image's references to boot classes then get named, and the boot checksum is checked), the .oat / .odex (paired by checksum or by name), the APK or JARs, .dex or .vdex files (their DEX files name the classes, methods and fields, matched to the dex caches by the archive's name or the image's).

Limits: without the DEX files most classes are type numbers; object fields other than those of classes, strings, arrays and dex caches are not decoded; the word at Class +80 and the trailer's first bytes of version 120 are not understood; versions before 120 have not been tried on files.

10The ArtImage library

lib/runtime/art-image.js, no user interface; it imports lib/compression/lz4.js.

import { ArtImage } from "../lib/runtime/art-image.js";
MemberWhat it is
ArtImage.parse(bytes, { limit, bootImages, dexFiles, name })Reads an image; throws only when the bytes are not an ART image. limit caps the decompressed size (512 MB). bootImages: other parsed images, to name what this one points to and check the boot checksum. dexFiles: DexFiles (lib/dex.js) of the dex caches, in multidex order. name: the image's name when other images refer to it.
image.header{ magic, version, layout, headerSize, imageReservationSize, componentCount, imageBegin, imageSize, imageChecksum, oatChecksum, oatFileBegin, oatDataBegin, oatDataEnd, oatFileEnd, bootImageBegin, bootImageSize, bootImageComponentCount, bootImageChecksum, imageRoots, pointerSize, dataSize, blocksOffset, blocksCount, imageKindField, trailer }; layout is "observed-120" or "source"
image.kind · image.release · image.storage"boot image", "boot image extension" or "app image"; the Android release; "LZ4HC"…
image.sections · image.blocks · image.bitmap[{ index, name, offset, size, description }]; [{ storageMode, storageName, dataOffset, dataSize, imageOffset, imageSize, error }]; { offset, size } in the file
image.data · image.objectsthe decompressed image (Uint8Array; offset 0 = imageBegin); { count, offsets } (Uint32Array of the objects' image offsets, from the bitmap)
image.imageMethods · image.roots[{ name, address, where }]; { address, length, dexCaches: [{ address, location, classLoader, dexFileIndex, classes }], classRoots: { address, length, inImage, classes: [{ index, name, address }], reference }, special: { address, kind, descriptor, objects, parent, parentText, reference } }
image.classes[{ address, offset, descriptor, descriptorSource, status, statusName, accessFlags, classFlags, dexCache, location, dexTypeIndex, dexClassDefIndex, superClass, componentType, classLoader, nameString, objectSize, classSize, primitiveType, componentSizeShift, unknownField, fieldsAddress, fieldCount, methodsAddress, methodCount, instances, instanceBytes, inClassTable }]
image.methods · image.runtimeMethods[{ address, offset, declaringClass, className, owner, accessFlags, dexMethodIndex, methodIndex, hotnessOrImtIndex, data, entryPoint, entry: { where, offset, text }, name, proto }]
image.fields[{ address, offset, declaringClass, className, accessFlags, fieldDexIndex, fieldOffset, name, type }]
image.stringsevery String object: [{ address, offset, length, compressed, hash, value, interned }]
image.internTables · image.classTables · image.classTableEntriesthe hash sets [{ offset, elements, buckets, elementsUntilExpand, minLoadFactor, maxLoadFactor, entries }]; the class table's [{ address, hashBits, external }]
image.objectCounts · image.entryPoints · image.stringReferences[{ classAddress, descriptor, count, bytes }]; the entry points several methods share [{ address, count, where, offset, text }]; [{ objectOffset, fieldOffset, address, value }]
image.imTables · image.conflictTables · image.layoutChecked · image.bootImageCheck · image.problemstable counts; whether the object layouts were read (versions 119, 120); { primaries, components, checksum, matches }; what is wrong or wasn't read
image.classAt(address) · image.stringAt(address) · image.descriptorOf(address) · image.describeAddress(address)a class or string of this image or a boot image given; a class's descriptor or a reference text ("<type #12 of core-oj.jar>", "<class at boot image range +0x55028>"); where an address points: { where, offset, text }
ArtImage.isArtImage(bytes) · ArtImage.findOatHeader(bytes) · ArtImage.releaseOf(version) · ArtImage.accessFlagsText(flags, kind)the magic check; the OatHeader { offset, version, checksum } in an .oat / .odex; the release of a version; flags as words (kind "class", "method", "field")
const boot = ArtImage.parse(bootArtBytes, { name: "boot.art" });
const app = ArtImage.parse(appArtBytes, { bootImages: [boot], dexFiles: [DexFile.open(classesDex)] });
const urls = app.strings.filter(string => /https?:\/\//.test(string.value));
const compiled = app.methods.filter(method => method.entry.where === "oat");
const oat = ArtImage.findOatHeader(odexBytes);
const paired = oat && oat.checksum === app.header.oatChecksum;