← OAT & ODEX
OAT·Format guide
All tools

OAT, ODEX and VDEX: Android's compiled code

Android apps ship Dalvik bytecode (DEX). Since Android 5 the ART runtime compiles part or all of it ahead of time with dex2oat, into an OAT file: an ELF shared object holding the native code and the tables ART needs to use it. Since Android 8 the DEX files (or their checksums) and the verification results go in a companion VDEX file. Before ART, Dalvik's dexopt wrote an optimized DEX, also called .odex but a different format (section 12).

Contents

  1. The ELF file and its symbols
  2. The OatHeader
  3. The key-value store
  4. OatDexFile records and the DEX files
  5. OatClass: class status and compiled methods
  6. Method headers and CodeInfo
  7. .bss slots and boot image references
  8. Reading the ARM64 code
  9. VDEX and DEX containers
  10. The mini debug info
  11. Versions: what was checked
  12. Dalvik's optimized DEX (dey)
  13. What to look for
  14. What the tool shows, and its limits
  15. The OatFile and VdexFile library
  16. The DalvikOdex library

1The ELF file and its symbols

An OAT file is an ELF shared object (ET_DYN) for the device's instruction set. It exports a handful of dynamic symbols that mark its parts; ART finds them with dlsym (or its own ELF loader):

SymbolSectionWhat starts there
oatdata.rodataThe OatHeader, the key-value store, the OatDexFile records, the class tables, the .bss mappings and every method's CodeInfo. Every OAT offset counts from here.
oatexec · oatlastword.textThe native code (and the trampolines of boot.oat, the thunks); oatlastword is its last 4 bytes.
oatdataimgrelro · oatdataimgrelroappimage · oatdataimgrelrolastword.data.img.rel.ro32-bit references into the boot image (and, after …appimage, into the app image), relocated when the file is loaded, then read-only.
oatbss · oatbssmethods · oatbssroots · oatbssstrings · oatbsslastword.bssSlots filled at run time: ArtMethod*, then GC roots of classes, then strings (section 7).
oatdex · oatdexlastword.dexAndroid 10–16 only: a VDEX embedded in the OAT file.

A .gnu_debugdata section usually follows: the mini debug info (section 10).

3The key-value store

NUL-terminated keys and values. Since about version 26x, the values that differ between build hosts (dex2oat-cmdline, apex-versions) are padded with NULs to a fixed length (2048, 1024) and left out of the checksum, so that the same input gives the same file everywhere (cloud compilation). Only boot.oat carries it among the boot image's components.

