In Art, DexClassLoader converts dex to the oat file format. dexclassloaderoat
After reading the source code DexClassLoader, the native function openDexFileNative in the DexFile class will be called.
Next let's take a look at what the openDexFileNative function has done.
The openDexFileNative function exports the openDexFileNative symbol in the code in the art \ runtime \ native \ dalvik_system_DexFile.cc file.
static JNINativeMethod gMethods[] = { NATIVE_METHOD(DexFile, closeDexFile, "(I)V"), NATIVE_METHOD(DexFile, defineClassNative, "(Ljava/lang/String;Ljava/lang/ClassLoader;I)Ljava/lang/Class;"), NATIVE_METHOD(DexFile, getClassNameList, "(I)[Ljava/lang/String;"), NATIVE_METHOD(DexFile, isDexOptNeeded, "(Ljava/lang/String;)Z"), NATIVE_METHOD(DexFile, openDexFileNative, "(Ljava/lang/String;Ljava/lang/String;I)I"),};
By observing the global variables above, we can find that the function represented by openDexFileNative is DexFile_openDexFileNative.
In the DexFile_openDexFileNative function, call the DexFile: GetChecksum function to obtain the checksum of the zip or dex file. If the checksum is obtained, the checksum is saved in the local variable dex_location_checksum.
DexFile::GetChecksum(dex_location, &dex_location_checksum)
If outputName is not NULL, the following code is executed to convert dex to oat.
std::string oat_location(outputName.c_str());dex_file = linker->FindOrCreateOatFileForDexLocation(dex_location, dex_location_checksum, oat_location);
-------------------------------------------------------------------
The FindOrCreateOatFileForDexLocation function is a member function of the ClassLinker class. Let's take a look at what the FindOrCreateOatFileForDexLocation function has done.
The ClassLinker: FindOrCreateOatFileForDexLocation function calls the ClassLinker: FindOrCreateOatFileForDexLocationLocked function.
return FindOrCreateOatFileForDexLocationLocked(dex_location, dex_location_checksum, oat_location);
-------------------------------------------------------------------
ClassLinker: In the FindOrCreateOatFileForDexLocationLocked function.
You can call the ClassLinker: FindDexFileInOatLocation function to determine whether the dex file has been optimized to an oat file.
// Check if we already have an up-to-date output fileconst DexFile* dex_file = FindDexFileInOatLocation(dex_location, dex_location_checksum, oat_location);
If dex is not optimized to an oat file, call the ClassLinker: GenerateOatFile function to convert dex to oat.
GenerateOatFile(dex_location, scoped_flock.GetFile().Fd(), oat_location)
In the ClassLinker: GenerateOatFile function, fork is a sub-process. In the sub-process, dex2oat is called to convert dex to oat, and the parent process waits until the sub-process stops running.
// fork and exec dex2oatpid_t pid = fork();
execl(dex2oat, dex2oat, "--runtime-arg", "-Xms64m", "--runtime-arg", "-Xmx64m", "--runtime-arg", "-classpath", "--runtime-arg", class_path, "--runtime-arg", oat_compiler_filter_option,#if !defined(ART_TARGET) "--host",#endif boot_image_option, dex_file_option, oat_fd_option, oat_location_option, NULL);
After the ClassLinker: GenerateOatFile function is executed, the oat_dex_file-> OpenDexFile () function is called to open the dex file in the memory.
const DexFile* result = oat_dex_file->OpenDexFile();
So far, the conversion from dex to oat has been completed.
What is comhtcautotestdlibRecordEngine in loader dalviksystemDexClassLoader @ 406bcc98?
Com. htc. autotest. dlib is a bit like a java package. You can find a file in this directory.