Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 1 | // 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 Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame^] | 7 | #include "globals.h" |
| 8 | #include "macros.h" |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 9 | |
| 10 | namespace art { |
| 11 | |
| 12 | class Object; |
| 13 | |
| 14 | // A space contains memory allocated for managed objects. |
| 15 | class 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 | |
| 37 | size_t Size() { |
| 38 | return limit_ - base_; |
| 39 | } |
| 40 | |
| 41 | private: |
| 42 | Space(size_t startup_size, size_t maximum_size) : |
| 43 | mspace_(NULL), |
| 44 | base_(NULL), |
| 45 | startup_size_(startup_size), |
| 46 | maximum_size_(maximum_size) { |
| 47 | } |
| 48 | |
| 49 | bool Init(); |
| 50 | |
| 51 | void* CreateMallocSpace(void* base, size_t startup_size, |
| 52 | size_t maximum_size); |
| 53 | |
| 54 | static void DontNeed(void* start, void* end, void* num_bytes); |
| 55 | |
| 56 | void* mspace_; |
| 57 | |
| 58 | byte* base_; |
| 59 | |
| 60 | byte* limit_; |
| 61 | |
| 62 | size_t startup_size_; |
| 63 | |
| 64 | size_t maximum_size_; |
| 65 | |
| 66 | DISALLOW_IMPLICIT_CONSTRUCTORS(Space); |
| 67 | }; |
| 68 | |
| 69 | } // namespace art |
| 70 | |
| 71 | #endif // ART_SRC_SPACE_H_ |