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虎年缘订三生
-
-
叶本心|当爱已成往事,敬它一杯酒,再爱不回头(美文)
-
2023年农历腊月初十宜招聘吗 2023年1月1日招聘黄道吉日
-
怎么装修儿童房更省钱 儿童房装修用榻榻米到底好不好
-
-
-
-
发型袁泉换新造型走“红”,一款短发搭配蓝色衬衫走机场,穿出高级感
-
-
-
-
-
-