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).
- The boot image:
/apex/com.android.art/javalib/arm64/boot.oat, /system/framework/arm64/boot-framework.oat… one boot*.oat, .vdex and .art (the heap image) per boot class path jar.
- System jars and apps:
/system/framework/oat/arm64/services.odex, an app's /data/app/…/oat/arm64/base.odex and base.vdex (and base.art, the app image, with speed-profile).
- dalvik-cache:
/data/dalvik-cache/arm64/ holds what was compiled on the device for files without a prebuilt one.
Contents
- The ELF file and its symbols
- The OatHeader
- The key-value store
- OatDexFile records and the DEX files
- OatClass: class status and compiled methods
- Method headers and CodeInfo
- .bss slots and boot image references
- Reading the ARM64 code
- VDEX and DEX containers
- The mini debug info
- Versions: what was checked
- Dalvik's optimized DEX (dey)
- What to look for
- What the tool shows, and its limits
- The OatFile and VdexFile library
- 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):
| Symbol | Section | What starts there |
| oatdata | .rodata | The 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 | .text | The native code (and the trampolines of boot.oat, the thunks); oatlastword is its last 4 bytes. |
| oatdataimgrelro · oatdataimgrelroappimage · oatdataimgrelrolastword | .data.img.rel.ro | 32-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 | .bss | Slots filled at run time: ArtMethod*, then GC roots of classes, then strings (section 7). |
| oatdex · oatdexlastword | .dex | Android 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.
| Key | Meaning |
| compiler-filter | verify (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-reason | install, bg-dexopt, first-boot, boot-after-ota, cmdline (adb shell cmd package compile), prebuilt (built with the system image), install-dm… |
| classpath | The 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-checksums | The boot class path the code was compiled against, and the checksums of its boot image (i;components/checksum) or DEX files. |
| debuggable · native-debuggable | Compiled 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-int | The 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-versions | The 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:
| Field | Notes |
| 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 checksum | The 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_offset | From 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_offset | An array of one OatClass offset per class definition |
| u32 lookup_table_offset | The type lookup table (in the VDEX since 12) |
| u32 dex_profile_metadata (17; layout sections 8.1–16) | Startup / layout information |
| 6 × u32 .bss mappings | method, 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
- x19 is the thread register (
tr, Thread*): ldr x16, [x19, #0x98] is the card table (write barrier), other offsets are Thread fields and entrypoints. x20 is the marking register (read barriers), x21 the suspend check address: ldr x21, [x21] faults when the thread must stop.
- The prologue probes the stack:
sub x16, sp, #0x2000; ldr wzr, [x16].
- Calls load the callee's entry point from its ArtMethod (
ldr lr, [x0, #…]; blr lr), or bl shared thunks placed after the methods: EntrypointCallThunk_N (jump to the Thread entrypoint at tr+N), CheckCastStub_…, ClinitCheckStub, read barrier marking. The mini debug info names them.
- Native methods have compiled JNI stubs (
art_jni_trampoline in the mini debug info).
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 version | Release | Status in this reader |
| 281 | Android 17 (API 37), later than the 17.0.0_r1 tag | Checked against the samples: 15 boot image components, services, am, abx, CredentialManager, NexusLauncherRelease, a debuggable app (VDEX 027, DEX 037 and 041) |
| 275 · 259 · 244 | 17 · 16 · 15 | From the AOSP sources at the tags (275 and 259 share 281's layout but one header field; 244 lacks base_oat_offset) |
| 230 · 225 · 195 | 14 · 13 · 12 | From source: packed method header, 5 .bss mappings, no DEX magic / SHA-1 |
| 183 · 170 | 11 · 10 | From source; CodeInfo isn't decoded (its header has no code size; the method header has it) |
| 138 · 131 · 124 | 9 · 8.1 · 8.0 | From source; "all compiled" classes need the DEX for their method count; VDEX 006–019 are only scanned for DEX files |
| 079 · 064 | 7.0 · 6.0 | From 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):
| Part | Contents |
| 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 DEX | With 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
- debuggable: a debuggable app or runtime; little or no native code (ART forces
verify).
- The compiler filter:
verify means everything runs from the DEX (interpreter, JIT) — analyse the DEX; with speed-profile only profiled methods have native code, and the profile tells which code is hot at startup.
- The class loader context: the jars and shared libraries the app loads, and their checksums.
- Checksum mismatches between the OAT file, the VDEX and the APK / JAR: a modified or swapped file (a repackaged app keeping a stale .odex, or an OAT file planted to run modified code — ART checks these, so a mismatching pair isn't used).
- Hooking and patching: compiled code is what runs; instrumenting a method at the DEX level doesn't change its OAT code, and the stack maps tie native pcs back to dex pcs for breakpoints.
- Older releases: non-PIC OAT files,
image_patch_delta (relocated boot images).
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.
- Tables show at most 1,500 rows: filter to see the rest.
- Without the DEX, class counts are estimated from the class tables, and the classes are unnamed (the methods take the mini debug info's names).
- The meaning of version 281's new header field isn't known. Thread entrypoint offsets aren't named. Only arm64 code is disassembled. CodeInfo is decoded for Android 12+.
- The app image (.art) is read by the ART image viewer, not here.
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";
| Member | What 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.base | The oat* dynamic symbols { name, address, size, fileOffset }; oatdata's address and file offset |
| oat.dexFiles | OatDexFile 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.problems | Mini 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";
| Member | What 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.problems | The 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 |