blob: 663efa5f747d42d0697b7ea6250b5ddd0742b296 [file] [log] [blame]
Carl Shapiro69759ea2011-07-21 18:13:35 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2// Author: cshapiro@google.com (Carl Shapiro)
3
4#ifndef ART_SRC_SPACE_H_
5#define ART_SRC_SPACE_H_
6
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07007#include "globals.h"
8#include "macros.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -07009
10namespace art {
11
12class Object;
13
14// A space contains memory allocated for managed objects.
15class Space {
16 public:
17 static Space* Create(size_t startup_size, size_t maximum_size);
18
19 ~Space();
20
21 Object* AllocWithGrowth(size_t num_bytes);
22
23 Object* AllocWithoutGrowth(size_t num_bytes);
24
25 size_t Free(void* ptr);
26
27 void Trim();
28
29 size_t MaxAllowedFootprint();
30
31 void Grow(size_t num_bytes);
32
33 byte* GetBase() {
34 return base_;
35 }
36
Carl Shapiro58551df2011-07-24 03:09:51 -070037 byte* GetLimit() {
38 return limit_;
39 }
40
Carl Shapiro69759ea2011-07-21 18:13:35 -070041 size_t Size() {
42 return limit_ - base_;
43 }
44
Carl Shapiro58551df2011-07-24 03:09:51 -070045 size_t AllocationSize(const Object* obj);
46
47 bool IsCondemned() {
48 return true; // TODO
49 }
50
Carl Shapiro69759ea2011-07-21 18:13:35 -070051 private:
Carl Shapiro58551df2011-07-24 03:09:51 -070052 // The boundary tag overhead.
53 static const size_t kChunkOverhead = kWordSize;
54
Carl Shapiro69759ea2011-07-21 18:13:35 -070055 Space(size_t startup_size, size_t maximum_size) :
56 mspace_(NULL),
57 base_(NULL),
58 startup_size_(startup_size),
59 maximum_size_(maximum_size) {
60 }
61
Carl Shapiro58551df2011-07-24 03:09:51 -070062 // Initializes the space and underlying storage.
Carl Shapiro69759ea2011-07-21 18:13:35 -070063 bool Init();
64
65 void* CreateMallocSpace(void* base, size_t startup_size,
66 size_t maximum_size);
67
68 static void DontNeed(void* start, void* end, void* num_bytes);
69
70 void* mspace_;
71
72 byte* base_;
73
74 byte* limit_;
75
76 size_t startup_size_;
77
78 size_t maximum_size_;
79
Carl Shapiro58551df2011-07-24 03:09:51 -070080 bool is_condemned_;
81
Carl Shapiro69759ea2011-07-21 18:13:35 -070082 DISALLOW_IMPLICIT_CONSTRUCTORS(Space);
83};
84
85} // namespace art
86
87#endif // ART_SRC_SPACE_H_