// Info about a method that resides in shared memory (shared between zygote and apps). // We keep the info here to avoid dirtying the `ArtMethod`'s page. struct SharedMethodInfo {
uint8_t counter = kIndividualSharedMethodHotnessThreshold;
};
/** *AcustomizedthreadpoolfortheJIT,toprioritizecompilationkinds,and *simplifyrootvisiting.
*/ class JitThreadPool : public AbstractThreadPool { public: static JitThreadPool* Create(constchar* name,
size_t num_threads,
size_t worker_stack_size = ThreadPoolWorker::kDefaultStackSize) {
JitThreadPool* pool = new JitThreadPool(name, num_threads, worker_stack_size);
pool->CreateThreads(); return pool;
}
// Add a task to the generic queue. This is for tasks like // ZygoteVerificationTask, or JitCompileTask for precompile. void AddTask(Thread* self, Task* task) REQUIRES(!task_queue_lock_) override;
size_t GetTaskCount(Thread* self) REQUIRES(!task_queue_lock_) override; void RemoveAllTasks(Thread* self) REQUIRES(!task_queue_lock_) override;
~JitThreadPool() override;
// Remove the task from the list of compiling tasks. void Remove(JitCompileTask* task) REQUIRES(!task_queue_lock_);
// Add a custom compilation task in the right queue. void AddTask(Thread* self, ArtMethod* method, CompilationKind kind) REQUIRES(!task_queue_lock_);
// Visit the ArtMethods stored in the various queues. void VisitRoots(RootVisitor* visitor);
private:
JitThreadPool(constchar* name,
size_t num_threads,
size_t worker_stack_size) // We need peers as JIT thread can load classes and we may report related events b/29547798.
: AbstractThreadPool(name, num_threads, /* create_peers= */ true, worker_stack_size) {}
// Try to fetch an entry from `methods`. Return null if `methods` is empty.
Task* FetchFrom(std::deque<ArtMethod*>& methods, CompilationKind kind) REQUIRES(task_queue_lock_);
// We track the methods that are currently enqueued to avoid // adding them to the queue multiple times, which could bloat the // queues.
std::set<ArtMethod*> osr_enqueued_methods_ GUARDED_BY(task_queue_lock_);
std::set<ArtMethod*> fast_enqueued_methods_ GUARDED_BY(task_queue_lock_);
std::set<ArtMethod*> baseline_enqueued_methods_ GUARDED_BY(task_queue_lock_);
std::set<ArtMethod*> optimized_enqueued_methods_ GUARDED_BY(task_queue_lock_);
// A set to keep track of methods that are currently being compiled. Entries // will be removed when JitCompileTask->Finalize is called.
std::unordered_set<JitCompileTask*> current_compilations_ GUARDED_BY(task_queue_lock_);
DISALLOW_COPY_AND_ASSIGN(JitThreadPool);
};
class Jit { public: // How frequently should the interpreter check to see if OSR compilation is ready. static constexpr int16_t kJitRecheckOSRThreshold = 101; // Prime number to avoid patterns.
// Return whether we should do JIT compilation. Note this will returns false // if we only need to save profile information and not compile methods. bool UseJitCompilation() const { return options_->UseJitCompilation();
}
// Starts the profile saver if the config options allow profile recording. // The profile will be stored in the specified `profile_filename` and will contain // information collected from the given `code_paths` (a set of dex locations). // // The `ref_profile_filename` denotes the path to the reference profile which // might be queried to determine if an initial save should be done earlier. // It can be empty indicating there is no reference profile. void StartProfileSaver(const std::string& profile_filename, const std::vector<std::string>& code_paths, const std::string& ref_profile_filename,
AppInfo::CodeType code_type); void StopProfileSaver();
// If debug info generation is turned on then write the type information for types already loaded // into the specified class linker to the jit debug interface, void DumpTypeInfoForLoadedTypes(ClassLinker* linker);
// Return whether we should try to JIT compiled code as soon as an ArtMethod is invoked.
EXPORT bool JitAtFirstUse();
// Return whether we can invoke JIT code for `method`. bool CanInvokeCompiledCode(ArtMethod* method);
// Return the information required to do an OSR jump. Return null if the OSR // cannot be done.
OsrData* PrepareForOsr(ArtMethod* method, uint32_t dex_pc, uint32_t* vregs)
REQUIRES_SHARED(Locks::mutator_lock_);
// If an OSR compiled version is available for `method`, // and `dex_pc + dex_pc_offset` is an entry point of that compiled // version, this method will jump to the compiled code, let it run, // and return true afterwards. Return false otherwise. staticbool MaybeDoOnStackReplacement(Thread* thread,
ArtMethod* method,
uint32_t dex_pc,
int32_t dex_pc_offset,
JValue* result)
REQUIRES_SHARED(Locks::mutator_lock_);
// Stop the JIT by waiting for all current compilations and enqueued compilations to finish.
EXPORT void Stop();
// Start JIT threads.
EXPORT void Start();
// Transition to a child state.
EXPORT void PostForkChildAction(bool is_system_server, bool is_zygote);
// Prepare for forking.
EXPORT void PreZygoteFork();
// Adjust state after forking. void PostZygoteFork();
// Add a task to the queue, ensuring it runs after boot is finished. void AddPostBootTask(Thread* self, Task* task);
// Called when system finishes booting. void BootCompleted();
// Are we in a zygote using JIT compilation? staticbool InZygoteUsingJit();
// Compile methods from the given profile (.prof extension). If `add_to_queue` // is true, methods in the profile are added to the JIT queue. Otherwise they are compiled // directly. // Return the number of methods added to the queue.
uint32_t CompileMethodsFromProfile(Thread* self, const std::vector<const DexFile*>& dex_files, const std::string& profile_path,
Handle<mirror::ClassLoader> class_loader, bool add_to_queue);
// Compile methods from the given boot profile (.bprof extension). If `add_to_queue` // is true, methods in the profile are added to the JIT queue. Otherwise they are compiled // directly. // Return the number of methods added to the queue.
uint32_t CompileMethodsFromBootProfile(Thread* self, const std::vector<const DexFile*>& dex_files, const std::string& profile_path,
Handle<mirror::ClassLoader> class_loader, bool add_to_queue);
// Register the dex files to the JIT. This is to perform any compilation/optimization // at the point of loading the dex files. void RegisterDexFiles(const std::vector<std::unique_ptr<const DexFile>>& dex_files,
jobject class_loader); // Register the compiler filter for the given type of code. void RegisterAppInfo(AppInfo::CodeType code_type, const std::string& compiler_filter);
// Called by the compiler to know whether it can directly encode the // method/class/string. bool CanEncodeMethod(ArtMethod* method, bool is_for_shared_region) const
REQUIRES_SHARED(Locks::mutator_lock_); bool CanEncodeClass(ObjPtr<mirror::Class> cls, bool is_for_shared_region) const
REQUIRES_SHARED(Locks::mutator_lock_); bool CanEncodeString(ObjPtr<mirror::String> string, bool is_for_shared_region) const
REQUIRES_SHARED(Locks::mutator_lock_); bool CanAssumeInitialized(ObjPtr<mirror::Class> cls, bool is_for_shared_region) const
REQUIRES_SHARED(Locks::mutator_lock_);
// Map boot image methods after all compilation in zygote has been done. void MapBootImageMethods() REQUIRES(Locks::mutator_lock_);
// Notify to other processes that the zygote is done profile compiling boot // class path methods. void NotifyZygoteCompilationDone();
// Get a snapshot of the current info for a shared method. The argument must be a shared method.
SharedMethodInfo GetSharedMethodInfo(ArtMethod* method);
bool UseFastCompiler() const { // Check for java debuggable here, as we can change to java debuggable and back. For example, // when a precise method trace is requested we move to java debuggable and transition back // once tracing is stopped. return use_fast_compiler_ && !Runtime::Current()->IsJavaDebuggable();
} static uint16_t GetInitialHotnessThreshold();
// Whether we should not add hotness counts for the given method. bool IgnoreSamplesForMethod(ArtMethod* method)
REQUIRES_SHARED(Locks::mutator_lock_);
// Compile an individual method listed in a profile. If `add_to_queue` is // true and the method was resolved, return true. Otherwise return false. bool CompileMethodFromProfile(Thread* self,
ClassLinker* linker,
uint32_t method_idx,
Handle<mirror::DexCache> dex_cache,
Handle<mirror::ClassLoader> class_loader, bool add_to_queue, bool compile_after_boot)
REQUIRES_SHARED(Locks::mutator_lock_);
// In the JIT zygote configuration, after all compilation is done, the zygote // will copy its contents of the boot image to the zygote_mapping_methods_, // which will be picked up by processes that will map the memory // in-place within the boot image mapping. // // zygote_mapping_methods_ is shared memory only usable by the zygote and not // inherited by child processes. We create it eagerly to ensure other // processes cannot seal writable the file.
MemMap zygote_mapping_methods_;
// The file descriptor created through memfd_create pointing to memory holding // boot image methods. Created by the zygote, and inherited by child // processes. The descriptor will be closed in each process (including the // zygote) once they don't need it.
android::base::unique_fd fd_methods_;
// The size of the memory pointed by `fd_methods_`. Cached here to avoid // recomputing it.
size_t fd_methods_size_;
// Map from shared methods to their info.
std::unordered_map<ArtMethod*, SharedMethodInfo> shared_method_info_map_;
friendclass art::jit::JitCompileTask;
DISALLOW_COPY_AND_ASSIGN(Jit);
};
// Helper class to stop the JIT for a given scope. This will wait for the JIT to quiesce. class EXPORT ScopedJitSuspend { public:
ScopedJitSuspend();
~ScopedJitSuspend();
private: bool was_on_;
};
} // namespace jit
} // namespace art
#endif// ART_RUNTIME_JIT_JIT_H_
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.