blob: 3cfa5050eacd7d994eb9c44a280ab35534b76277 [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"
Carl Shapiro69759ea2011-07-21 18:13:35 -07008
9namespace art {
10
11class Object;
12
13// A space contains memory allocated for managed objects.
14class Space {
15 public:
16 static Space* Create(size_t startup_size, size_t maximum_size);
17
18 ~Space();
19
20 Object* AllocWithGrowth(size_t num_bytes);
21
22 Object* AllocWithoutGrowth(size_t num_bytes);
23
24 size_t Free(void* ptr);
25
26 void Trim();
27
28 size_t MaxAllowedFootprint();
29
30 void Grow(size_t num_bytes);
31
32 byte* GetBase() {
33 return base_;
34 }
35
Carl Shapiro58551df2011-07-24 03:09:51 -070036 byte* GetLimit() {
37 return limit_;
38 }
39
Carl Shapiro69759ea2011-07-21 18:13:35 -070040 size_t Size() {
41 return limit_ - base_;
42 }
43
Carl Shapiro58551df2011-07-24 03:09:51 -070044 size_t AllocationSize(const Object* obj);
45
46 bool IsCondemned() {
47 return true; // TODO
48 }
49
Carl Shapiro69759ea2011-07-21 18:13:35 -070050 private:
Carl Shapiro58551df2011-07-24 03:09:51 -070051 // The boundary tag overhead.
52 static const size_t kChunkOverhead = kWordSize;
53
Carl Shapiro69759ea2011-07-21 18:13:35 -070054 Space(size_t startup_size, size_t maximum_size) :
55 mspace_(NULL),
56 base_(NULL),
57 startup_size_(startup_size),
58 maximum_size_(maximum_size) {
59 }
60
Carl Shapiro58551df2011-07-24 03:09:51 -070061 // Initializes the space and underlying storage.
Carl Shapiro69759ea2011-07-21 18:13:35 -070062 bool Init();
63
64 void* CreateMallocSpace(void* base, size_t startup_size,
65 size_t maximum_size);
66
67 static void DontNeed(void* start, void* end, void* num_bytes);
68
69 void* mspace_;
70
71 byte* base_;
72
73 byte* limit_;
74
75 size_t startup_size_;
76
77 size_t maximum_size_;
78
Carl Shapiro58551df2011-07-24 03:09:51 -070079 bool is_condemned_;
80
Carl Shapiro69759ea2011-07-21 18:13:35 -070081 DISALLOW_IMPLICIT_CONSTRUCTORS(Space);
82};
83
84} // namespace art
85
86#endif // ART_SRC_SPACE_H_