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));}}}
经验总结扩展阅读
-
导语:心仪的他就在眼前 心仪的男人不唐突的4种搭讪方式,教你把握机会,迈出追爱第一步
-
-
-
六款2023年最佳手机推荐 手机好用排行榜2023
-
-
-
2022年10月24日是出火的黄道吉日吗 2022年农历九月廿九宜出火吗
-
再过4天,鸿运当头,高人一等,喜事接踵,横财不断,尽享富贵
-
-
-
-
-
-
-
-
-
-
-
亚麻衣服怎么洗不缩水,亚麻面料的衣服这样清洗不会缩水?
-
疾病 40岁是肠道疾病“高发期”,若想肠道更健康,3个坏习惯要改掉