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