blob: b57f1cfd859fc80e620fc1b604c18b1e5f4d095e [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;
17class ThreadList;
18
Carl Shapiro1fb86202011-06-27 17:43:13 -070019class Runtime {
20 public:
Carl Shapiro61e019d2011-07-14 16:53:09 -070021 // Creates and initializes a new runtime.
Brian Carlstromf615a612011-07-23 12:50:34 -070022 static Runtime* Create(std::vector<DexFile*> boot_class_path);
Carl Shapiro1fb86202011-06-27 17:43:13 -070023
Carl Shapiro61e019d2011-07-14 16:53:09 -070024 // Compiles a dex file.
25 static void Compile(const StringPiece& filename);
Carl Shapirob5573532011-07-12 18:22:59 -070026
Elliott Hughesffe67362011-07-17 12:09:27 -070027 // Aborts semi-cleanly. Used in the implementation of LOG(FATAL), which most
28 // callers should prefer.
29 // This isn't marked ((noreturn)) because then gcc will merge multiple calls
30 // in a single function together. This reduces code size slightly, but means
31 // that the native stack trace we get may point at the wrong call site.
32 static void Abort(const char* file, int line);
33
Carl Shapiro61e019d2011-07-14 16:53:09 -070034 // Attaches the current native thread to the runtime.
35 bool AttachCurrentThread();
36
37 // Detaches the current native thread from the runtime.
38 bool DetachCurrentThread();
39
40 ~Runtime();
Carl Shapirob5573532011-07-12 18:22:59 -070041
Carl Shapiro7a909592011-07-24 19:21:59 -070042 ClassLinker* GetClassLinker() {
43 return class_linker_;
44 }
45
Carl Shapirob5573532011-07-12 18:22:59 -070046 private:
Elliott Hughesffe67362011-07-17 12:09:27 -070047 static void PlatformAbort(const char*, int);
48
Carl Shapiro69759ea2011-07-21 18:13:35 -070049 Runtime() : class_linker_(NULL), thread_list_(NULL) {}
Carl Shapiro61e019d2011-07-14 16:53:09 -070050
51 // Initializes a new uninitialized runtime.
Brian Carlstromf615a612011-07-23 12:50:34 -070052 bool Init(std::vector<DexFile*> boot_class_path);
Carl Shapiro61e019d2011-07-14 16:53:09 -070053
54 ClassLinker* class_linker_;
55
Carl Shapirob5573532011-07-12 18:22:59 -070056 ThreadList* thread_list_;
Carl Shapiro61e019d2011-07-14 16:53:09 -070057
58 DISALLOW_COPY_AND_ASSIGN(Runtime);
Carl Shapiro1fb86202011-06-27 17:43:13 -070059};
60
61} // namespace art
62
Carl Shapiro1fb86202011-06-27 17:43:13 -070063#endif // ART_SRC_RUNTIME_H_