runtime.h revision cc236d74772dda5a4161d9bc5f497fd3d956eb87
12faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes/* 22faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Copyright (C) 2011 The Android Open Source Project 32faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * 42faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Licensed under the Apache License, Version 2.0 (the "License"); 52faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * you may not use this file except in compliance with the License. 62faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * You may obtain a copy of the License at 72faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * 82faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 92faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * 102faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Unless required by applicable law or agreed to in writing, software 112faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 122faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 132faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * See the License for the specific language governing permissions and 142faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * limitations under the License. 152faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes */ 167b21670581d13db32f1384a3b2692bcfc8f57320Carl Shapiro 171fb8620309a4e94d11879aabc33364acfa733904Carl Shapiro#ifndef ART_SRC_RUNTIME_H_ 181fb8620309a4e94d11879aabc33364acfa733904Carl Shapiro#define ART_SRC_RUNTIME_H_ 196b6b5f0e67ce03f38223a525612955663bc1799bCarl Shapiro 20a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes#include <jni.h> 21c5f7c91ab89055cffb573fff7e06dbdd860bccedElliott Hughes#include <stdio.h> 22c5f7c91ab89055cffb573fff7e06dbdd860bccedElliott Hughes 23e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes#include <iosfwd> 246ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom#include <string> 25fc322c72d7a89a6f7a05c8bdc232d780aecd9232Carl Shapiro#include <utility> 266ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom#include <vector> 27578bbdc684db8ed68e9fedbc678669d27fa68b6eBrian Carlstrom 28a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes#include "globals.h" 291f87008b165d26541d832ff805250afdc89c253dBrian Carlstrom#include "heap.h" 300f3c55331439970e01af67f80ac117c473bc04cfElliott Hughes#include "instruction_set.h" 31578bbdc684db8ed68e9fedbc678669d27fa68b6eBrian Carlstrom#include "macros.h" 329d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes#include "runtime_stats.h" 33a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes#include "safe_map.h" 34578bbdc684db8ed68e9fedbc678669d27fa68b6eBrian Carlstrom#include "stringpiece.h" 35b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro 36971bf3f9184010d68b9a3ad30b396fa401af91a3Logan Chien#if defined(ART_USE_LLVM_COMPILER) 37971bf3f9184010d68b9a3ad30b396fa401af91a3Logan Chien#include "compiler_llvm/procedure_linkage_table.h" 38971bf3f9184010d68b9a3ad30b396fa401af91a3Logan Chien#endif 39971bf3f9184010d68b9a3ad30b396fa401af91a3Logan Chien 406b6b5f0e67ce03f38223a525612955663bc1799bCarl Shapironamespace art { 417b21670581d13db32f1384a3b2692bcfc8f57320Carl Shapiro 42161928613d3f097108319de60494fab1aab8d48aBrian Carlstromtemplate<class T> class PrimitiveArray; 43161928613d3f097108319de60494fab1aab8d48aBrian Carlstromtypedef PrimitiveArray<int8_t> ByteArray; 4461e019d291583029c01b61b93bea750f2b663c37Carl Shapiroclass ClassLinker; 45aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstromclass ClassLoader; 46fc322c72d7a89a6f7a05c8bdc232d780aecd9232Carl Shapiroclass DexFile; 4761e019d291583029c01b61b93bea750f2b663c37Carl Shapiroclass Heap; 48cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughesclass InternTable; 49c5f7c91ab89055cffb573fff7e06dbdd860bccedElliott Hughesclass JavaVMExt; 50ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogersclass Method; 51c33a32bccc4c66ed82ce3a580b16636399385cb4Elliott Hughesclass MonitorList; 52e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughesclass SignalCatcher; 536ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstromclass String; 5461e019d291583029c01b61b93bea750f2b663c37Carl Shapiroclass ThreadList; 55225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughesclass Throwable; 562692b573a56cd63a3c8c8aa1636e3766b6d8c9c4jeffhaoclass Trace; 5761e019d291583029c01b61b93bea750f2b663c37Carl Shapiro 581fb8620309a4e94d11879aabc33364acfa733904Carl Shapiroclass Runtime { 597b21670581d13db32f1384a3b2692bcfc8f57320Carl Shapiro public: 60f1a5adc87760f938b01df26d906295063546b259Elliott Hughes typedef std::vector<std::pair<std::string, const void*> > Options; 618a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom 628a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom class ParsedOptions { 638a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom public: 646ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom // returns null if problem parsing and ignore_unrecognized is false 656ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom static ParsedOptions* Create(const Options& options, bool ignore_unrecognized); 668a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom 67a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom const std::vector<const DexFile*>* boot_class_path_; 68a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom std::string boot_class_path_string_; 69a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom std::string class_path_string_; 7058ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom std::string host_prefix_; 71223f20fa939c386c695977263780dea2195093dbBrian Carlstrom std::string image_; 72515a5bc89282d6f910cae4d5852bb77124a47825Elliott Hughes bool check_jni_; 73a09576416788b916095739e43a16917e7948f3a4Elliott Hughes std::string jni_trace_; 74d9c67be7c116875d96b31e640ad47d587b205605Elliott Hughes bool is_compiler_; 759ca7a1fdd0daa546b790adb6a24dbc13c22df76aElliott Hughes bool is_zygote_; 76069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier bool is_concurrent_gc_enabled_; 778a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom size_t heap_initial_size_; 788a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom size_t heap_maximum_size_; 79c11607024d2e7a52ca690b8339306cab040e6653jeffhao size_t heap_growth_limit_; 80f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstrom size_t stack_size_; 81bb1e8f0a07c12a8b0a2dd3cab6a1a7e825a54c6fElliott Hughes size_t jni_globals_max_; 82bb1e8f0a07c12a8b0a2dd3cab6a1a7e825a54c6fElliott Hughes size_t lock_profiling_threshold_; 8394ce37a3919a0bdb8855a3d3264a50df1dbc41beElliott Hughes std::string stack_trace_file_; 84b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao bool method_trace_; 85b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao std::string method_trace_file_; 86b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao size_t method_trace_file_size_; 87fc86162ce2a3467acb690e18cc8bd9b3daafc606Elliott Hughes bool (*hook_is_sensitive_thread_)(); 886ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom jint (*hook_vfprintf_)(FILE* stream, const char* format, va_list ap); 896ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom void (*hook_exit_)(jint status); 906ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom void (*hook_abort_)(); 916ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom std::vector<std::string> properties_; 926ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom 936ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom private: 940cfe1fb7060576d047f7f894fc0d8b87de84fcabIan Rogers ParsedOptions() {} 958a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom }; 962ed144c2b49ae1da6c464d7a1be0062870530802Carl Shapiro 9761e019d291583029c01b61b93bea750f2b663c37Carl Shapiro // Creates and initializes a new runtime. 982ed144c2b49ae1da6c464d7a1be0062870530802Carl Shapiro static Runtime* Create(const Options& options, bool ignore_unrecognized); 9969b15fb098162f19a4c20e6dccdcead04d9c77f0Brian Carlstrom 100d9c67be7c116875d96b31e640ad47d587b205605Elliott Hughes bool IsCompiler() const { 101d9c67be7c116875d96b31e640ad47d587b205605Elliott Hughes return is_compiler_; 102d9c67be7c116875d96b31e640ad47d587b205605Elliott Hughes } 103d9c67be7c116875d96b31e640ad47d587b205605Elliott Hughes 104caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom bool IsZygote() const { 105caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom return is_zygote_; 106caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom } 107caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom 108069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier bool IsConcurrentGcEnabled() const { 109069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier return is_concurrent_gc_enabled_; 110069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier } 111069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier 11258ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom const std::string& GetHostPrefix() const { 113307f75d6bcf7c32db7e1b43124dead628cc7ce96Elliott Hughes DCHECK(!IsStarted()); 11458ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom return host_prefix_; 11558ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom } 11658ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom 11769b15fb098162f19a4c20e6dccdcead04d9c77f0Brian Carlstrom // Starts a runtime, which may cause threads to be started and code to run. 11869b15fb098162f19a4c20e6dccdcead04d9c77f0Brian Carlstrom void Start(); 1192ed144c2b49ae1da6c464d7a1be0062870530802Carl Shapiro 1209af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers bool IsShuttingDown() const { 1219af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers return shutting_down_; 1229af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers } 1239af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers 1249af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers bool IsStarted() const { 1259af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers return started_; 1269af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers } 127dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes 1287664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier bool IsFinishedStarting() const { 1297664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier return finished_starting_; 1307664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier } 1317664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier 1322ed144c2b49ae1da6c464d7a1be0062870530802Carl Shapiro static Runtime* Current() { 1332ed144c2b49ae1da6c464d7a1be0062870530802Carl Shapiro return instance_; 1342ed144c2b49ae1da6c464d7a1be0062870530802Carl Shapiro } 13561e019d291583029c01b61b93bea750f2b663c37Carl Shapiro 136ffe6736397d17457188727510f0a2953f69a383aElliott Hughes // Aborts semi-cleanly. Used in the implementation of LOG(FATAL), which most 137ffe6736397d17457188727510f0a2953f69a383aElliott Hughes // callers should prefer. 138ffe6736397d17457188727510f0a2953f69a383aElliott Hughes // This isn't marked ((noreturn)) because then gcc will merge multiple calls 139ffe6736397d17457188727510f0a2953f69a383aElliott Hughes // in a single function together. This reduces code size slightly, but means 140ffe6736397d17457188727510f0a2953f69a383aElliott Hughes // that the native stack trace we get may point at the wrong call site. 1418593fdbacf97261f790ca53ea0ec416f57c987a7Elliott Hughes static void Abort(); 142ffe6736397d17457188727510f0a2953f69a383aElliott Hughes 143365c10235438607541fa2259a5fec48061b90bd8Ian Rogers // Returns the "main" ThreadGroup, used when attaching user threads. 144365c10235438607541fa2259a5fec48061b90bd8Ian Rogers jobject GetMainThreadGroup() const { 14578a5e15629e6591090582cd83b1ec1380a50a840Ian Rogers CHECK(main_thread_group_ != NULL || IsCompiler()); 146365c10235438607541fa2259a5fec48061b90bd8Ian Rogers return main_thread_group_; 147365c10235438607541fa2259a5fec48061b90bd8Ian Rogers } 148365c10235438607541fa2259a5fec48061b90bd8Ian Rogers 149365c10235438607541fa2259a5fec48061b90bd8Ian Rogers // Returns the "system" ThreadGroup, used when attaching our internal threads. 150365c10235438607541fa2259a5fec48061b90bd8Ian Rogers jobject GetSystemThreadGroup() const { 15178a5e15629e6591090582cd83b1ec1380a50a840Ian Rogers CHECK(system_thread_group_ != NULL || IsCompiler()); 152365c10235438607541fa2259a5fec48061b90bd8Ian Rogers return system_thread_group_; 153365c10235438607541fa2259a5fec48061b90bd8Ian Rogers } 154365c10235438607541fa2259a5fec48061b90bd8Ian Rogers 155462c94449720e0dc6b93d7138d835d345ccf67aeElliott Hughes // Attaches the calling native thread to the runtime. 156365c10235438607541fa2259a5fec48061b90bd8Ian Rogers void AttachCurrentThread(const char* thread_name, bool as_daemon, jobject thread_group); 157b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro 158bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes void CallExitHook(jint status); 159bf86d0438e9ef9c145ebcf16a2e74c4efaa2686aElliott Hughes 16061e019d291583029c01b61b93bea750f2b663c37Carl Shapiro // Detaches the current native thread from the runtime. 161d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughes void DetachCurrentThread(); 16261e019d291583029c01b61b93bea750f2b663c37Carl Shapiro 163c967f78cd29b6019f7cfca40a02e9b677112da70Elliott Hughes void DumpForSigQuit(std::ostream& os); 16421a5bf2dc8c9cb3fbe5a30a88d1149c328e3aacaElliott Hughes void DumpLockHolders(std::ostream& os); 165e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes 16661e019d291583029c01b61b93bea750f2b663c37Carl Shapiro ~Runtime(); 167b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro 168a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom const std::string& GetBootClassPathString() const { 169a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom return boot_class_path_string_; 170b765be0d656c3073402693aeaf64e95a0e49f218Brian Carlstrom } 171b765be0d656c3073402693aeaf64e95a0e49f218Brian Carlstrom 172a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom const std::string& GetClassPathString() const { 173a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom return class_path_string_; 1747a90959d4ef7a69f3bcb7b8763f646e12d9267d3Carl Shapiro } 1757a90959d4ef7a69f3bcb7b8763f646e12d9267d3Carl Shapiro 176a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom ClassLinker* GetClassLinker() const { 177a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom return class_linker_; 1787ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes } 1797ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes 1807ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes size_t GetDefaultStackSize() const { 1817ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes return default_stack_size_; 1827ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes } 1837ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes 184b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes Heap* GetHeap() const { 185b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes return heap_; 186b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes } 187b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes 188cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughes InternTable* GetInternTable() const { 189cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughes return intern_table_; 190cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughes } 191cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughes 1920af5543f8ea20c3e655b2d748a1b7dcf283792feElliott Hughes JavaVMExt* GetJavaVM() const { 193c5f7c91ab89055cffb573fff7e06dbdd860bccedElliott Hughes return java_vm_; 194f2682d5a6ce0f7de58da8fd4ec8aec200c43b92eElliott Hughes } 195f2682d5a6ce0f7de58da8fd4ec8aec200c43b92eElliott Hughes 196c33a32bccc4c66ed82ce3a580b16636399385cb4Elliott Hughes MonitorList* GetMonitorList() const { 197c33a32bccc4c66ed82ce3a580b16636399385cb4Elliott Hughes return monitor_list_; 198c33a32bccc4c66ed82ce3a580b16636399385cb4Elliott Hughes } 199c33a32bccc4c66ed82ce3a580b16636399385cb4Elliott Hughes 200225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes Throwable* GetPreAllocatedOutOfMemoryError() { 201225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes return pre_allocated_OutOfMemoryError_; 202225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes } 203225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes 204225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes const std::vector<std::string>& GetProperties() const { 205225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes return properties_; 206225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes } 207225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes 208d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughes ThreadList* GetThreadList() const { 209d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughes return thread_list_; 210d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughes } 211d92bec457dc6c506c80e9da6b8e0c958266b5cdcElliott Hughes 2127ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes const char* GetVersion() const { 2137ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes return "2.0.0"; 2147ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes } 2157ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes 216410c0c876f326e14c176a39ba21fc4dd3f7db8abElliott Hughes void VisitRoots(Heap::RootVisitor* visitor, void* arg) const; 2171f87008b165d26541d832ff805250afdc89c253dBrian Carlstrom 2189af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers bool HasJniDlsymLookupStub() const { 2199af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers return jni_stub_array_ != NULL; 2209af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers } 2219af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers 2229af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers ByteArray* GetJniDlsymLookupStub() const { 2239af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers CHECK(HasJniDlsymLookupStub()); 2249af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers return jni_stub_array_; 2259af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers } 2269af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers 227169c9a7f46776b235d0a37d5e0ff27682deffe06Ian Rogers void SetJniDlsymLookupStub(ByteArray* jni_stub_array); 228ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogers 2299af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers bool HasAbstractMethodErrorStubArray() const { 2309af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers return abstract_method_error_stub_array_ != NULL; 2319af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers } 2329af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers 2339af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers ByteArray* GetAbstractMethodErrorStubArray() const { 2349af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers CHECK(abstract_method_error_stub_array_ != NULL); 2359af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers return abstract_method_error_stub_array_; 2369af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers } 2379af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers 238e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom void SetAbstractMethodErrorStubArray(ByteArray* abstract_method_error_stub_array); 239ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogers 2401cb0a1dfc32531c79a968aeac26ccb5525862497Ian Rogers enum TrampolineType { 2411cb0a1dfc32531c79a968aeac26ccb5525862497Ian Rogers kStaticMethod, 2421cb0a1dfc32531c79a968aeac26ccb5525862497Ian Rogers kUnknownMethod, 2434f0d07c783afef89703dce32c94440fc8621a29bIan Rogers kLastTrampolineMethodType // Value used for iteration 2441cb0a1dfc32531c79a968aeac26ccb5525862497Ian Rogers }; 2459af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers 2469af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers bool HasResolutionStubArray(TrampolineType type) const { 2479af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers return resolution_stub_array_[type] != NULL; 2489af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers } 2499af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers 2509af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers ByteArray* GetResolutionStubArray(TrampolineType type) const { 2519af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers CHECK(HasResolutionStubArray(type)); 2529af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers DCHECK_LT(static_cast<int>(type), static_cast<int>(kLastTrampolineMethodType)); 2539af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers return resolution_stub_array_[type]; 2549af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers } 2559af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers 2561cb0a1dfc32531c79a968aeac26ccb5525862497Ian Rogers void SetResolutionStubArray(ByteArray* resolution_stub_array, TrampolineType type); 257ad25ac568407ceb14334e8551dd1c4dd0fd6993cIan Rogers 2589af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers // Returns a special method that calls into a trampoline for runtime method resolution 2599af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers Method* GetResolutionMethod() const { 2609af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers CHECK(HasResolutionMethod()); 2619af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers return resolution_method_; 2629af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers } 2639af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers 2649af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers bool HasResolutionMethod() const { 2659af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers return resolution_method_ != NULL; 2669af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers } 2679af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers 2689af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers void SetResolutionMethod(Method* method) { 2699af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers resolution_method_ = method; 2709af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers } 2719af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers 2721984651929744dd603fd082e23eacd877b9bc177Ian Rogers Method* CreateResolutionMethod(); 2731984651929744dd603fd082e23eacd877b9bc177Ian Rogers 274ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogers // Returns a special method that describes all callee saves being spilled to the stack. 2754f0d07c783afef89703dce32c94440fc8621a29bIan Rogers enum CalleeSaveType { 2764f0d07c783afef89703dce32c94440fc8621a29bIan Rogers kSaveAll, 2774f0d07c783afef89703dce32c94440fc8621a29bIan Rogers kRefsOnly, 2784f0d07c783afef89703dce32c94440fc8621a29bIan Rogers kRefsAndArgs, 2794f0d07c783afef89703dce32c94440fc8621a29bIan Rogers kLastCalleeSaveType // Value used for iteration 2804f0d07c783afef89703dce32c94440fc8621a29bIan Rogers }; 2819af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers 2829af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers bool HasCalleeSaveMethod(CalleeSaveType type) const { 283225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes return callee_save_methods_[type] != NULL; 2849af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers } 2859af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers 2869af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers Method* GetCalleeSaveMethod(CalleeSaveType type) const { 2879af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers CHECK(HasCalleeSaveMethod(type)); 288225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes return callee_save_methods_[type]; 2899af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers } 2909af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers 2914f0d07c783afef89703dce32c94440fc8621a29bIan Rogers void SetCalleeSaveMethod(Method* method, CalleeSaveType type); 2924f0d07c783afef89703dce32c94440fc8621a29bIan Rogers 2939af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers Method* CreateCalleeSaveMethod(InstructionSet instruction_set, CalleeSaveType type); 2949af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers 295ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom Method* CreateRefOnlyCalleeSaveMethod(InstructionSet instruction_set); 296ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom Method* CreateRefAndArgsCalleeSaveMethod(InstructionSet instruction_set); 297ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogers 2989d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes int32_t GetStat(int kind); 2999d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes 3009af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers RuntimeStats* GetStats() { 3019af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers return &stats_; 3029af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers } 3039d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes 3049d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes bool HasStatsEnabled() const { 3059d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes return stats_enabled_; 3069d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes } 3079d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes 3089d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes void ResetStats(int kinds); 3099d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes 3109d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes void SetStatsEnabled(bool new_state); 3119d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes 312caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom void DidForkFromZygote(); 313cc236d74772dda5a4161d9bc5f497fd3d956eb87Mathieu Chartier bool PreZygoteFork(); 314caabb1b77b4a55eb1bb45ebcd3071c9ea01dd3cfBrian Carlstrom 3152692b573a56cd63a3c8c8aa1636e3766b6d8c9c4jeffhao void EnableMethodTracing(Trace* tracer); 3162692b573a56cd63a3c8c8aa1636e3766b6d8c9c4jeffhao void DisableMethodTracing(); 3179af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers 3189af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers bool IsMethodTracingActive() const { 3199af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers return tracer_ != NULL; 3209af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers } 3219af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers 3229af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers Trace* GetTracer() const { 3239af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers CHECK(IsMethodTracingActive()); 3249af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers return tracer_; 3259af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers } 3262692b573a56cd63a3c8c8aa1636e3766b6d8c9c4jeffhao 327b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes bool UseCompileTimeClassPath() const { 328b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes return use_compile_time_class_path_; 329b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes } 3309af209c9dcc6763fae2976981570a90aa41fd86bIan Rogers 331b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes const std::vector<const DexFile*>& GetCompileTimeClassPath(const ClassLoader* class_loader); 332b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes void SetCompileTimeClassPath(const ClassLoader* class_loader, std::vector<const DexFile*>& class_path); 333b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes 334b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro private: 335457005c557b8762475db3220ce5a747d629f975bElliott Hughes static void InitPlatformSignalHandlers(); 336ffe6736397d17457188727510f0a2953f69a383aElliott Hughes 337dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes Runtime(); 33861e019d291583029c01b61b93bea750f2b663c37Carl Shapiro 339c1674ed06662420213441ff2b818f2f71f9098dcElliott Hughes void BlockSignals(); 340c1674ed06662420213441ff2b818f2f71f9098dcElliott Hughes 3418a436595d36c1e4935984fcac249d7d877e00383Brian Carlstrom bool Init(const Options& options, bool ignore_unrecognized); 342038a806df72f884d22283a84a31c9a1d35ba1fdfElliott Hughes void InitNativeMethods(); 343365c10235438607541fa2259a5fec48061b90bd8Ian Rogers void InitThreadGroups(Thread* self); 344ff17f1fd3ff32f93e45588eb2b158832d73f9afaElliott Hughes void RegisterRuntimeNativeMethods(JNIEnv* env); 345d1cc8363d4f4bbac7568b1d02a5ca481cd10830fElliott Hughes 34685d1545e985ac689db4bad7849880e843707c862Elliott Hughes void StartDaemonThreads(); 347d1cc8363d4f4bbac7568b1d02a5ca481cd10830fElliott Hughes void StartSignalCatcher(); 34861e019d291583029c01b61b93bea750f2b663c37Carl Shapiro 349b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes // A pointer to the active runtime or NULL. 350b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes static Runtime* instance_; 351b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes 352d9c67be7c116875d96b31e640ad47d587b205605Elliott Hughes bool is_compiler_; 3539ca7a1fdd0daa546b790adb6a24dbc13c22df76aElliott Hughes bool is_zygote_; 354069387a60cb2b72e116cc38b32e14403f092df8fMathieu Chartier bool is_concurrent_gc_enabled_; 3550a5b14de5115f51e0ed2dd6c3fcc5b84bbce690eBrian Carlstrom 35658ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom // The host prefix is used during cross compilation. It is removed 35758ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom // from the start of host paths such as: 35829e7ac74a3f9aec192099fec381baadaa55730adBrian Carlstrom // $ANDROID_PRODUCT_OUT/system/framework/boot.oat 35934f426c49ac2de8cea70acef6b9ecdd8e62209d2Brian Carlstrom // to produce target paths such as 36047a0d5a6f221066c3daf7f67f2122ed9c9cd217cBrian Carlstrom // /system/framework/boot.oat 36158ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom // Similarly it is prepended to target paths to arrive back at a 36258ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom // host past. In both cases this is necessary because image and oat 36358ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom // files embedded expect paths of dependent files (an image points 36458ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom // to an oat file and an oat files to one or more dex files). These 36558ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom // files contain the expected target path. 36658ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom std::string host_prefix_; 36758ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom 368a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom std::string boot_class_path_string_; 369a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom std::string class_path_string_; 3707ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes std::vector<std::string> properties_; 3717ede61eceed2f8da14a4fff05c57c748c160d57fElliott Hughes 372b765be0d656c3073402693aeaf64e95a0e49f218Brian Carlstrom // The default stack size for managed threads created by the runtime. 373be759c63c6bb58b76ac71cad2c5a736bd31f374dElliott Hughes size_t default_stack_size_; 374b765be0d656c3073402693aeaf64e95a0e49f218Brian Carlstrom 375b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes Heap* heap_; 376b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes 377c33a32bccc4c66ed82ce3a580b16636399385cb4Elliott Hughes MonitorList* monitor_list_; 378c33a32bccc4c66ed82ce3a580b16636399385cb4Elliott Hughes 379b557353b22c728eecbd1c68593b482622c7782a8Carl Shapiro ThreadList* thread_list_; 38061e019d291583029c01b61b93bea750f2b663c37Carl Shapiro 381cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughes InternTable* intern_table_; 382cf4c6c41b0084dc4567ff709fb8ce9ebd72b26acElliott Hughes 383b0460eaa2cb131f1dbdd5a7217bd36b9a9f1b995Brian Carlstrom ClassLinker* class_linker_; 384b0460eaa2cb131f1dbdd5a7217bd36b9a9f1b995Brian Carlstrom 385e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes SignalCatcher* signal_catcher_; 38694ce37a3919a0bdb8855a3d3264a50df1dbc41beElliott Hughes std::string stack_trace_file_; 387e27955ca3ca960928d4dbd6cb79711fce06950b3Elliott Hughes 388c5f7c91ab89055cffb573fff7e06dbdd860bccedElliott Hughes JavaVMExt* java_vm_; 389f2682d5a6ce0f7de58da8fd4ec8aec200c43b92eElliott Hughes 390225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes Throwable* pre_allocated_OutOfMemoryError_; 391225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes 392161928613d3f097108319de60494fab1aab8d48aBrian Carlstrom ByteArray* jni_stub_array_; 393161928613d3f097108319de60494fab1aab8d48aBrian Carlstrom 394e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom ByteArray* abstract_method_error_stub_array_; 395e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 3964f0d07c783afef89703dce32c94440fc8621a29bIan Rogers ByteArray* resolution_stub_array_[kLastTrampolineMethodType]; 397ad25ac568407ceb14334e8551dd1c4dd0fd6993cIan Rogers 398225f5a1df25241babd16cdba54056b9e2cd166a2Elliott Hughes Method* callee_save_methods_[kLastCalleeSaveType]; 399ff1ed4770bf7ff024a807b9f909b1a26abb78341Ian Rogers 4001984651929744dd603fd082e23eacd877b9bc177Ian Rogers Method* resolution_method_; 4011984651929744dd603fd082e23eacd877b9bc177Ian Rogers 402aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom // As returned by ClassLoader.getSystemClassLoader() 403aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom ClassLoader* system_class_loader_; 404aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 4056b3557571e798b60df995f978fa01c0ca1980dfdElliott Hughes bool shutting_down_; 406dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes bool started_; 407dcc247493fd8fb243e335c3ec08e5e625896a47cElliott Hughes 4087664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier // New flag added which tells us if the runtime has finished starting. If 4097664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier // this flag is set then the Daemon threads are created and the class loader 4107664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier // is created. This flag is needed for knowing if its safe to request CMS. 4117664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier bool finished_starting_; 4127664f5cd118b355a5fe0c7536cb48ac991ed2b62Mathieu Chartier 4136ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom // Hooks supported by JNI_CreateJavaVM 4146ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom jint (*vfprintf_)(FILE* stream, const char* format, va_list ap); 4156ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom void (*exit_)(jint status); 4166ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom void (*abort_)(); 4176ea095ad30bf13cc00b4fee7afbbe4731a349c83Brian Carlstrom 4189d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes bool stats_enabled_; 4199d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes RuntimeStats stats_; 4209d5ccec86d60c9ddd811836b9a2bc28d0b3d11feElliott Hughes 421b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao bool method_trace_; 422b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao std::string method_trace_file_; 423b5e81858a47dd7ed051135f6982fbc4e13d0f309jeffhao size_t method_trace_file_size_; 4242692b573a56cd63a3c8c8aa1636e3766b6d8c9c4jeffhao Trace* tracer_; 4252692b573a56cd63a3c8c8aa1636e3766b6d8c9c4jeffhao 426a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes typedef SafeMap<const ClassLoader*, std::vector<const DexFile*> > CompileTimeClassPaths; 427b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes CompileTimeClassPaths compile_time_class_paths_; 428b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes bool use_compile_time_class_path_; 429131aef8c94292cc530da2fd91ee98d1432352959Elliott Hughes 430365c10235438607541fa2259a5fec48061b90bd8Ian Rogers jobject main_thread_group_; 431365c10235438607541fa2259a5fec48061b90bd8Ian Rogers jobject system_thread_group_; 432971bf3f9184010d68b9a3ad30b396fa401af91a3Logan Chien#if defined(ART_USE_LLVM_COMPILER) 433971bf3f9184010d68b9a3ad30b396fa401af91a3Logan Chien compiler_llvm::ProcedureLinkageTable plt_; 434971bf3f9184010d68b9a3ad30b396fa401af91a3Logan Chien#endif 435365c10235438607541fa2259a5fec48061b90bd8Ian Rogers 43661e019d291583029c01b61b93bea750f2b663c37Carl Shapiro DISALLOW_COPY_AND_ASSIGN(Runtime); 4377b21670581d13db32f1384a3b2692bcfc8f57320Carl Shapiro}; 4387b21670581d13db32f1384a3b2692bcfc8f57320Carl Shapiro 4396b6b5f0e67ce03f38223a525612955663bc1799bCarl Shapiro} // namespace art 4407b21670581d13db32f1384a3b2692bcfc8f57320Carl Shapiro 4411fb8620309a4e94d11879aabc33364acfa733904Carl Shapiro#endif // ART_SRC_RUNTIME_H_ 442