KeyMeaning
compiler-filterverify (no code: classes verified only), speed-profile (the profile's hot and startup methods), speed, everything, space(-profile), assume-verified; Android 8–11 also had quicken and extract.
compilation-reasoninstall, bg-dexopt, first-boot, boot-after-ota, cmdline (adb shell cmd package compile), prebuilt (built with the system image), install-dm…
classpathThe class loader context: PCL[a.jar*checksum:…]{shared libraries};parent… (PCL PathClassLoader, DLC DelegateLastClassLoader, IMC InMemoryDexClassLoader). At run time the app's actual class loaders must match or the code is ignored.
bootclasspath · bootclasspath-checksumsThe boot class path the code was compiled against, and the checksums of its boot image (i;components/checksum) or DEX files.
debuggable · native-debuggableCompiled for a debuggable app or runtime. ART forces verify for debuggable apps: the four app samples, asked for speed, speed-profile, verify and everything, all came out verify.
concurrent-copying · requires-image · enable-profile-code · assume-value-sdk-intThe GC the code is built for · the code needs a boot / app image · the code records a profile · the SDK level folded into the code.
dex2oat-cmdline · apex-versionsThe command line (empty in the samples) · the APEX module versions.

4OatDexFile records and the DEX files

One record per DEX file, at oat_dex_files_offset (right after the header before 8.1). Version 281:

FieldNotes
u32 location size, location/system/framework/services.jar, then …services.jar!1, !2 for the next DEX files (older releases: !classes2.dex)
8-byte DEX magic (15+)dex\n041
u32 checksumThe location checksum: the CRC-32 of the classes*.dex ZIP entry. The DEX files of one version-41 container share it.
20-byte SHA-1 (15+)The DEX header's signature
u32 dex_file_offsetFrom the start of the VDEX (Android 8+; before, of oatdata). 0: the DEX stays in the APK / JAR (system jars ship uncompressed DEX files).
u32 class_offsets_offsetAn array of one OatClass offset per class definition
u32 lookup_table_offsetThe type lookup table (in the VDEX since 12)
u32 dex_profile_metadata (17; layout sections 8.1–16)Startup / layout information
6 × u32 .bss mappingsmethod, type, public type, package type, string, method type (3 in 9–11, 5 in 12–14)

The tool checks each record's checksum against the VDEX checksum section and the ZIP entry's CRC-32, and its SHA-1 against the DEX given: a mismatch means the DEX isn't the one the code was compiled from (ART would reject the OAT file).

5OatClass: class status and compiled methods

Each class definition has an OatClass: u16 status, u16 type (0 all compiled, 1 some compiled, 2 none compiled); unless none, a u32 method count (Android 12+; before, "all compiled" took it from the DEX and "some compiled" started with the bitmap's size in bytes); for "some compiled" a bitmap of the methods that have code; then one u32 code offset (OatMethodOffsets) per compiled method. Methods are numbered in the DEX class data's order: direct methods, then virtual methods.

The status is how far dex2oat got: verified (no verification at run time), verified (needs access checks), retry verification at run time (a failure, often a missing class), up to initialized / visibly initialized for boot image classes. Statuses were signed before Android 9 (−3 retired … 10 initialized).

6Method headers and CodeInfo

The code offset points at the code; an OatQuickMethodHeader is just before it. Since Android 15 it is one u32: how far back the method's CodeInfo is (12–14: the same with flag bits; 10–11: vmap offset and code size; 8–9: vmap and method info offsets, frame size, spill masks, code size).

CodeInfo is bit-packed: 7 "interleaved varints" (4-bit fields first; 0–11 is the value, 12–15 mean 1–4 bytes follow) — flags (inline info, should-deoptimize, baseline, debuggable), code size, frame size / 16, core and FP spill masks, dex register count, and which bit tables are present or deduplicated. Then up to 8 bit tables: stack maps, register masks, stack masks, inline infos, method infos, dex register masks, maps and catalogue. Each is a header (row count, the bit width of each column) and the rows; values are stored plus one (0 = none); a deduplicated table is a varint pointing back at an identical one.

A stack map row: kind (default, catch, OSR, debug), native pc / 4 (arm64), dex pc, and indexes into the other tables. It exists wherever the runtime may look at the frame (after a call, at a check that can throw): it is the native pc ↔ dex pc mapping debuggers, exceptions and deoptimization use. The tool decodes the header and the stack maps (Android 12+), and counts the rows of the other tables.

7.bss slots and boot image references

Compiled code doesn't embed pointers to classes, strings or methods resolved at run time: it loads them from a .bss slot (adrp x0, page; ldr w0, [x0, #off]), which the runtime fills on first use. Each OatDexFile's IndexBssMapping lists { index_and_mask, bss_offset } entries: the low bits (enough for the largest index) are a DEX index, its slot at bss_offset; each set bit of the mask above maps a smaller index to the slot just before. Slots are 8 bytes for ArtMethod*, 4 for GC roots. With the DEX, the tool names the string, type or method behind each slot the code reads. The BCP BSS info does the same for the boot class path's DEX files (an app's references to framework classes).

References to objects already in the boot image go through .data.img.rel.ro: 32-bit addresses relocated when the file is loaded.

8Reading the ARM64 code

9VDEX and DEX containers

VDEX 027 (Android 12+): vdex 027\0, the section count, then { kind, offset, size }: 0 checksums (one u32 per DEX), 1 DEX files (empty when they stay in the APK / JAR — the boot image and system jars), 2 verifier dependencies, 3 type lookup tables. Older VDEX (006–021) had a fixed header and quickened DEX files.

DEX 041 (Android 15+) puts several DEX files in one classes.dex, a container: each header adds container_size and header_offset, and its offsets count from the container's start, so they share one string data area. services.jar's classes.dex holds three. The library splits a container into DEX files the DEX reader accepts.

10The mini debug info

.gnu_debugdata is an xz-compressed ELF with only a .symtab and .debug_frame: "MiniDebugInfo", so that native stack traces and profilers name compiled Java code. Its function symbols are package.Class.method (no signature; [DEDUPED] … for shared code), art_jni_trampoline for JNI stubs, and the trampolines' and thunks' names. Without the DEX, the tool names the compiled methods from it. In the samples every compiled method has a symbol, and the 3,150 non-JNI names of services.odex match the DEX's.

11Versions: what was checked

OAT versionReleaseStatus in this reader
281Android 17 (API 37), later than the 17.0.0_r1 tagChecked against the samples: 15 boot image components, services, am, abx, CredentialManager, NexusLauncherRelease, a debuggable app (VDEX 027, DEX 037 and 041)
275 · 259 · 24417 · 16 · 15From the AOSP sources at the tags (275 and 259 share 281's layout but one header field; 244 lacks base_oat_offset)
230 · 225 · 19514 · 13 · 12From source: packed method header, 5 .bss mappings, no DEX magic / SHA-1
183 · 17011 · 10From source; CodeInfo isn't decoded (its header has no code size; the method header has it)
138 · 131 · 1249 · 8.1 · 8.0From source; "all compiled" classes need the DEX for their method count; VDEX 006–019 are only scanned for DEX files
079 · 0647.0 · 6.0From source: the DEX is inside the OAT file; 6.0's class offsets are inline

Versions between tags (development builds, ART module updates through Google Play since Android 12) use the older tag's layout, after the checks of section 2. Instruction sets other than arm64 are parsed but not disassembled.

12Dalvik's optimized DEX (dey)

Before ART (Android 4.4 and earlier), dexopt wrote an optimized DEX: in /data/dalvik-cache/, or as .odex next to a "deodexed" system jar or APK. Layout (platform/dalvik, android-4.4_r1, libdex/DexFile.h and vm/analysis/DexPrepare.cpp):

PartContents
DexOptHeader (40 bytes)magic dey\n036\0 (035 before), dex offset and length, deps offset and length, opt offset and length, flags (bit 1 big-endian), the Adler-32 of deps + opt
the DEXWith quickened instructions (iget-quick, invoke-virtual-quick, execute-inline…) tied to the device's boot class path
dependencies (8-aligned)Source modification time and CRC-32, DALVIK_VM_BUILD (27), the count, then for each boot class path entry its dalvik-cache name and the SHA-1 of its DEX
opt chunks (8-aligned){ type, size } then the data padded to 8: CLKP the class lookup hash table (descriptor hash ×31, twice as many slots as classes), RMAP register maps for the precise GC (per class, per method: format none / compact8 / compact16 / differential), AEND

No real sample was available. The test fixtures (tests/build-dalvik-odex-fixtures.py) wrap an unmodified DEX of tests/data/dex in this layout, with a real class lookup table, invented register maps and dependencies; the reader is checked against them only.

13What to look for

14What the tool shows, and its limits

Drop the .oat / .odex alone, or with its .vdex (and the .apk / .jar) at the same time: Overview (release guessed from the version, instruction set, filter, flags, the class loader context, the command line, what deserves attention, a byte map of the ELF sections and OAT parts, buttons to the ELF, Hex and DEX tools), Key-value store, DEX files (checksums and their checks, the VDEX), Classes (status, compile type; filterable), Compiled methods (searchable by name or address), Code (the ARM64 disassembly with calls, thunks and .bss slots named; the stack maps; the method's DEX bytecode), Header (fields, trampolines, symbols, sections). A Dalvik .odex shows its header, dependencies and chunks; a .vdex alone its sections.

15The OatFile and VdexFile library

lib/runtime/oat.js has no user interface; it imports lib/elf.js, lib/dex.js, lib/arm64-disasm.js, lib/compression/zip.js and lib/compression/xz.js. Parsing is asynchronous (the ELF and ZIP readers are).

import { OatFile, VdexFile } from "../lib/runtime/oat.js";
MemberWhat it is
await OatFile.parse(bytes, { vdex, archive, dexFiles, fileName })Reads an OAT / ODEX (throws if it isn't one). vdex: the companion's bytes; archive: the .apk / .jar (bytes or Blob); dexFiles: [{ name, buffer, crc }].
oat.header{ version, versionNumber, checksum, instructionSet, instructionSetName, instructionSetFeatures, featureNames, dexFileCount, oatDexFilesOffset, bcpBssInfoOffset, baseOatOffset, executableOffset, unknownField281, trampolines: [{ key, name, offset, address }], keyValueStoreSize, size, layout }
oat.keyValues · oat.value(key)[{ key, value, offset }]; one value or null
oat.release · oat.profile{ android, api, exact, note }; what the version implies (record fields, method header, CodeInfo)
oat.symbols · oat.baseThe oat* dynamic symbols { name, address, size, fileOffset }; oatdata's address and file offset
oat.dexFilesOatDexFile records: { index, location, magic, checksum, sha1, dexOffset, classOffsetsOffset, lookupTableOffset, profileMetadataOffset, layoutSectionsOffset, bssMappings, source, dex (a DexFile or null), dexName, checks: { vdexChecksum, archiveCrc, sha1 }, classCount, classCountEstimated }
oat.classes[{ dexIndex, classIndex, descriptor, offset, status, statusName, type, typeName, methodCount, compiledCount, bitmap }]
oat.methods[{ index, dexIndex, classIndex, classMethodIndex, methodIdx, className, name, proto, debugName, access, codeOffset, address, fileOffset, codeSize, codeInfoOffset, frameSize, coreSpillMask, fpSpillMask, codeInfoFlags, sharedCode }]
oat.codeInfo(method){ flags, flagNames, codeSize, frameSize, coreSpillMask, fpSpillMask, dexRegisters, tableRows, stackMaps: [{ kind, nativePc, dexPc, inlineInfoIndex }] }
oat.instructions(method, cap)ARM64 disassembly [{ address, word, mn, ops, target, comment, method, bss }]
oat.describeAddress(address) · oat.bssSlotAt(address) · oat.methodName(method)What is at an address (method, trampoline, thunk, .bss slot, boot image reference); a .bss slot's DEX index and text; a method's full name
oat.debugSymbols · oat.bcpBss · oat.vdex · oat.elf · oat.stats · oat.notes · oat.problemsMini debug info symbols; BCP BSS info; the VdexFile; the ElfFile; counts; what deserves attention; what is wrong
OatFile.isOat(bytes) · OatFile.releaseFor(version)An ELF with an OAT header; the Android release of an OAT version
VdexFile.parse(bytes){ version, sections: [{ kind, name, offset, size }], checksums, dexFiles: [{ offset, size, version, containerOffset, containerSize }], problems }
VdexFile.dexFilesIn(bytes, start, end) · VdexFile.dexBuffer(bytes, entry)The DEX files in a region (splitting version-41 containers); an ArrayBuffer of one for DexFile.open
const oat = await OatFile.parse(odexBytes, { vdex: vdexBytes, archive: jarBytes });
console.log(oat.header.version, oat.value("compiler-filter"), oat.methods.length);
const method = oat.methods.find(candidate => candidate.name === "onCreate");
for (const line of oat.instructions(method)) {
	console.log(line.address.toString(16), line.mn, line.ops, line.comment || "");
}
const stackMaps = oat.codeInfo(method).stackMaps;   // [{ kind, nativePc, dexPc }]

16The DalvikOdex library

lib/runtime/dalvik-odex.js: no dependencies, synchronous.

import { DalvikOdex } from "../lib/runtime/dalvik-odex.js";
MemberWhat it is
DalvikOdex.isOdex(bytes) · DalvikOdex.parse(bytes)A dey\n file; read it (throws if it isn't one)
odex.header{ dexOffset, dexLength, depsOffset, depsLength, optOffset, optLength, flags, flagNames, checksum, computedChecksum, checksumValid }
odex.dependencies{ modificationTime, crc, vmBuild, entries: [{ name, sha1 }] }
odex.chunks · odex.classLookup · odex.registerMaps[{ type, typeName, offset, size }]; { numEntries, used, entries: [{ slot, hash, descriptor, classDefOffset, hashValid }] }; { numClasses, classesWithMaps, maps, formats, classes }
odex.dex · odex.problemsThe embedded DEX (a view: DexFile.open(odex.dex.slice().buffer)); what is wrong
DalvikOdex.adler32(bytes, start, end) · DalvikOdex.descriptorHash(text)The checksum and the class lookup hash