blob: 7b72bba53ca4bc9e22a23f2020c6ea2fc0a508bc [file] [log] [blame]
Carl Shapiro69759ea2011-07-21 18:13:35 -07001// Copyright 2011 Google Inc. All Rights Reserved.
Carl Shapiro69759ea2011-07-21 18:13:35 -07002
3#ifndef ART_SRC_SPACE_H_
4#define ART_SRC_SPACE_H_
5
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07006#include "globals.h"
7#include "macros.h"
Brian Carlstromdb4d5402011-08-09 12:18:28 -07008#include "mem_map.h"
9#include "scoped_ptr.h"
Carl Shapiro69759ea2011-07-21 18:13:35 -070010
11namespace art {
12
13class Object;
14
15// A space contains memory allocated for managed objects.
16class Space {
17 public:
18 static Space* Create(size_t startup_size, size_t maximum_size);
19
20 ~Space();
21
22 Object* AllocWithGrowth(size_t num_bytes);
23
24 Object* AllocWithoutGrowth(size_t num_bytes);
25
26 size_t Free(void* ptr);
27
28 void Trim();
29
30 size_t MaxAllowedFootprint();
31
32 void Grow(size_t num_bytes);
33
Brian Carlstromdb4d5402011-08-09 12:18:28 -070034 byte* GetBase() const {
Carl Shapiro69759ea2011-07-21 18:13:35 -070035 return base_;
36 }
37
Brian Carlstromdb4d5402011-08-09 12:18:28 -070038 byte* GetLimit() const {
Carl Shapiro58551df2011-07-24 03:09:51 -070039 return limit_;
40 }
41
Brian Carlstromdb4d5402011-08-09 12:18:28 -070042 size_t Size() const {
Carl Shapiro69759ea2011-07-21 18:13:35 -070043 return limit_ - base_;
44 }
45
Carl Shapiro58551df2011-07-24 03:09:51 -070046 size_t AllocationSize(const Object* obj);
47
Brian Carlstromdb4d5402011-08-09 12:18:28 -070048 bool IsCondemned() const {
Carl Shapiro58551df2011-07-24 03:09:51 -070049 return true; // TODO
50 }
51
Carl Shapiro69759ea2011-07-21 18:13:35 -070052 private:
Carl Shapiro58551df2011-07-24 03:09:51 -070053 // The boundary tag overhead.
54 static const size_t kChunkOverhead = kWordSize;
55
Carl Shapiro69759ea2011-07-21 18:13:35 -070056 Space(size_t startup_size, size_t maximum_size) :
57 mspace_(NULL),
58 base_(NULL),
59 startup_size_(startup_size),
60 maximum_size_(maximum_size) {
61 }
62
Carl Shapiro58551df2011-07-24 03:09:51 -070063 // Initializes the space and underlying storage.
Carl Shapiro69759ea2011-07-21 18:13:35 -070064 bool Init();
65
66 void* CreateMallocSpace(void* base, size_t startup_size,
67 size_t maximum_size);
68
69 static void DontNeed(void* start, void* end, void* num_bytes);
70
71 void* mspace_;
72
Brian Carlstromdb4d5402011-08-09 12:18:28 -070073 scoped_ptr<MemMap> mem_map_;
74
Carl Shapiro69759ea2011-07-21 18:13:35 -070075 byte* base_;
76
77 byte* limit_;
78
79 size_t startup_size_;
80
81 size_t maximum_size_;
82
Carl Shapiro58551df2011-07-24 03:09:51 -070083 bool is_condemned_;
84
Carl Shapiro69759ea2011-07-21 18:13:35 -070085 DISALLOW_IMPLICIT_CONSTRUCTORS(Space);
86};
87
88} // namespace art
89
90#endif // ART_SRC_SPACE_H_