Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | #ifndef ART_SRC_RUNTIME_H_ |
| 4 | #define ART_SRC_RUNTIME_H_ |
| 5 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 6 | #include <vector> |
| 7 | |
| 8 | #include "globals.h" |
| 9 | #include "macros.h" |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 10 | #include "dex_file.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 11 | #include "stringpiece.h" |
Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 12 | |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 13 | namespace art { |
| 14 | |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 15 | class ClassLinker; |
| 16 | class Heap; |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 17 | class JniEnvironment; |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 18 | class ThreadList; |
| 19 | |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 20 | class Runtime { |
| 21 | public: |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 22 | typedef std::vector<std::pair<const char*, void*> > Options; |
| 23 | |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 24 | // Creates and initializes a new runtime. |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 25 | static Runtime* Create(const Options& options, bool ignore_unrecognized); |
| 26 | static Runtime* Create(const std::vector<DexFile*>& boot_class_path); |
| 27 | |
| 28 | static Runtime* Current() { |
| 29 | return instance_; |
| 30 | } |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 31 | |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 32 | // Compiles a dex file. |
| 33 | static void Compile(const StringPiece& filename); |
Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 34 | |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 35 | // Aborts semi-cleanly. Used in the implementation of LOG(FATAL), which most |
| 36 | // callers should prefer. |
| 37 | // This isn't marked ((noreturn)) because then gcc will merge multiple calls |
| 38 | // in a single function together. This reduces code size slightly, but means |
| 39 | // that the native stack trace we get may point at the wrong call site. |
| 40 | static void Abort(const char* file, int line); |
| 41 | |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 42 | // Attaches the current native thread to the runtime. |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 43 | bool AttachCurrentThread(const char* name, JniEnvironment** jni_env); |
| 44 | bool AttachCurrentThreadAsDaemon(const char* name, JniEnvironment** jni_env); |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 45 | |
| 46 | // Detaches the current native thread from the runtime. |
| 47 | bool DetachCurrentThread(); |
| 48 | |
| 49 | ~Runtime(); |
Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 50 | |
Carl Shapiro | 7a90959 | 2011-07-24 19:21:59 -0700 | [diff] [blame] | 51 | ClassLinker* GetClassLinker() { |
| 52 | return class_linker_; |
| 53 | } |
| 54 | |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 55 | void SetVfprintfHook(void* hook); |
| 56 | |
| 57 | void SetExitHook(void* hook); |
| 58 | |
| 59 | void SetAbortHook(void* hook); |
| 60 | |
Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 61 | private: |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 62 | static void PlatformAbort(const char*, int); |
| 63 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 64 | Runtime() : class_linker_(NULL), thread_list_(NULL) {} |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 65 | |
| 66 | // Initializes a new uninitialized runtime. |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 67 | bool Init(const std::vector<DexFile*>& boot_class_path); |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 68 | |
| 69 | ClassLinker* class_linker_; |
| 70 | |
Carl Shapiro | b557353 | 2011-07-12 18:22:59 -0700 | [diff] [blame] | 71 | ThreadList* thread_list_; |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 72 | |
Carl Shapiro | 2ed144c | 2011-07-26 16:52:08 -0700 | [diff] [blame] | 73 | // A pointer to the active runtime or NULL. |
| 74 | static Runtime* instance_; |
| 75 | |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 76 | DISALLOW_COPY_AND_ASSIGN(Runtime); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | } // namespace art |
| 80 | |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 81 | #endif // ART_SRC_RUNTIME_H_ |