blob: 1a9661f81a05b31d1a45d36c6a2a5856b9106d84 [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>
Carl Shapirofc322c72011-07-27 00:20:01 -07007#include <utility>
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07008
9#include "globals.h"
10#include "macros.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;
Carl Shapirofc322c72011-07-27 00:20:01 -070016class DexFile;
Carl Shapiro61e019d2011-07-14 16:53:09 -070017class Heap;
Carl Shapiro2ed144c2011-07-26 16:52:08 -070018class JniEnvironment;
Carl Shapiro61e019d2011-07-14 16:53:09 -070019class ThreadList;
20
Carl Shapiro1fb86202011-06-27 17:43:13 -070021class Runtime {
22 public:
Carl Shapirofc322c72011-07-27 00:20:01 -070023 typedef std::vector<std::pair<StringPiece, void*> > Options;
Carl Shapiro2ed144c2011-07-26 16:52:08 -070024
Carl Shapiro61e019d2011-07-14 16:53:09 -070025 // Creates and initializes a new runtime.
Carl Shapiro2ed144c2011-07-26 16:52:08 -070026 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 Shapiro1fb86202011-06-27 17:43:13 -070032
Carl Shapiro61e019d2011-07-14 16:53:09 -070033 // Compiles a dex file.
34 static void Compile(const StringPiece& filename);
Carl Shapirob5573532011-07-12 18:22:59 -070035
Elliott Hughesffe67362011-07-17 12:09:27 -070036 // 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 Shapiro61e019d2011-07-14 16:53:09 -070043 // Attaches the current native thread to the runtime.
Carl Shapiro2ed144c2011-07-26 16:52:08 -070044 bool AttachCurrentThread(const char* name, JniEnvironment** jni_env);
45 bool AttachCurrentThreadAsDaemon(const char* name, JniEnvironment** jni_env);
Carl Shapiro61e019d2011-07-14 16:53:09 -070046
47 // Detaches the current native thread from the runtime.
48 bool DetachCurrentThread();
49
50 ~Runtime();
Carl Shapirob5573532011-07-12 18:22:59 -070051
Carl Shapiro7a909592011-07-24 19:21:59 -070052 ClassLinker* GetClassLinker() {
53 return class_linker_;
54 }
55
Carl Shapiro2ed144c2011-07-26 16:52:08 -070056 void SetVfprintfHook(void* hook);
57
58 void SetExitHook(void* hook);
59
60 void SetAbortHook(void* hook);
61
Carl Shapirob5573532011-07-12 18:22:59 -070062 private:
Elliott Hughesffe67362011-07-17 12:09:27 -070063 static void PlatformAbort(const char*, int);
64
Brian Carlstromb0460ea2011-07-29 10:08:05 -070065 Runtime() : thread_list_(NULL), class_linker_(NULL) {}
Carl Shapiro61e019d2011-07-14 16:53:09 -070066
67 // Initializes a new uninitialized runtime.
Carl Shapiro2ed144c2011-07-26 16:52:08 -070068 bool Init(const std::vector<DexFile*>& boot_class_path);
Carl Shapiro61e019d2011-07-14 16:53:09 -070069
Carl Shapirob5573532011-07-12 18:22:59 -070070 ThreadList* thread_list_;
Carl Shapiro61e019d2011-07-14 16:53:09 -070071
Brian Carlstromb0460ea2011-07-29 10:08:05 -070072 ClassLinker* class_linker_;
73
Carl Shapiro2ed144c2011-07-26 16:52:08 -070074 // A pointer to the active runtime or NULL.
75 static Runtime* instance_;
76
Carl Shapiro61e019d2011-07-14 16:53:09 -070077 DISALLOW_COPY_AND_ASSIGN(Runtime);
Carl Shapiro1fb86202011-06-27 17:43:13 -070078};
79
80} // namespace art
81
Carl Shapiro1fb86202011-06-27 17:43:13 -070082#endif // ART_SRC_RUNTIME_H_