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