建设的网站都是怎么赚钱,wordpress 怎样打补丁,音乐分享网站开发,wordpress 显示视频前言
之前整理了一系列Dalvik虚拟机的关于堆内存和GC的文章#xff0c;轮到对ART内存进行分析优化了#xff0c;继续整理输出一波#xff0c;本篇为ART虚拟机系列的第一篇#xff0c;介绍ART虚拟机的启动和初始化。 #mermaid-svg-8iNdLFTpOHLgRjHA {font-family:tre…前言
之前整理了一系列Dalvik虚拟机的关于堆内存和GC的文章轮到对ART内存进行分析优化了继续整理输出一波本篇为ART虚拟机系列的第一篇介绍ART虚拟机的启动和初始化。
#mermaid-svg-8iNdLFTpOHLgRjHA {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-8iNdLFTpOHLgRjHA .error-icon{fill:#552222;}#mermaid-svg-8iNdLFTpOHLgRjHA .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-8iNdLFTpOHLgRjHA .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-8iNdLFTpOHLgRjHA .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-8iNdLFTpOHLgRjHA .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-8iNdLFTpOHLgRjHA .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-8iNdLFTpOHLgRjHA .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-8iNdLFTpOHLgRjHA .marker{fill:#333333;stroke:#333333;}#mermaid-svg-8iNdLFTpOHLgRjHA .marker.cross{stroke:#333333;}#mermaid-svg-8iNdLFTpOHLgRjHA svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-8iNdLFTpOHLgRjHA .actor{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-8iNdLFTpOHLgRjHA text.actortspan{fill:black;stroke:none;}#mermaid-svg-8iNdLFTpOHLgRjHA .actor-line{stroke:grey;}#mermaid-svg-8iNdLFTpOHLgRjHA .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333;}#mermaid-svg-8iNdLFTpOHLgRjHA .messageLine1{stroke-width:1.5;stroke-dasharray:2,2;stroke:#333;}#mermaid-svg-8iNdLFTpOHLgRjHA #arrowhead path{fill:#333;stroke:#333;}#mermaid-svg-8iNdLFTpOHLgRjHA .sequenceNumber{fill:white;}#mermaid-svg-8iNdLFTpOHLgRjHA #sequencenumber{fill:#333;}#mermaid-svg-8iNdLFTpOHLgRjHA #crosshead path{fill:#333;stroke:#333;}#mermaid-svg-8iNdLFTpOHLgRjHA .messageText{fill:#333;stroke:#333;}#mermaid-svg-8iNdLFTpOHLgRjHA .labelBox{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-8iNdLFTpOHLgRjHA .labelText,#mermaid-svg-8iNdLFTpOHLgRjHA .labelTexttspan{fill:black;stroke:none;}#mermaid-svg-8iNdLFTpOHLgRjHA .loopText,#mermaid-svg-8iNdLFTpOHLgRjHA .loopTexttspan{fill:black;stroke:none;}#mermaid-svg-8iNdLFTpOHLgRjHA .loopLine{stroke-width:2px;stroke-dasharray:2,2;stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-8iNdLFTpOHLgRjHA .note{stroke:#aaaa33;fill:#fff5ad;}#mermaid-svg-8iNdLFTpOHLgRjHA .noteText,#mermaid-svg-8iNdLFTpOHLgRjHA .noteTexttspan{fill:black;stroke:none;}#mermaid-svg-8iNdLFTpOHLgRjHA .activation0{fill:#f4f4f4;stroke:#666;}#mermaid-svg-8iNdLFTpOHLgRjHA .activation1{fill:#f4f4f4;stroke:#666;}#mermaid-svg-8iNdLFTpOHLgRjHA .activation2{fill:#f4f4f4;stroke:#666;}#mermaid-svg-8iNdLFTpOHLgRjHA .actorPopupMenu{position:absolute;}#mermaid-svg-8iNdLFTpOHLgRjHA .actorPopupMenuPanel{position:absolute;fill:#ECECFF;box-shadow:0px 8px 16px 0px rgba(0,0,0,0.2);filter:drop-shadow(3px 5px 2px rgb(0 0 0 / 0.4));}#mermaid-svg-8iNdLFTpOHLgRjHA .actor-man line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-8iNdLFTpOHLgRjHA .actor-man circle,#mermaid-svg-8iNdLFTpOHLgRjHA line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;stroke-width:2px;}#mermaid-svg-8iNdLFTpOHLgRjHA :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}Android Rumtime.cppjni_internal.ccruntime.ccJNI_CreateJavaVMRuntime::CreateRuntime::Init、new gc::HeapRuntime::StartRuntime::InitNativeMethods、StartDaemonThreadsAndroid Rumtime.cppjni_internal.ccruntime.ccART启动
app_main启动
frameworks/base/cmds/app_process/app_main.cpp
int main(int argc, char* const argv[])
{AppRuntime runtime(argv[0], computeArgBlockSize(argc, argv));if (zygote) {runtime.start(com.android.internal.os.ZygoteInit, args);} else if (className) {runtime.start(com.android.internal.os.RuntimeInit, args);} else {return 10;}
}AndroidRuntime.cpp
frameworks/base/core/jni/AndroidRuntime.cpp
void AndroidRuntime::start(const char* className, const VectorString8 options)
{/* start the virtual machine */JniInvocation jni_invocation;jni_invocation.Init(NULL);JNIEnv* env;if (startVm(mJavaVM, env) ! 0) {return;}onVmCreated(env);/** Register android functions.*/if (startReg(env) 0) {return;}
}int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
{// 拼接一大堆参数if (JNI_CreateJavaVM(pJavaVM, pEnv, initArgs) 0) {ALOGE(JNI_CreateJavaVM failed\n);goto bail;}
}JniInvocation.cpp
libnativehelper/JniInvocation.cpp 5.x的代码里获取libart.so再获取到JNI_CreateJavaVM、JNI_GetCreatedJavaVMs等的实现。
static const char* kLibraryFallback libart.so;bool JniInvocation::Init(const char* library) {library GetLibrary(library, buffer);handle_ dlopen(library, RTLD_NOW);if (!FindSymbol(reinterpret_castvoid**(JNI_GetDefaultJavaVMInitArgs_),JNI_GetDefaultJavaVMInitArgs)) {return false;}if (!FindSymbol(reinterpret_castvoid**(JNI_CreateJavaVM_),JNI_CreateJavaVM)) {return false;}if (!FindSymbol(reinterpret_castvoid**(JNI_GetCreatedJavaVMs_),JNI_GetCreatedJavaVMs)) {return false;}return true;
}extern C jint JNI_GetDefaultJavaVMInitArgs(void* vm_args) {return JniInvocation::GetJniInvocation().JNI_GetDefaultJavaVMInitArgs(vm_args);
}extern C jint JNI_CreateJavaVM(JavaVM** p_vm, JNIEnv** p_env, void* vm_args) {return JniInvocation::GetJniInvocation().JNI_CreateJavaVM(p_vm, p_env, vm_args);
}extern C jint JNI_GetCreatedJavaVMs(JavaVM** vms, jsize size, jsize* vm_count) {return JniInvocation::GetJniInvocation().JNI_GetCreatedJavaVMs(vms, size, vm_count);
}jni_internal.cc
art/runtime/jni_internal.cc
extern C jint JNI_CreateJavaVM(JavaVM** p_vm, JNIEnv** p_env, void* vm_args) {const JavaVMInitArgs* args static_castJavaVMInitArgs*(vm_args);// 创建虚拟机if (!Runtime::Create(options, ignore_unrecognized)) {return JNI_ERR;}Runtime* runtime Runtime::Current();runtime-Start();*p_env Thread::Current()-GetJniEnv();*p_vm runtime-GetJavaVM();return JNI_OK;
}art初始化
art/runtime/runtime.h art/runtime/runtime.cc
runtime.h
class Runtime {public:// Creates and initializes a new runtime.static bool Create(const RuntimeOptions options, bool ignore_unrecognized)SHARED_TRYLOCK_FUNCTION(true, Locks::mutator_lock_);// Starts a runtime, which may cause threads to be started and code to run.bool Start() UNLOCK_FUNCTION(Locks::mutator_lock_);static Runtime* Current() {return instance_;}gc::Heap* GetHeap() const {return heap_;}~Runtime();private:Runtime();void BlockSignals();bool Init(const RuntimeOptions options, bool ignore_unrecognized)SHARED_TRYLOCK_FUNCTION(true, Locks::mutator_lock_);// A pointer to the active runtime or NULL.static Runtime* instance_;gc::Heap* heap_;
}Runtime::Create
bool Runtime::Create(const RuntimeOptions options, bool ignore_unrecognized) {if (Runtime::instance_ ! NULL) {return false;}instance_ new Runtime;instance_-Init(options, ignore_unrecognized);return true;
}Runtime()
Runtime::Runtime(): is_zygote_(false),is_concurrent_gc_enabled_(true),is_explicit_gc_disabled_(false),dex2oat_enabled_(true),default_stack_size_(0),heap_(nullptr),monitor_list_(nullptr),monitor_pool_(nullptr),thread_list_(nullptr),class_linker_(nullptr),signal_catcher_(nullptr),java_vm_(nullptr) {
}Runtime::Init
bool Runtime::Init(const RuntimeOptions raw_options, bool ignore_unrecognized) {Monitor::Init(options-lock_profiling_threshold_, options-hook_is_sensitive_thread_);heap_ new gc::Heap(options-heap_initial_size_,options-heap_growth_limit_,options-heap_min_free_,options-heap_max_free_,options-heap_target_utilization_,options-foreground_heap_growth_multiplier_,options-heap_maximum_size_,options-heap_non_moving_space_capacity_,options-image_,options-image_isa_,options-collector_type_,options-background_collector_type_,options-parallel_gc_threads_,options-conc_gc_threads_,options-low_memory_mode_,options-long_pause_log_threshold_,options-long_gc_log_threshold_,options-ignore_max_footprint_,options-use_tlab_,options-verify_pre_gc_heap_,options-verify_pre_sweeping_heap_,options-verify_post_gc_heap_,options-verify_pre_gc_rosalloc_,options-verify_pre_sweeping_rosalloc_,options-verify_post_gc_rosalloc_,options-use_homogeneous_space_compaction_for_oom_,options-min_interval_homogeneous_space_compaction_by_oom_);dump_gc_performance_on_shutdown_ options-dump_gc_performance_on_shutdown_;BlockSignals();InitPlatformSignalHandlers();InitializeSignalChain();java_vm_ new JavaVMExt(this, options.get());Thread::Startup();class_linker_ new ClassLinker(intern_table_);//...return true;
}runtime-start
bool Runtime::Start() {// Restore main thread state to kNative as expected by native code.Thread* self Thread::Current();self-TransitionFromRunnableToSuspended(kNative);started_ true;if (IsZygote()) {ScopedObjectAccess soa(self);gc::space::ImageSpace* image_space heap_-GetImageSpace();if (image_space ! nullptr) {Runtime::Current()-GetInternTable()-AddImageStringsToTable(image_space);Runtime::Current()-GetClassLinker()-MoveImageClassesToClassTable();}}// InitNativeMethods needs to be after started_ so that the classes it touches will have methods linked to the oat file if necessary.InitNativeMethods();// Initialize well known thread group values that may be accessed threads while attaching.InitThreadGroups(self);Thread::FinishStartup();system_class_loader_ CreateSystemClassLoader();StartDaemonThreads();finished_starting_ true;return true;
}