art\runtime\class_linker.cc::LoadField
LoadField设置ArtField结构中字段的一些值
void ClassLinker::LoadField(const ClassDataItemIterator& it,Handle<mirror::Class> klass,ArtField* dst) {const uint32_t field_idx = it.GetMemberIndex();dst->SetDexFieldIndex(field_idx);dst->SetDeclaringClass(klass.Get());dst->SetAccessFlags(it.GetFieldAccessFlags());}
art\runtime\class_linker.cc::LoadMethod
LoadMethod函数主要做设置ArtMethod结构的一些属性 , 比如函数的MethodIdx,CodeItem在dex文件中的偏移 , 函数的AccessFlag等 。
void ClassLinker::LoadMethod(const DexFile& dex_file,const ClassDataItemIterator& it,Handle<mirror::Class> klass,ArtMethod* dst){uint32_t dex_method_idx = it.GetMemberIndex();const DexFile::MethodId& method_id = dex_file.GetMethodId(dex_method_idx);const char* method_name = dex_file.StringDataByIdx(method_id.name_idx_);ScopedAssertNoThreadSuspension ants("LoadMethod");dst->SetDexMethodIndex(dex_method_idx);dst->SetDeclaringClass(klass.Get());dst->SetCodeItemOffset(it.GetMethodCodeItemOffset());dst->SetDexCacheResolvedMethods(klass->GetDexCache()->GetResolvedMethods(), image_pointer_size_);uint32_t access_flags = it.GetMethodAccessFlags();......dst->SetAccessFlags(access_flags);}
延申:ArtMethod是存储Java函数在虚拟机内相关信息的结构,它不同于mirror命名空间下的Method类,ArtMethod在Java层没有类与之直接映射 。
art\runtime\class_linker.cc::LinkCode
LinkCode函数主要功能是判断代码是否编译从而为函数设置入口代码 。
static void LinkCode(ClassLinker* class_linker,ArtMethod* method,const OatFile::OatClass* oat_class,uint32_t class_def_method_index){Runtime* const runtime = Runtime::Current();if (runtime->IsAotCompiler()) {// The following code only applies to a non-compiler runtime.return;}// Method shouldn't have already been linked.DCHECK(method->GetEntryPointFromQuickCompiledCode() == nullptr);if (oat_class != nullptr) {// Every kind of method should at least get an invoke stub from the oat_method.// non-abstract methods also get their code pointers.const OatFile::OatMethod oat_method = oat_class->GetOatMethod(class_def_method_index);oat_method.LinkMethod(method);}// Install entry point from interpreter.const void* quick_code = method->GetEntryPointFromQuickCompiledCode();bool enter_interpreter = class_linker->ShouldUseInterpreterEntrypoint(method, quick_code);if (!method->IsInvokable()) {EnsureThrowsInvocationError(class_linker, method);return;}if (method->IsStatic() && !method->IsConstructor()) {// For static methods excluding the class initializer, install the trampoline.// It will be replaced by the proper entry point by ClassLinker::FixupStaticTrampolines// after initializing class (see ClassLinker::InitializeClass method).method->SetEntryPointFromQuickCompiledCode(GetQuickResolutionStub());} else if (quick_code == nullptr && method->IsNative()) {method->SetEntryPointFromQuickCompiledCode(GetQuickGenericJniStub());} else if (enter_interpreter) {// Set entry point from compiled code if there's no code or in interpreter only mode.method->SetEntryPointFromQuickCompiledCode(GetQuickToInterpreterBridge());}if (method->IsNative()) {// Unregistering restores the dlsym lookup stub.method->UnregisterNative();if (enter_interpreter || quick_code == nullptr) {// We have a native method here without code. Then it should have either the generic JNI// trampoline as entrypoint (non-static), or the resolution trampoline (static).// TODO: this doesn't handle all the cases where trampolines may be installed.const void* entry_point = method->GetEntryPointFromQuickCompiledCode();DCHECK(class_linker->IsQuickGenericJniStub(entry_point) ||class_linker->IsQuickResolutionStub(entry_point));}}}
推荐阅读
-
-
-
-
-
-
-
-
-
-
昆明机场离哪个高铁站近,昆明飞机场到高铁站有多远?
-
熟黄芪泡水喝的功效与作用 熟黄芪泡水喝有哪些功效与作用
-
今年广东调整养老金的新消息 2022广东省养老金上调方案及补发时间
-
-
-
-
父母买房可以写未成年孩子的名字吗,规避转让税但不能贷款
-
-
-
-