blob: 9ff532c00c643267450a9de86bcf7e12a69015fd [file] [log] [blame]
Carl Shapiro1fb86202011-06-27 17:43:13 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
3#ifndef ART_SRC_RUNTIME_H_
4#define ART_SRC_RUNTIME_H_
5
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07006#include <vector>
7
8#include "globals.h"
9#include "macros.h"
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070010#include "dex_file.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070011#include "stringpiece.h"
Carl Shapirob5573532011-07-12 18:22:59 -070012
Carl Shapiro1fb86202011-06-27 17:43:13 -070013namespace art {
14
Carl Shapiro61e019d2011-07-14 16:53:09 -070015class ClassLinker;
16class Heap;
Carl Shapiro2ed144c2011-07-26 16:52:08 -070017class JniEnvironment;
Carl Shapiro61e019d2011-07-14 16:53:09 -070018class ThreadList;
19
Carl Shapiro1fb86202011-06-27 17:43:13 -070020class Runtime {
21 public:
Carl Shapiro2ed144c2011-07-26 16:52:08 -070022 typedef std::vector<std::pair<const char*, void*> > Options;
23
Carl Shapiro61e019d2011-07-14 16:53:09 -070024 // Creates and initializes a new runtime.
Carl Shapiro2ed144c2011-07-26 16:52:08 -070025 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 Shapiro1fb86202011-06-27 17:43:13 -070031
Carl Shapiro61e019d2011-07-14 16:53:09 -070032 // Compiles a dex file.
33 static void Compile(const StringPiece& filename);
Carl Shapirob5573532011-07-12 18:22:59 -070034
Elliott Hughesffe67362011-07-17 12:09:27 -070035 // 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 Shapiro61e019d2011-07-14 16:53:09 -070042 // Attaches the current native thread to the runtime.
Carl Shapiro2ed144c2011-07-26 16:52:08 -070043 bool AttachCurrentThread(const char* name, JniEnvironment** jni_env);
44 bool AttachCurrentThreadAsDaemon(const char* name, JniEnvironment** jni_env);
Carl Shapiro61e019d2011-07-14 16:53:09 -070045
46 // Detaches the current native thread from the runtime.
47 bool DetachCurrentThread();
48
49 ~Runtime();
Carl Shapirob5573532011-07-12 18:22:59 -070050
Carl Shapiro7a909592011-07-24 19:21:59 -070051 ClassLinker* GetClassLinker() {
52 return class_linker_;
53 }
54
Carl Shapiro2ed144c2011-07-26 16:52:08 -070055 void SetVfprintfHook(void* hook);
56
57 void SetExitHook(void* hook);
58
59 void SetAbortHook(void* hook);
60
Carl Shapirob5573532011-07-12 18:22:59 -070061 private:
Elliott Hughesffe67362011-07-17 12:09:27 -070062 static void PlatformAbort(const char*, int);
63
Carl Shapiro69759ea2011-07-21 18:13:35 -070064 Runtime() : class_linker_(NULL), thread_list_(NULL) {}
Carl Shapiro61e019d2011-07-14 16:53:09 -070065
66 // Initializes a new uninitialized runtime.
Carl Shapiro2ed144c2011-07-26 16:52:08 -070067 bool Init(const std::vector<DexFile*>& boot_class_path);
Carl Shapiro61e019d2011-07-14 16:53:09 -070068
69 ClassLinker* class_linker_;
70
Carl Shapirob5573532011-07-12 18:22:59 -070071 ThreadList* thread_list_;
Carl Shapiro61e019d2011-07-14 16:53:09 -070072
Carl Shapiro2ed144c2011-07-26 16:52:08 -070073 // A pointer to the active runtime or NULL.
74 static Runtime* instance_;
75
Carl Shapiro61e019d2011-07-14 16:53:09 -070076 DISALLOW_COPY_AND_ASSIGN(Runtime);
Carl Shapiro1fb86202011-06-27 17:43:13 -070077};
78
79} // namespace art
80
Carl Shapiro1fb86202011-06-27 17:43:13 -070081#endif // ART_SRC_RUNTIME_H_