blob: 9245f19fe0f2583feb704222abc3c206a16985b2 [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
Carl Shapiro61e019d2011-07-14 16:53:09 -07006#include "src/globals.h"
7#include "src/macros.h"
8#include "src/stringpiece.h"
Carl Shapirob5573532011-07-12 18:22:59 -07009
Carl Shapiro1fb86202011-06-27 17:43:13 -070010namespace art {
11
Carl Shapiro61e019d2011-07-14 16:53:09 -070012class ClassLinker;
13class Heap;
14class ThreadList;
15
Carl Shapiro1fb86202011-06-27 17:43:13 -070016class Runtime {
17 public:
Carl Shapiro61e019d2011-07-14 16:53:09 -070018 // Creates and initializes a new runtime.
19 static Runtime* Create();
Carl Shapiro1fb86202011-06-27 17:43:13 -070020
Carl Shapiro61e019d2011-07-14 16:53:09 -070021 // Compiles a dex file.
22 static void Compile(const StringPiece& filename);
Carl Shapirob5573532011-07-12 18:22:59 -070023
Elliott Hughesffe67362011-07-17 12:09:27 -070024 // Aborts semi-cleanly. Used in the implementation of LOG(FATAL), which most
25 // callers should prefer.
26 // This isn't marked ((noreturn)) because then gcc will merge multiple calls
27 // in a single function together. This reduces code size slightly, but means
28 // that the native stack trace we get may point at the wrong call site.
29 static void Abort(const char* file, int line);
30
Carl Shapiro61e019d2011-07-14 16:53:09 -070031 // Attaches the current native thread to the runtime.
32 bool AttachCurrentThread();
33
34 // Detaches the current native thread from the runtime.
35 bool DetachCurrentThread();
36
37 ~Runtime();
Carl Shapirob5573532011-07-12 18:22:59 -070038
39 private:
Elliott Hughesffe67362011-07-17 12:09:27 -070040 static void PlatformAbort(const char*, int);
41
Carl Shapiro61e019d2011-07-14 16:53:09 -070042 Runtime() : class_linker_(NULL), heap_(NULL), thread_list_(NULL) {}
43
44 // Initializes a new uninitialized runtime.
45 bool Init();
46
47 ClassLinker* class_linker_;
48
49 Heap* heap_;
50
Carl Shapirob5573532011-07-12 18:22:59 -070051 ThreadList* thread_list_;
Carl Shapiro61e019d2011-07-14 16:53:09 -070052
53 DISALLOW_COPY_AND_ASSIGN(Runtime);
Carl Shapiro1fb86202011-06-27 17:43:13 -070054};
55
56} // namespace art
57
Carl Shapiro1fb86202011-06-27 17:43:13 -070058#endif // ART_SRC_RUNTIME_H_